10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211618Srie 220Sstevel@tonic-gate /* 23*7682SAli.Bahrami@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * String conversion routine for version flag entries. 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate #include <stdio.h> 310Sstevel@tonic-gate #include "_conv.h" 320Sstevel@tonic-gate #include "version_msg.h" 330Sstevel@tonic-gate 34*7682SAli.Bahrami@Sun.COM #define VERFLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 35*7682SAli.Bahrami@Sun.COM MSG_VER_FLG_WEAK_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 36*7682SAli.Bahrami@Sun.COM MSG_VER_FLG_BASE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 37*7682SAli.Bahrami@Sun.COM MSG_VER_FLG_INFO_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 38*7682SAli.Bahrami@Sun.COM CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 39*7682SAli.Bahrami@Sun.COM 40*7682SAli.Bahrami@Sun.COM /* 41*7682SAli.Bahrami@Sun.COM * Ensure that Conv_ver_flags_buf_t is large enough: 42*7682SAli.Bahrami@Sun.COM * 43*7682SAli.Bahrami@Sun.COM * VERFLAGSZ is the real minimum size of the buffer required by 44*7682SAli.Bahrami@Sun.COM * conv_ver_flags(). However, Conv_ver_flags_buf_t uses CONV_VER_FLAGS_BUFSIZE 45*7682SAli.Bahrami@Sun.COM * to set the buffer size. We do things this way because the definition of 46*7682SAli.Bahrami@Sun.COM * VERFLAGSZ uses information that is not available in the environment of 47*7682SAli.Bahrami@Sun.COM * other programs that include the conv.h header file. 48*7682SAli.Bahrami@Sun.COM */ 49*7682SAli.Bahrami@Sun.COM #if (CONV_VER_FLAGS_BUFSIZE != VERFLAGSZ) && !defined(__lint) 50*7682SAli.Bahrami@Sun.COM #define REPORT_BUFSIZE VERFLAGSZ 51*7682SAli.Bahrami@Sun.COM #include "report_bufsize.h" 52*7682SAli.Bahrami@Sun.COM #error "CONV_VER_FLAGS_BUFSIZE does not match VERFLAGSZ" 53*7682SAli.Bahrami@Sun.COM #endif 54*7682SAli.Bahrami@Sun.COM 550Sstevel@tonic-gate const char * 56*7682SAli.Bahrami@Sun.COM conv_ver_flags(Half flags, Conv_fmt_flags_t fmt_flags, 57*7682SAli.Bahrami@Sun.COM Conv_ver_flags_buf_t *ver_flags_buf) 580Sstevel@tonic-gate { 59*7682SAli.Bahrami@Sun.COM static Val_desc vda[] = { 60*7682SAli.Bahrami@Sun.COM { VER_FLG_WEAK, MSG_ORIG(MSG_VER_FLG_WEAK) }, 61*7682SAli.Bahrami@Sun.COM { VER_FLG_BASE, MSG_ORIG(MSG_VER_FLG_BASE) }, 62*7682SAli.Bahrami@Sun.COM { VER_FLG_INFO, MSG_ORIG(MSG_VER_FLG_INFO) }, 63*7682SAli.Bahrami@Sun.COM { 0, 0 } 64*7682SAli.Bahrami@Sun.COM }; 65*7682SAli.Bahrami@Sun.COM static CONV_EXPN_FIELD_ARG conv_arg = { 66*7682SAli.Bahrami@Sun.COM NULL, sizeof (ver_flags_buf->buf), vda }; 67*7682SAli.Bahrami@Sun.COM 68*7682SAli.Bahrami@Sun.COM if (flags == 0) 690Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_NULL)); 70*7682SAli.Bahrami@Sun.COM 71*7682SAli.Bahrami@Sun.COM conv_arg.buf = ver_flags_buf->buf; 72*7682SAli.Bahrami@Sun.COM conv_arg.oflags = conv_arg.rflags = flags; 73*7682SAli.Bahrami@Sun.COM (void) conv_expn_field(&conv_arg, fmt_flags); 74*7682SAli.Bahrami@Sun.COM 75*7682SAli.Bahrami@Sun.COM return ((const char *)ver_flags_buf->buf); 760Sstevel@tonic-gate } 773875Sab196087 783875Sab196087 793875Sab196087 /* 803875Sab196087 * Format a version index as contained in a VERSYM section 814716Sab196087 * 824716Sab196087 * entry: 834716Sab196087 * verndx - Version index to format 844716Sab196087 * gnuver - If True (non-zero), the version rules used by the 854716Sab196087 * GNU ld are assumed. If False (0), Solaris ld rules apply. 863875Sab196087 */ 873875Sab196087 const char * 884734Sab196087 conv_ver_index(Versym verndx, int gnuver, Conv_inv_buf_t *inv_buf) 893875Sab196087 { 904716Sab196087 const char *fmt; 913875Sab196087 923875Sab196087 /* Special case versions starting at VER_NDX_LORESERVE */ 933875Sab196087 if (verndx == VER_NDX_ELIMINATE) 943875Sab196087 return (MSG_ORIG(MSG_VERSYM_ELIMINATE)); 953875Sab196087 964716Sab196087 /* 974716Sab196087 * The GNU style of versioning uses the top bit of the 984716Sab196087 * 16-bit version index (0x8000) as a "hidden bit". A 994716Sab196087 * hidden symbol is supposed to be ignored by the linker. 1004716Sab196087 */ 1014716Sab196087 if (gnuver && (verndx & 0x8000)) { 1024716Sab196087 verndx &= ~0x8000; 1034716Sab196087 fmt = MSG_ORIG(MSG_VERSYM_GNUH_FMT); 1044716Sab196087 } else { 1054716Sab196087 fmt = MSG_ORIG(MSG_VERSYM_FMT); 1064716Sab196087 } 1074716Sab196087 1083875Sab196087 /* format as numeric */ 1094734Sab196087 (void) snprintf(inv_buf->buf, sizeof (inv_buf->buf), 1104734Sab196087 fmt, EC_HALF(verndx)); 1114734Sab196087 return (inv_buf->buf); 1123875Sab196087 } 113