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*9273SAli.Bahrami@Sun.COM * Copyright 2009 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
347682SAli.Bahrami@Sun.COM #define VERFLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
357682SAli.Bahrami@Sun.COM MSG_VER_FLG_WEAK_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
367682SAli.Bahrami@Sun.COM MSG_VER_FLG_BASE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
377682SAli.Bahrami@Sun.COM MSG_VER_FLG_INFO_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
387682SAli.Bahrami@Sun.COM CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
397682SAli.Bahrami@Sun.COM
407682SAli.Bahrami@Sun.COM /*
417682SAli.Bahrami@Sun.COM * Ensure that Conv_ver_flags_buf_t is large enough:
427682SAli.Bahrami@Sun.COM *
437682SAli.Bahrami@Sun.COM * VERFLAGSZ is the real minimum size of the buffer required by
447682SAli.Bahrami@Sun.COM * conv_ver_flags(). However, Conv_ver_flags_buf_t uses CONV_VER_FLAGS_BUFSIZE
457682SAli.Bahrami@Sun.COM * to set the buffer size. We do things this way because the definition of
467682SAli.Bahrami@Sun.COM * VERFLAGSZ uses information that is not available in the environment of
477682SAli.Bahrami@Sun.COM * other programs that include the conv.h header file.
487682SAli.Bahrami@Sun.COM */
497682SAli.Bahrami@Sun.COM #if (CONV_VER_FLAGS_BUFSIZE != VERFLAGSZ) && !defined(__lint)
507682SAli.Bahrami@Sun.COM #define REPORT_BUFSIZE VERFLAGSZ
517682SAli.Bahrami@Sun.COM #include "report_bufsize.h"
527682SAli.Bahrami@Sun.COM #error "CONV_VER_FLAGS_BUFSIZE does not match VERFLAGSZ"
537682SAli.Bahrami@Sun.COM #endif
547682SAli.Bahrami@Sun.COM
550Sstevel@tonic-gate const char *
conv_ver_flags(Half flags,Conv_fmt_flags_t fmt_flags,Conv_ver_flags_buf_t * ver_flags_buf)567682SAli.Bahrami@Sun.COM conv_ver_flags(Half flags, Conv_fmt_flags_t fmt_flags,
577682SAli.Bahrami@Sun.COM Conv_ver_flags_buf_t *ver_flags_buf)
580Sstevel@tonic-gate {
59*9273SAli.Bahrami@Sun.COM static const Val_desc vda[] = {
60*9273SAli.Bahrami@Sun.COM { VER_FLG_WEAK, MSG_VER_FLG_WEAK },
61*9273SAli.Bahrami@Sun.COM { VER_FLG_BASE, MSG_VER_FLG_BASE },
62*9273SAli.Bahrami@Sun.COM { VER_FLG_INFO, MSG_VER_FLG_INFO },
637682SAli.Bahrami@Sun.COM { 0, 0 }
647682SAli.Bahrami@Sun.COM };
657682SAli.Bahrami@Sun.COM static CONV_EXPN_FIELD_ARG conv_arg = {
66*9273SAli.Bahrami@Sun.COM NULL, sizeof (ver_flags_buf->buf) };
677682SAli.Bahrami@Sun.COM
687682SAli.Bahrami@Sun.COM if (flags == 0)
690Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_NULL));
707682SAli.Bahrami@Sun.COM
717682SAli.Bahrami@Sun.COM conv_arg.buf = ver_flags_buf->buf;
727682SAli.Bahrami@Sun.COM conv_arg.oflags = conv_arg.rflags = flags;
73*9273SAli.Bahrami@Sun.COM (void) conv_expn_field(&conv_arg, vda, fmt_flags);
747682SAli.Bahrami@Sun.COM
757682SAli.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 *
conv_ver_index(Versym verndx,int gnuver,Conv_inv_buf_t * inv_buf)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