syms.c revision 4a8d0ea71c9a4e51c6a916a083ced6b499eb207f
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1988 AT&T
* All Rights Reserved
*
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Symbol table management routines
*/
#define ELF_TARGET_AMD64
#include <stdio.h>
#include <string.h>
#include <debug.h>
#include "msg.h"
#include "_libld.h"
/*
* AVL tree comparator function:
*
* The primary key is the symbol name hash with a secondary key of the symbol
* name itself.
*/
int
{
int res;
if (res < 0)
return (-1);
if (res > 0)
return (1);
/*
* Hash is equal - now compare name
*/
if (res == 0)
return (0);
if (res > 0)
return (1);
return (-1);
}
/*
* Focal point for verifying symbol names.
*/
inline static const char *
{
if (name) {
return (NULL);
}
return (NULL);
}
}
/*
* Determine if we're dealing with a register and if so validate it.
* If it's a scratch register, a fabricated name will be returned.
*/
return (NULL);
}
if (regname)
return (regname);
}
/*
* If this isn't a register, but we have a global symbol with a null
* name, we're not going to be able to hash this, search for it, or
* do anything interesting. However, we've been accepting a symbol of
* this kind for ages now, so give the user a warning (rather than a
* fatal error), just in case this instance exists somewhere in the
* world and hasn't, as yet, been a problem.
*/
}
}
/*
* For producing symbol names strings to use in error messages.
* If the symbol has a non-null name, then the string returned by
* this function is the output from demangle(), surrounded by
* single quotes. For null names, a descriptive string giving
* the symbol section and index is generated.
*
* This function uses an internal static buffer to hold the resulting
* string. The value returned is usable by the caller until the next
* call, at which point it is overwritten.
*/
static const char *
{
#define INIT_BUFSIZE 256
static char *buf;
int use_name;
if (use_name) {
} else {
}
len++; /* Null termination */
/* If our buffer is too small, double it until it is big enough */
char *new_buf;
if (new_bufsize == 0)
while (len > new_bufsize)
new_bufsize *= 2;
return (name);
}
if (use_name) {
} else {
}
return (buf);
}
/*
* Shared objects can be built that define specific symbols that can not be
* directly bound to. These objects have a syminfo section (and an associated
* DF_1_NODIRECT dynamic flags entry). Scan this table looking for symbols
* that can't be bound to directly, and if this files symbol is presently
* referenced, mark it so that we don't directly bind to it.
*/
{
char *strdata;
/*
* Get the syminfo data, and determine the number of entries.
*/
/*
* Get the associated symbol table.
*/
/*
* Get the string table associated with the symbol table.
*/
/*
* Traverse the syminfo data for symbols that can't be directly
* bound to.
*/
char *str;
continue;
continue;
}
}
return (0);
}
/*
* If, during symbol processing, it is necessary to update a local symbols
* contents before we have generated the symbol tables in the output image,
* create a new symbol structure and copy the original symbol contents. While
* we are processing the input files, their local symbols are part of the
* read-only mapped image. Commonly, these symbols are copied to the new output
* file image and then updated to reflect their new address and any change in
* attributes. However, sometimes during relocation counting, it is necessary
* to adjust the symbols information. This routine provides for the generation
* of a new symbol image so that this update can be performed.
* All global symbols are copied to an internal symbol table to improve locality
* of reference and hence performance, and thus this copying is not necessary.
*/
{
return (S_ERROR);
}
return (1);
}
/*
* Finds a given name in the link editors internal symbol table. If no
* hash value is specified it is calculated. A pointer to the located
* Sym_desc entry is returned, or NULL if the symbol is not found.
*/
Sym_desc *
{
if (hash == SYM_NOHASH)
/* LINTED */
/*
* Perform search for symbol in AVL tree. Note that the 'where' field
* is passed in from the caller. If a 'where' is present, it can be
* used in subsequent 'ld_sym_enter()' calls if required.
*/
/*
* If symbol was not found in the avl tree, return null to show that.
*/
return (NULL);
/*
* Return symbol found.
*/
return (sav->sav_symdesc);
}
/*
* Enter a new symbol into the link editors internal symbol table.
* If the symbol is from an input file, information regarding the input file
* and input section is also recorded. Otherwise (file == NULL) the symbol
* has been internally generated (ie. _etext, _edata, etc.).
*/
Sym_desc *
{
char *_name;
/*
* Establish the file type.
*/
if (ifl)
else
ofl->ofl_entercnt++;
/*
* Allocate a Sym Descriptor, Auxiliary Descriptor, and a Sym AVLNode -
* contiguously.
*/
/*
* Copy the symbol table entry from the input file into the internal
* entry and have the symbol descriptor use it.
*/
/*
* Enter Symbol in AVL tree.
*/
if (where == 0) {
/* LINTED */
/*
* If a previous ld_sym_find() hasn't initialized 'where' do it
* now.
*/
}
/*
* Record the section index. This is possible because the
* `ifl_isdesc' table is filled before we start symbol processing.
*/
else {
/*
* If this symbol is from a relocatable object, make sure that
* it is still associated with a section. For example, an
* unknown section type (SHT_NULL) would have been rejected on
* input with a warning. Here, we make the use of the symbol
* fatal. A symbol descriptor is still returned, so that the
* caller can continue processing all symbols, and hence flush
* out as many error conditions as possible.
*/
return (sdp);
}
}
/*
* Mark any COMMON symbols as 'tentative'.
*/
if (sdflags & FLG_SY_SPECSEC) {
#if defined(_ELF64)
#endif
}
/*
* Establish the symbols visibility and reference.
*/
switch (vis) {
case STV_DEFAULT:
break;
case STV_INTERNAL:
case STV_HIDDEN:
break;
case STV_PROTECTED:
break;
case STV_EXPORTED:
break;
case STV_SINGLETON:
break;
case STV_ELIMINATE:
break;
default:
}
/*
* Under -Bnodirect, all exported interfaces that have not
* explicitly been defined protected or directly bound to, are
* tagged to prevent direct binding.
*/
}
} else {
/*
* Record the binding file for this symbol in the sa_bindto
* field. If this symbol is ever overridden by a REF_REL_NEED
* definition, sa_bindto is used when building a 'translator'.
*/
/*
* If this is a protected symbol, remember this. Note, this
* state is different from the FLG_SY1_PROTECT used to establish
* a symbol definitions visibility. This state is used to warn
* against possible copy relocations against this referenced
* symbol.
*/
if (vis == STV_PROTECTED)
/*
* If this is a SINGLETON definition, then indicate the symbol
* can not be directly bound to, and retain the visibility.
* This visibility will be inherited by any references made to
* this symbol.
*/
/*
* If the new symbol is from a shared library and is associated
* with a SHT_NOBITS section then this symbol originated from a
* tentative symbol.
*/
}
/*
* Reclassify any SHN_SUNW_IGNORE symbols to SHN_UNDEF so as to
* simplify future processing.
*/
}
/*
* If this is an undefined, or common symbol from a relocatable object
* determine whether it is a global or weak reference (see build_osym(),
* where REF_DYN_NEED definitions are returned back to undefines).
*/
#if defined(_ELF64)
#else
/* BEGIN CSTYLED */
/* END CSTYLED */
#endif
/*
* Record the input filename on the referenced or defined files list
* for possible later diagnostics. The `sa_rfile' pointer contains the
* name of the file that first referenced this symbol and is used to
* generate undefined symbol diagnostics (refer to sym_undef_entry()).
* Note that this entry can be overridden if a reference from a
* relocatable object is found after a reference from a shared object
* (refer to sym_override()).
* The `sa_dfiles' list is used to maintain the list of files that
* define the same symbol. This list can be used for two reasons:
*
* - To save the first definition of a symbol that is not available
* for this link-edit.
*
* - To save all definitions of a symbol when the -m option is in
* effect. This is optional as it is used to list multiple
* (interposed) definitions of a symbol (refer to ldmap_out()),
* and can be quite expensive.
*/
} else {
/*
* A symbol is determined to be unavailable if it
* belongs to a version of a shared object that this
* user does not wish to use, or if it belongs to an
* implicit shared object.
*/
if (ifl->ifl_vercnt) {
}
}
/*
* If this symbol has been obtained from a versioned
* input relocatable object then the new symbol must be
* promoted to the versioning of the output file.
*/
if (ifl->ifl_versym)
}
((sdflags & FLG_SY_SPECSEC) == 0))
AL_CNT_SDP_DFILES) == NULL)
}
/*
* Provided we're not processing a mapfile, diagnose the entered symbol.
* Mapfile processing requires the symbol to be updated with additional
* information, therefore the diagnosing of the symbol is deferred until
* later (see Dbg_map_symbol()).
*/
return (sdp);
}
/*
* Add a special symbol to the symbol table. Takes special symbol name with
* and without underscores. This routine is called, after all other symbol
* resolution has completed, to generate a reserved absolute symbol (the
* underscore version). Special symbols are updated with the appropriate
* values in update_osym(). If the user has already defined this symbol
* issue a warning and leave the symbol as is. If the non-underscore symbol
* is referenced then turn it into a weak alias of the underscored symbol.
*
* The bits in flags_u are OR'd into the flags field of the symbol
* for the underscored symbol.
*
* If this is a global symbol, and it hasn't explicitly been defined as being
* directly bound to, indicate that it can't be directly bound to.
* Historically, most special symbols only have meaning to the object in which
* they exist, however, they've always been global. To ensure compatibility
* with any unexpected use presently in effect, ensure these symbols don't get
* directly bound to. Note, that establishing this state here isn't sufficient
* to create a syminfo table, only if a syminfo table is being created by some
* other symbol directives will the nodirect binding be recorded. This ensures
* we don't create syminfo sections for all objects we create, as this might add
* unnecessary bloat to users who haven't explicitly requested extra symbol
* information.
*/
static uintptr_t
{
/* LINTED */
/*
* If the underscore symbol exists and is undefined, or was
* defined in a shared library, convert it to a local symbol.
* Otherwise leave it as is and warn the user.
*/
/* LINTED */
/*
* If a user hasn't specifically indicated that the
* scope of this symbol be made local, then leave it
* as global (ie. prevent automatic scoping). The GOT
* should be defined protected, whereas all other
* special symbols are tagged as no-direct.
*/
(flags1 & FLG_SY1_DEFAULT)) {
if (sdaux_id == SDAUX_ID_GOT) {
} else if (
}
}
/*
* If the reference originated from a mapfile ensure
* we mark the symbol as used.
*/
} else
} else {
/*
* If the symbol does not exist create it.
*/
return (S_ERROR);
return (S_ERROR);
/* LINTED */
if (sdaux_id == SDAUX_ID_GOT) {
} else if ((flags1 & FLG_SY1_DEFAULT) &&
}
}
/*
* If the non-underscore symbol exists and is undefined
* convert it to be a local. If the underscore has
* sa_symspec set (ie. it was created above) then simulate this
* as a weak alias.
*/
/* LINTED */
} else
bind = STB_GLOBAL;
/*
* If a user hasn't specifically indicated the scope of this
* symbol be made local then leave it as global (ie. prevent
* automatic scoping). The GOT should be defined protected,
* whereas all other special symbols are tagged as no-direct.
*/
(flags1 & FLG_SY1_DEFAULT)) {
if (sdaux_id == SDAUX_ID_GOT) {
}
}
/*
* If the reference originated from a mapfile ensure
* we mark the symbol as used.
*/
}
return (1);
}
/*
* Print undefined symbols.
*/
static void
{
undef_title = FALSE;
}
/*
* Undefined symbols can fall into one of four types:
*
* - the symbol is really undefined (SHN_UNDEF).
*
* - versioning has been enabled, however this symbol has not been assigned
* to one of the defined versions.
*
* - the symbol has been defined by an implicitly supplied library, ie. one
* which was encounted because it was NEEDED by another library, rather
* than from a command line supplied library which would become the only
* dependency of the output file being produced.
*
* - the symbol has been defined by a version of a shared object that is
* not permitted for this link-edit.
*
* In all cases the file who made the first reference to this symbol will have
* been recorded via the `sa_rfile' pointer.
*/
typedef enum {
} Type;
MSG_SYM_UND_UNDEF, /* MSG_INTL(MSG_SYM_UND_UNDEF) */
MSG_SYM_UND_NOVER, /* MSG_INTL(MSG_SYM_UND_NOVER) */
MSG_SYM_UND_IMPL, /* MSG_INTL(MSG_SYM_UND_IMPL) */
MSG_SYM_UND_NOTA, /* MSG_INTL(MSG_SYM_UND_NOTA) */
MSG_SYM_UND_BNDLOCAL /* MSG_INTL(MSG_SYM_UND_BNDLOCAL) */
};
static void
{
if (undef_title)
switch (type) {
case UNDEF:
case BNDLOCAL:
break;
case NOVERSION:
break;
case IMPLICIT:
break;
case NOTAVAIL:
break;
default:
return;
}
}
/*
* At this point all symbol input processing has been completed, therefore
* complete the symbol table entries by generating any necessary internal
* symbols.
*/
{
return (1);
return (S_ERROR);
return (S_ERROR);
return (S_ERROR);
return (S_ERROR);
return (S_ERROR);
/*
* Historically we've always produced a _DYNAMIC symbol, even for
* static executables (in which case its value will be 0).
*/
return (S_ERROR);
if (OFL_ALLOW_DYNSYM(ofl))
return (S_ERROR);
/*
* A GOT reference will be accompanied by the associated GOT symbol.
* Make sure it gets assigned the appropriate special attributes.
*/
return (S_ERROR);
}
return (1);
}
/*
* This routine checks to see if a symbols visibility needs to be reduced to
* either SYMBOLIC or LOCAL. This routine can be called from either
* reloc_init() or sym_validate().
*/
void
{
/*
* If auto-reduction/elimination is enabled, reduce any
* non-versioned global symbols. This routine is called either
* from any initial relocation processing that references this
* symbol, or from the symbol validation processing.
*
* A symbol is a candidate for auto-reduction/elimination if:
*
* . the symbol wasn't explicitly defined within a mapfile
* (in which case all the necessary state has been applied
* to the symbol), or
* . the symbol isn't one of the family of reserved
* special symbols (ie. _end, _etext, etc.), or
* . the symbol isn't a SINGLETON, or
* . the symbol wasn't explicitly defined within a version
* definition associated with an input relocatable object.
*
* Indicate that the symbol has been reduced as it may be
* necessary to print these symbols later.
*/
}
}
/*
* If -Bsymbolic is in effect, and the symbol hasn't explicitly
* been defined nodirect (via a mapfile), then bind the global
* symbol symbolically and assign the STV_PROTECTED visibility
* attribute.
*/
if ((oflags & FLG_OF_SYMBOLIC) &&
}
}
/*
* Indicate that this symbol has had it's visibility checked so that
* we don't need to do this investigation again.
*/
}
/*
* Make sure a symbol definition is local to the object being built.
*/
inline static int
{
if (str) {
}
return (1);
}
if (str) {
}
return (1);
}
}
return (0);
}
/*
* Make sure all the symbol definitions required for initarray, finiarray, or
* preinitarray's are local to the object being built.
*/
static int
{
int ret = 0;
return (ret);
}
/*
* After all symbol table input processing has been finished, and all relocation
* counting has been carried out (ie. no more symbols will be read, generated,
* or modified), validate and count the relevant entries:
*
* - check and print any undefined symbols remaining. Note that
* if a symbol has been defined by virtue of the inclusion of
* an implicit shared library, it is still classed as undefined.
*
* - count the number of global needed symbols together with the
* size of their associated name strings (if scoping has been
* indicated these symbols may be reduced to locals).
*
* - establish the size and alignment requirements for the global
* .bss section (the alignment of this section is based on the
* first symbol that it will contain).
*/
{
#if defined(_ELF64)
#endif
int ret;
int allow_ldynsym;
/*
* If a symbol is undefined and this link-edit calls for no undefined
* symbols to remain (this is the default case when generating an
* executable but can be enforced for any object using -z defs), the
* symbol is classified as undefined and a fatal error condition will
* be indicated.
*
* If the symbol is undefined and we're creating a shared object with
* the -Bsymbolic flag, then the symbol is also classified as undefined
* and a warning condition will be indicated.
*/
undef = FLG_OF_WARN;
if (oflags & FLG_OF_NOUNDEF)
/*
* If the symbol is referenced from an implicitly included shared object
* (ie. it's not on the NEEDED list) then the symbol is also classified
* as undefined and a fatal error condition will be indicated.
*/
/*
* If the output image is being versioned all symbol definitions must be
* associated with a version. Any symbol that isn't is classified as
* undefined and a fatal error condition will be indicated.
*/
if (allow_ldynsym) {
/*
* Normally, we disallow symbols with 0 size from appearing
* in a dyn[sym|tls]sort section. However, there are some
* symbols that serve special purposes that we want to exempt
* from this rule. Look them up, and set their
* FLG_SY_DYNSORT flag.
*/
static const char *special[] = {
};
int i;
return (S_ERROR);
}
}
}
/*
* Collect and validate the globals from the internal symbol table.
*/
int undeferr = 0;
/*
* If undefined symbols are allowed ignore any symbols that are
* not needed.
*/
if (!(oflags & FLG_OF_NOUNDEF) &&
continue;
/*
* If the symbol originates from an external or parent mapfile
* reference and hasn't been matched to a reference from a
* relocatable object, ignore it.
*/
continue;
}
/*
* Sanity check TLS.
*/
continue;
}
}
(oflags & FLG_OF_PROCRED)) {
sdp, 0, 0));
}
/*
* Record any STV_SINGLETON existence.
*/
/*
* If building a shared object or executable, and this is a
* non-weak UNDEF symbol with reduced visibility (STV_*), then
* give a fatal error.
*/
if (((oflags & FLG_OF_RELOBJ) == 0) &&
continue;
}
}
/*
* If this symbol is defined in a non-allocatable section,
* reduce it to local symbol.
*/
}
/*
* If this symbol originated as a SHN_SUNW_IGNORE, it will have
* been processed as an SHN_UNDEF. Return the symbol to its
* original index for validation, and propagation to the output
* file.
*/
if (undef) {
/*
* If a non-weak reference remains undefined, or if a
* mapfile reference is not bound to the relocatable
* objects that make up the object being built, we have
* a fatal error.
*
* The exceptions are symbols which are defined to be
* found in the parent (FLG_SY_PARENT), which is really
* only meaningful for direct binding, or are defined
* external (FLG_SY_EXTERN) so as to suppress -zdefs
* errors.
*
* Register symbols are always allowed to be UNDEF.
*
* Note that we don't include references created via -u
* in the same shared object binding test. This is for
* backward compatibility, in that a number of archive
* makefile rules used -u to cause archive extraction.
* These same rules have been cut and pasted to apply
* to shared objects, and thus although the -u reference
* is redundant, flagging it as fatal could cause some
* build to fail. Also we have documented the use of
* -u as a mechanism to cause binding to weak version
* definitions, thus giving users an error condition
* would be incorrect.
*/
(FLG_SY_PARENT | FLG_SY_EXTERN)) == 0)) ||
(FLG_SY_MAPREF | FLG_SY_MAPUSED)) ==
FLG_SY_MAPREF) &&
FLG_SY1_PROTECT)) == 0)))) {
undeferr = 1;
}
} else {
/*
* For building things like shared objects (or anything
* -znodefs), undefined symbols are allowed.
*
* If a mapfile reference remains undefined the user
* would probably like a warning at least (they've
* usually mis-spelt the reference). Refer to the above
* comments for discussion on -u references, which
* are not tested for in the same manner.
*/
(FLG_SY_MAPREF | FLG_SY_MAPUSED)) ==
undeferr = 1;
}
}
/*
* If this symbol comes from a dependency mark the dependency
* as required (-z ignore can result in unused dependencies
* being dropped). If we need to record dependency versioning
* information indicate what version of the needed shared object
* this symbol is part of. Flag the symbol as undefined if it
* has not been made available to us.
*/
/*
* Capture that we've bound to a symbol that doesn't
* allow being directly bound to.
*/
int vndx;
} else {
continue;
}
}
}
/*
* Test that we do not bind to symbol supplied from an implicit
* shared object. If a binding is from a weak reference it can
* be ignored.
*/
continue;
}
/*
* Test that a symbol isn't going to be reduced to local scope
* which actually wants to bind to a shared object - if so it's
* a fatal error.
*/
continue;
}
/*
* If the output image is to be versioned then all symbol
* definitions must be associated with a version.
*/
continue;
}
/*
* If we don't need the symbol there's no need to process it
* any further.
*/
continue;
/*
* Calculate the size and alignment requirements for the global
* .bss and .tls sections. If we're building a relocatable
* object only account for scoped COMMON symbols (these will
* be converted to .bss references).
*
* When -z nopartial is in effect, partially initialized
* symbols are directed to the special .data section
* created for that purpose (ofl->ofl_isparexpn).
* Otherwise, partially initialized symbols go to .bss.
*
* Also refer to make_mvsections() in sunwmove.c
*/
(((oflags & FLG_OF_RELOBJ) == 0) ||
(oflags & FLG_OF_PROCRED)))) {
} else {
}
}
}
#if defined(_ELF64)
/*
* Calculate the size and alignment requirement for the global
* .lbss. TLS or partially initialized symbols do not need to be
* considered yet.
*/
}
#endif
/*
* If a symbol was referenced via the command line
* (ld -u <>, ...), then this counts as a reference against the
* symbol. Mark any section that symbol is defined in.
*/
}
/*
* Update the symbol count and the associated name string size.
*/
(oflags & FLG_OF_PROCRED)) {
/*
* If any reductions are being processed, keep a count
* of eliminated symbols, and if the symbol is being
* reduced to local, count it's size for the .symtab.
*/
ofl->ofl_elimcnt++;
} else {
ofl->ofl_scopecnt++;
return (S_ERROR);
ldynsym_symtype[type]) {
ofl->ofl_dynscopecnt++;
return (S_ERROR);
/* Include it in sort section? */
}
}
} else {
ofl->ofl_globcnt++;
/*
* Check to see if this global variable should
* go into a sort section. Sort sections require
* a .SUNW_ldynsym section, so, don't check
* unless a .SUNW_ldynsym is allowed.
*/
if (allow_ldynsym) {
}
/*
* If global direct bindings are in effect, or this
* symbol has bound to a dependency which was specified
* as requiring direct bindings, and it hasn't
* explicitly been defined as a non-direct binding
* symbol, mark it.
*/
/*
* Insert the symbol name.
*/
return (S_ERROR);
return (S_ERROR);
}
/*
* If this section offers a global symbol - record that
* fact.
*/
if (isp) {
}
}
}
/*
* If we've encountered a fatal error during symbol validation then
* return now.
*/
return (1);
/*
* Now that symbol resolution is completed, scan any register symbols.
* From now on, we're only interested in those that contribute to the
* output file.
*/
if (ofl->ofl_regsyms) {
int ndx;
continue;
continue;
}
ofl->ofl_regsymcnt++;
ofl->ofl_lregsymcnt++;
}
}
/*
* Generate the .bss section now that we know its size and alignment.
*/
if (bsssize) {
return (S_ERROR);
}
if (tlssize) {
return (S_ERROR);
}
#if defined(_ELF64)
return (S_ERROR);
}
#endif
/*
* Determine what entry point symbol we need, and if found save its
* symbol descriptor so that we can update the ELF header entry with the
* symbols value later (see update_oehdr). Make sure the symbol is
* tagged to ensure its update in case -s is in effect. Use any -e
* option first, or the default entry points `_start' and `main'.
*/
ret = 0;
if ((sdp =
ret++;
MSG_INTL(MSG_SYM_ENTRY)) != 0) {
ret++;
} else {
}
sdp, 0) == 0)) {
sdp, 0) == 0)) {
}
/*
* If ld -zdtrace=<sym> was given, then validate that the symbol is
* defined within the current object being built.
*/
/*
* If any initarray, finiarray or preinitarray functions have been
* requested, make sure they are defined within the current object
* being built.
*/
if (ofl->ofl_initarray) {
}
if (ofl->ofl_finiarray) {
}
if (ofl->ofl_preiarray) {
}
if (ret)
return (S_ERROR);
/*
* If we're required to record any needed dependencies versioning
* information calculate it now that all symbols have been validated.
*/
return (ld_vers_check_need(ofl));
else
return (1);
}
/*
* qsort(3c) comparison function. As an optimization for associating weak
* symbols to their strong counterparts sort global symbols according to their
* section index, address and binding.
*/
static int
{
/*
* Symbol descriptors may be zero, move these to the front of the
* sorted array.
*/
return (-1);
return (1);
/*
* Compare the symbols section index. This is important when sorting
* the symbol tables of relocatable objects. In this case, a symbols
* value is the offset within the associated section, and thus many
* symbols can have the same value, but are effectively different
* addresses.
*/
return (1);
return (-1);
/*
* Compare the symbols value (address).
*/
return (1);
return (-1);
/*
* If two symbols have the same address place the weak symbol before
* any strong counterpart.
*/
return (-1);
return (1);
return (0);
}
/*
* Issue a MSG_SYM_BADADDR error from ld_sym_process(). This error
* target section.
*
* Such objects are at least partially corrupt, and the user would
* be well advised to be skeptical of them, and to ask their compiler
* supplier to fix the problem. However, a distinction needs to be
* made between symbols that reference readonly text, and those that
* access writable data. Other than throwing off profiling results,
* the readonly section case is less serious. We have encountered
* such objects in the field. In order to allow existing objects
* to continue working, we issue a warning rather than a fatal error
* if the symbol is against readonly text. Other cases are fatal.
*/
static void
{
const char *msg;
SHF_ALLOC) {
flag = FLG_OF_WARN;
err = ERR_WARNING;
} else {
flag = FLG_OF_FATAL;
}
}
/*
* Process the symbol table for the specified input file. At this point all
* input sections from this input file have been assigned an input section
* descriptor which is saved in the `ifl_isdesc' array.
*
* - local symbols are saved (as is) if the input file is a
* relocatable object
*
* - global symbols are added to the linkers internal symbol
* table if they are not already present, otherwise a symbol
* resolution function is called upon to resolve the conflict.
*/
{
/*
* This macro tests the given symbol to see if it is out of
* range relative to the section it references.
*
* entry:
* - ifl is a relative object (ET_REL)
* _sdp - Symbol descriptor
* _sym - Symbol
* _type - Symbol type
*
* The following are tested:
* - Symbol length is non-zero
* - Symbol type is a type that references code or data
* - Referenced section is not 0 (indicates an UNDEF symbol)
* and is not in the range of special values above SHN_LORESERVE
* (excluding SHN_XINDEX, which is OK).
* - We have a valid section header for the target section
*
* If the above are all true, and the symbol position is not
* contained by the target section, this macro evaluates to
* True (1). Otherwise, False(0).
*/
char *strs;
int etype_rel;
const char *symsecname, *strsecname;
int test_gnu_hidden_bit, weak;
/*
* Its possible that a file may contain more that one symbol table,
* ie. .dynsym and .symtab in a shared library. Only process the first
* table (here, we assume .dynsym comes before .symtab).
*/
if (ifl->ifl_symscnt)
return (1);
if (isc->is_symshndx)
else
/*
* From the symbol tables section header information determine which
* strtab table is needed to locate the actual symbol names.
*/
return (S_ERROR);
}
else
} else {
/*
* There is no string table section in this input file
* although there are symbols in this symbol table section.
* This means that these symbols do not have names.
* Currently, only scratch register symbols are allowed
* not to have names.
*/
strsize = 0;
}
/*
* Determine the number of local symbols together with the total
* number we have to process.
*/
/*
* Allocate a symbol table index array and a local symbol array
* (global symbols are processed and added to the ofl->ofl_symbkt[]
* array). If we are dealing with a relocatable object, allocate the
* local symbol descriptors. If this isn't a relocatable object we
* still have to process any shared object locals to determine if any
* register symbols exist. Although these aren't added to the output
* image, they are used as part of symbol resolution.
*/
return (S_ERROR);
return (S_ERROR);
/* LINTED */
}
/*
* If there are local symbols to save add them to the symbol table
* index array.
*/
if (local) {
int last_file_ndx = 0;
const char *name;
int shndx_bad = 0;
int symtab_enter = 1;
/*
* Determine and validate the associated section index.
*/
/* We need the name before we can issue error */
shndx_bad = 1;
}
/*
* Check if st_name has a valid value or not.
*/
continue;
}
/*
* Now that we have the name, if the section index
* was bad, report it.
*/
if (shndx_bad) {
CONV_FMT_DECIMAL, &inv_buf));
continue;
}
/*
* If this local symbol table originates from a shared
* object, then we're only interested in recording
* register symbols. As local symbol descriptors aren't
* allocated for shared objects, one will be allocated
* to associated with the register symbol. This symbol
* won't become part of the output image, but we must
* process it to test for register conflicts.
*/
if (sdflags & FLG_SY_REGSYM) {
/*
* The presence of FLG_SY_REGSYM means that
* the pointers in ld_targ.t_ms are non-NULL.
*/
if (rsdp != 0) {
/*
* The fact that another register def-
* inition has been found is fatal.
* Call the verification routine to get
* the error message and move on.
*/
continue;
}
if ((sdp = libld_calloc(
return (S_ERROR);
/* Will not appear in output object */
symtab_enter = 0;
}
continue;
/*
* Fill in the remaining symbol descriptor information.
*/
}
}
/*
* Reclassify any SHN_SUNW_IGNORE symbols to SHN_UNDEF
* so as to simplify future processing.
*/
}
/*
* Process any register symbols.
*/
/*
* Add a diagnostic to indicate we've caught a
* register symbol, as this can be useful if a
* register conflict is later discovered.
*/
/*
* If this register symbol hasn't already been
* recorded, enter it now.
*
* The presence of FLG_SY_REGSYM means that
* the pointers in ld_targ.t_ms are non-NULL.
*/
0))
return (S_ERROR);
}
/*
* Assign an input section.
*/
/*
* If this symbol falls within the range of a section
* being discarded, then discard the symbol itself.
* There is no reason to keep this local symbol.
*/
continue;
}
/*
* Skip any section symbols as new versions of these
* will be created.
*/
&inv_buf));
}
continue;
}
/*
* For a relocatable object, if this symbol is defined
* and has non-zero length and references an address
* within an associated section, then check its extents
* to make sure the section boundaries encompass it.
* If they don't, the ELF file is corrupt.
*/
if (etype_rel) {
continue;
}
/*
* We have observed relocatable objects
* containing identical adjacent STT_FILE
* symbols. Discard any other than the first,
* as they are all equivalent and the extras
* do not add information.
*
* For the purpose of this test, we assume
* that only the symbol type and the string
* table offset (st_name) matter.
*/
last_file_sdp = sdp;
last_file_ndx = ndx;
if (toss) {
continue;
}
}
}
/*
* Sanity check for TLS
*/
continue;
}
}
/*
* Carry our some basic sanity checks (these are just
* some of the erroneous symbol entries we've come
* across, there's probably a lot more). The symbol
* will not be carried forward to the output file, which
* won't be a problem unless a relocation is required
* against it.
*/
CONV_FMT_DECIMAL, &inv_buf));
continue;
}
/*
* As these local symbols will become part of the output
* image, record their number and name string size.
* Globals are counted after all input file processing
* (and hence symbol resolution) is complete during
* sym_validate().
*/
symtab_enter) {
ofl->ofl_locscnt++;
return (S_ERROR);
ldynsym_symtype[type]) {
ofl->ofl_dynlocscnt++;
return (S_ERROR);
/* Include it in sort section? */
}
}
}
}
/*
* The GNU ld interprets the top bit of the 16-bit Versym value
* (0x8000) as the "hidden" bit. If this bit is set, the linker
* is supposed to act as if that symbol does not exist. The Solaris
* linker does not support this mechanism, or the model of interface
* evolution that it allows, but we honor it in GNU ld produced
* objects in order to interoperate with them.
*
* Determine if we should honor the GNU hidden bit for this file.
*/
/*
* Now scan the global symbols entering them in the internal symbol
* table or resolving them as necessary.
*/
weak = 0;
/* LINTED */
const char *name;
int shndx_bad = 0;
/*
* Determine and validate the associated section index.
*/
/* We need the name before we can issue error */
shndx_bad = 1;
}
/*
* Check if st_name has a valid value or not.
*/
continue;
}
/*
* Now that we have the name, if the section index
* was bad, report it.
*/
if (shndx_bad) {
CONV_FMT_DECIMAL, &inv_buf));
continue;
}
/*
* Test for the GNU hidden bit, and ignore symbols that
* have it set.
*/
if (test_gnu_hidden_bit &&
continue;
/*
* The linker itself will generate symbols for _end, _etext,
* _edata, _DYNAMIC and _PROCEDURE_LINKAGE_TABLE_, so don't
* bother entering these symbols from shared objects. This
* results in some wasted resolution processing, which is hard
* to feel, but if nothing else, pollutes diagnostic relocation
* output.
*/
continue;
}
/*
* Determine and validate the symbols binding.
*/
continue;
}
weak++;
/*
* If this symbol falls within the range of a section being
* discarded, then discard the symbol itself.
*/
if (((sdflags & FLG_SY_SPECSEC) == 0) &&
/*
* Carry our some basic sanity checks
* The symbol will not be carried forward to
* the output file, which won't be a problem
* unless a relocation is required against it.
*/
CONV_FMT_DECIMAL, &inv_buf));
continue;
}
if ((sdp =
return (S_ERROR);
/*
* Create a dummy symbol entry so that if we
* find any references to this discarded symbol
* we can compensate.
*/
continue;
}
}
/*
* If the symbol does not already exist in the internal symbol
* table add it, otherwise resolve the conflict. If the symbol
* from this file is kept, retain its symbol table index for
* possible use in associating a global alias.
*/
/* LINTED */
return (S_ERROR);
return (S_ERROR);
/*
* After we've compared a defined symbol in one shared
* object, flag the symbol so we don't compare it again.
*/
/*
* If the symbol is accepted from this file retain the symbol
* index for possible use in aliasing.
*/
/*
* If we've accepted a register symbol, continue to validate
* it.
*/
/*
* The presence of FLG_SY_REGSYM means that
* the pointers in ld_targ.t_ms are non-NULL.
*/
return (S_ERROR);
}
}
/*
* For a relocatable object, if this symbol is defined
* and has non-zero length and references an address
* within an associated section, then check its extents
* to make sure the section boundaries encompass it.
* If they don't, the ELF file is corrupt. Note that this
* global symbol may have come from another file to satisfy
* an UNDEF symbol of the same name from this one. In that
* case, we don't check it, because it was already checked
* as part of its own file.
*/
continue;
}
}
}
/*
* Associate weak (alias) symbols to their non-weak counterparts by
* scaning the global symbols one more time.
*
* This association is needed when processing the symbols from a shared
* object dependency when a a weak definition satisfies a reference:
*
* - When building a dynamic executable, if a referenced symbol is a
* data item, the symbol data is copied to the executables address
* space. In this copy-relocation case, we must also reassociate
* the alias symbol with its new location in the executable.
*
* - If the referenced symbol is a function then we may need to
* promote the symbols binding from undefined weak to undefined,
* otherwise the run-time linker will not generate the correct
* relocation error should the symbol not be found.
*
* Weak alias association is also required when a local dynsym table
* is being created. This table should only contain one instance of a
* symbol that is associated to a given address.
*
* symbol entries are identical, thus first we create a sorted symbol
* list keyed off of the symbols section index and value. If the symbol
* belongs to the same section and has the same value, then the chances
* are that the rest of the symbols data is the same. This list is then
* scanned for weak symbols, and if one is found then any strong
* association will exist in the entries that follow. Thus we just have
* to scan one (typically a single alias) or more (in the uncommon
* instance of multiple weak to strong associations) entries to
* determine if a match exists.
*/
/*
* As we might be processing many input files, and many symbols,
* try and reuse a static sort buffer. Note, presently we're
* playing the game of never freeing any buffers as there's a
* belief this wastes time.
*/
return (S_ERROR);
}
int sndx;
/*
* Ignore any empty symbol descriptor, or the case where
* the symbol has been resolved to a different file.
*/
continue;
continue;
/*
* We have a weak symbol, if it has a strong alias it
* will have been sorted to one of the following sort
* table entries. Note that we could have multiple weak
* symbols aliased to one strong (if this occurs then
* the strong symbol only maintains one alias back to
* the last weak).
*/
/*
* Ignore any empty symbol descriptor, or the
* case where the symbol has been resolved to a
* different file.
*/
continue;
continue;
break;
continue;
/*
* If a sharable object, set link fields so
* that they reference each other.`
*/
}
/*
* Determine which of these two symbols go into
* the sort section. If a mapfile has made
* explicit settings of the FLG_SY_*DYNSORT
* flags for both symbols, then we do what they
* say. If one has the DYNSORT flags set, we
* set the NODYNSORT bit in the other. And if
* neither has an explicit setting, then we
* favor the weak symbol because they usually
* lack the leading underscore.
*/
if (s_dynbits) {
if (s_dynbits == FLG_SY_DYNSORT)
} else if (w_dynbits !=
}
}
break;
}
}
}
return (1);
}
/*
* Add an undefined symbol to the symbol table. The reference originates from
* the location identifed by the message id (mid). These references can
* originate from command line options such as -e, -u, -initarray, etc.
* (identified with MSG_INTL(MSG_STR_COMMAND)), or from internally generated
* TLS relocation references (identified with MSG_INTL(MSG_STR_TLSREL)).
*/
Sym_desc *
{
/*
* As an optimization, determine whether we've already generated this
* reference. If the symbol doesn't already exist we'll create it.
* Or if the symbol does exist from a different source, we'll resolve
* the conflict.
*/
/* LINTED */
return (sdp);
}
/*
* Determine whether a pseudo input file descriptor exists to represent
* the command line, as any global symbol needs an input file descriptor
* during any symbol resolution (refer to map_ifl() which provides a
* similar method for adding symbols from mapfiles).
*/
break;
}
/*
* If no descriptor exists create one.
*/
}
/*
* Allocate a symbol structure and add it to the global symbol table.
*/
return (sdp);
}
/*
* STT_SECTION symbols have their st_name field set to NULL, and consequently
* have no name. Generate a name suitable for diagnostic use for such a symbol.
* The resulting name will be of the form:
*
* "XXX (section)"
*
* where XXX is the name of the section.
*
* Diagnostics for STT_SECTION symbols tend to come in clusters,
* so we use a static variable to retain the last string we generate. If
* another one comes along for the same section before some other section
* intervenes, we will reuse the string.
*
* entry:
* isc - Input section assocated with the symbol.
* fmt - NULL, or format string to use.
*
* exit:
* Returns the allocated string, or NULL on allocation failure.
*/
const const char *
{
static const char *last_fmt;
static char *namestr;
const char *fmt;
return (namestr);
return (NULL);
/* Remember for next time */
return (namestr);
}
return (NULL);
}