/*
* 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 (c) 2012, Joyent, Inc. All rights reserved.
*/
/*
* Processing of relocatable objects and shared objects.
*/
#define ELF_TARGET_AMD64
#define ELF_TARGET_SPARC
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <link.h>
#include <limits.h>
#include <sys/systeminfo.h>
#include <debug.h>
#include <msg.h>
#include <_libld.h>
/*
* Decide if we can link against this input file.
*/
static int
{
/*
* Check the validity of the elf header information for compatibility
* with this machine and our own internal elf library.
*/
return (0);
}
return (0);
}
return (0);
}
return (1);
}
/*
* Check sanity of file header and allocate an infile descriptor
* for the file being processed.
*/
static Ifl_desc *
{
}
return (0);
}
/*
* Is this file using 'extended Section Indexes'. If so, use the
* e_shnum & e_shstrndx which can be found at:
*
* e_shnum == Shdr[0].sh_size
* e_shstrndx == Shdr[0].sh_link
*/
name);
}
name);
}
else
} else {
}
/*
* Record this new input file on the shared object or relocatable
* object input file list.
*/
} else {
}
return (ifl);
}
/*
* Process a generic section. The appropriate section information is added
* to the files input descriptor list.
*/
static uintptr_t
{
/*
* Create a new input section descriptor. If this is a NOBITS
* section elf_getdata() will still create a data buffer (the buffer
* will be null and the size will reflect the actual memory size).
*/
return (S_ERROR);
isp->is_keyident = ident;
return (0);
}
}
/*
* Add the new input section to the files input section list and
* flag whether the section needs placing in an output section. This
* placement is deferred until all input section processing has been
* completed, as SHT_GROUP sections can provide information that will
* affect how other sections within the file should be placed.
*/
if (ident) {
}
}
return (1);
}
/*
* Determine the software capabilities of the object being built from the
* capabilities of the input relocatable objects. One software capability
*
* SF1_SUNW_FPUSED the frame pointer is in use.
*
* The resolution of the present fame pointer state, and the capabilities
* provided by a new input relocatable object are:
*
* new input relocatable object
*
* present | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
* state | SF1_SUNW_FPUSED | |
* ---------------------------------------------------------------------------
* SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
* SF1_SUNW_FPUSED | SF1_SUNW_FPUSED | | SF1_SUNW_FPUSED
* ---------------------------------------------------------------------------
* SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN
* | | |
* ---------------------------------------------------------------------------
* <unknown> | SF1_SUNW_FPKNWN | SF1_SUNW_FPKNWN | <unknown>
* | SF1_SUNW_FPUSED | |
*/
static void
{
/*
* If a mapfile has established definitions to override any object
* capabilities, ignore any new object capabilities.
*/
return;
}
#if !defined(_ELF64)
/*
* The SF1_SUNW_ADDR32 is only meaningful when building a 64-bit
* object. Warn the user, and remove the setting, if we're
* building a 32-bit object.
*/
if (val & SF1_SUNW_ADDR32) {
val &= ~SF1_SUNW_ADDR32;
}
}
#endif
/*
* If this object doesn't specify any capabilities, ignore it, and
* leave the state as is.
*/
if (val == 0)
return;
/*
* Make sure we only accept known software capabilities. Note, that
* an F1_SUNW_FPUSED by itself is viewed as bad practice.
*/
val &= SF1_SUNW_MASK;
}
return;
}
/*
* If the input file is not a relocatable object, then we're only here
* to warn the user of any questionable capabilities.
*/
#if defined(_ELF64)
/*
* If we're building a 64-bit executable, and we come across a
* dependency that requires a restricted address space, then
* that dependencies requirement can only be satisfied if the
* executable triggers the restricted address space. This is a
* warning rather than a fatal error, as the possibility exists
* that an appropriate dependency will be provided at runtime.
* The runtime linker will refuse to use this dependency.
*/
SF1_SUNW_ADDR32) == 0)) {
}
#endif
return;
}
if (DBG_ENABLED) {
}
/*
* Determine the resolution of the present frame pointer and the
* new input relocatable objects frame pointer.
*/
/*
* If the new relocatable object isn't using a frame pointer,
* reduce the present state to unused.
*/
/*
* Having processed the frame pointer bits, remove them from
* the value so they don't get OR'd in below.
*/
/*
* If the present frame pointer state is unknown, mask it out
* and allow the values from the new relocatable object
* to overwrite them.
*/
} else {
/* Do not take the frame pointer flags from the object */
}
}
/*
* Determine the hardware capabilities of the object being built from the
* capabilities of the input relocatable objects. There's really little to
* do here, other than to offer diagnostics, hardware capabilities are simply
* additive.
*/
static void
{
if (tag == CA_SUNW_HW_1) {
} else {
}
/*
* If a mapfile has established definitions to override any object
* capabilities, ignore any new object capabilities.
*/
return;
}
/*
* If this object doesn't specify any capabilities, ignore it, and
* leave the state as is.
*/
if (val == 0)
return;
if (DBG_ENABLED) {
}
}
/*
* Promote a machine capability or platform capability to the output file.
* Multiple instances of these names can be defined.
*/
static void
{
/*
* If a mapfile has established definitions to override this capability,
* ignore any new capability.
*/
return;
}
}
return;
}
}
if (DBG_ENABLED) {
}
}
}
/*
* Promote a capability identifier to the output file. A capability group can
* only have one identifier, and thus only the first identifier seen from any
* input relocatable objects is retained. An explicit user defined identifier,
* rather than an an identifier fabricated by ld(1) with -z symbcap processing,
* takes precedence. Note, a user may have defined an identifier via a mapfile,
* in which case the mapfile identifier is retained.
*/
static void
{
((flags & FLG_OCS_USRDEFID) == 0)) {
return;
}
}
CA_SUNW_ID, pstr));
CA_SUNW_ID, pstr));
}
/*
* Promote a capabilities group to the object capabilities. This catches a
* corner case. An object capabilities file can be converted to symbol
* capabilities with -z symbolcap. However, if the user has indicated that all
* the symbols should be demoted, we'd be left with a symbol capabilities file,
* with no associated symbols. Catch this case by promoting the symbol
* capabilities back to object capabilities.
*/
void
{
}
capstr)) {
}
}
capstr)) {
}
}
}
}
/*
* Determine whether a capabilities group already exists that describes this
* new capabilities group.
*
* Note, a capability group identifier, CA_SUNW_ID, isn't used as part of the
* comparison. This attribute simply assigns a diagnostic name to the group,
* and in the case of multiple identifiers, the first will be taken.
*/
static Cap_group *
{
/*
* If the new capabilities contains a CA_SUNW_ID, drop the count of the
* number of comparable items.
*/
ccnum--;
/*
* Traverse the existing symbols capabilities groups.
*/
onum--;
continue;
continue;
continue;
continue;
continue;
continue;
continue;
continue;
/*
* If a matching group is found, then this new group has
* already been supplied by a previous file, and hence the
* existing group can be used. Record this new input section,
* from which we can also derive the input file name, on the
* existing groups input sections.
*/
AL_CNT_CAP_SECS) == NULL)
return (NULL);
return (cgp);
}
/*
* If a capabilities group is not found, create a new one.
*/
AL_CNT_CAP_DESCS) == NULL))
return (NULL);
/*
* If we're converting object capabilities to symbol capabilities and
* no CA_SUNW_ID is defined, fabricate one. This identifier is appended
* to all symbol names that are converted into capabilities symbols,
* see ld_sym_process().
*/
/*
* Create an identifier using the group number together with a
* default template. We allocate a buffer large enough for any
* possible number of items (way more than we need).
*/
return (NULL);
cnum++;
}
/*
* Null the callers alist's as they've effectively been transferred
* to this new Cap_group.
*/
/*
* Keep track of which input section, and hence input file, established
* this group.
*/
return (NULL);
/*
* Keep track of the number of symbol capabilities entries that will be
* required in the output file. Each group requires a terminating
* CA_SUNW_NULL.
*/
return (cgp);
}
/*
* Capture symbol capability family information. This data structure is focal
* in maintaining all symbol capability relationships, and provides for the
* eventual creation of a capabilities information section, and possibly a
* capabilities chain section.
*
* Capabilities families are lead by a CAPINFO_SUNW_GLOB symbol. This symbol
* provides the visible global symbol that is referenced by all external
* pair, such as memcpy()/_memcpy() may lead the same capabilities family.
* Each family contains one or more local symbol members. These members provide
* the capabilities specific functions, and are associated to a capabilities
* group. For example, the capability members memcpy%sun4u and memcpy%sun4v
* might be associated with the memcpy() capability family.
*
* This routine is called when a relocatable object that provides object
* capabilities is transformed into a symbol capabilities object, using the
* -z symbolcap option.
*
* This routine is also called to collect the SUNW_capinfo section information
* of a relocatable object that contains symbol capability definitions.
*/
{
/*
* Make sure the capability families have an initialized AVL tree.
*/
return (S_ERROR);
/*
* When creating a dynamic object, capability family members
* are maintained in a .SUNW_capchain, the first entry of
* which is the version number of the chain.
*/
}
/*
* Determine whether a family already exists, and if not, create one
* using the lead family symbol.
*/
return (S_ERROR);
/*
* When creating a dynamic object, capability family members
* are maintained in a .SUNW_capchain, each family starts with
* this lead symbol, and is terminated with a 0 element.
*/
}
/*
* If no group information is provided then this request is to add a
* lead capability symbol, or lead symbol alias. If this is the lead
* symbol there's nothing more to do. Otherwise save the alias.
*/
AL_CNT_CAP_ALIASES) == NULL))
return (S_ERROR);
return (0);
}
/*
* Determine whether a member of the same group as this new member is
* already defined within this family. If so, we have a multiply
* defined symbol.
*/
continue;
/*
* Diagnose that a multiple symbol definition exists.
*/
}
/*
* Add this capabilities symbol member to the family.
*/
return (S_ERROR);
/*
* When creating a dynamic object, capability family members are
* maintained in a .SUNW_capchain. Account for this family member.
*/
ofl->ofl_capchaincnt++;
/*
* If this input file is undergoing object capabilities to symbol
* capabilities conversion, then this member is a new local symbol
* that has been generated from an original global symbol. Keep track
* of this symbol so that the output file symbol table can be populated
* with these new symbol entries.
*/
return (S_ERROR);
return (0);
}
/*
* Process a SHT_SUNW_cap capabilities section.
*/
static uintptr_t
{
char *strs;
/*
* Determine the capabilities data and size.
*/
return (0);
/*
* Traverse the section to determine what capabilities groups are
* available.
*
* A capabilities section can contain one or more, CA_SUNW_NULL
* terminated groups.
*
* - The first group defines the object capabilities.
* - Additional groups define symbol capabilities.
* - Since the initial group is always reserved for object
* capabilities, any object with symbol capabilities must also
* have an object capabilities group. If the object has no object
* capabilities, an empty object group is defined, consisting of a
* CA_SUNW_NULL element in index [0].
* - If any capabilities require references to a named string, then
* the section header sh_info points to the associated string
* table.
* - If an object contains symbol capability groups, then the
* section header sh_link points to the associated capinfo table.
*/
objcapndx = 0;
nulls = 0;
case CA_SUNW_NULL:
/*
* If this is the first CA_SUNW_NULL entry, and no
* capabilities group has been found, then this object
* does not define any object capabilities.
*/
if (nulls++ == 0) {
if (ndx == 0)
objcapndx = -1;
break;
case CA_SUNW_PLAT:
case CA_SUNW_MACH:
case CA_SUNW_ID:
capstrs++;
/* FALLTHROUGH */
case CA_SUNW_HW_1:
case CA_SUNW_SF_1:
case CA_SUNW_HW_2:
/*
* If this is the start of a new group, save it.
*/
if (descapndx == -1)
break;
default:
}
}
/*
* If a string capabilities entry has been found, the capabilities
* section must reference the associated string table.
*/
if (capstrs) {
return (S_ERROR);
}
}
/*
* The processing of capabilities groups is as follows:
*
* - if a relocatable object provides only object capabilities, and
* the -z symbolcap option is in effect, then the object
* capabilities are transformed into symbol capabilities and the
* symbol capabilities are carried over to the output file.
* - in all other cases, any capabilities present in an input
* relocatable object are carried from the input object to the
* output without any transformation or conversion.
*
* Capture any object capabilities that are to be carried over to the
* output file.
*/
if ((objcapndx == 0) &&
/*
* Object capabilities end at the first null.
*/
break;
/*
* Only the object software capabilities that are
* defined in a relocatable object become part of the
* object software capabilities in the output file.
* However, check the validity of any object software
* capabilities of any dependencies.
*/
continue;
}
/*
* The remaining capability types must come from a
* relocatable object in order to contribute to the
* output.
*/
continue;
case CA_SUNW_HW_1:
case CA_SUNW_HW_2:
break;
case CA_SUNW_PLAT:
break;
case CA_SUNW_MACH:
break;
case CA_SUNW_ID:
break;
default:
assert(0); /* Unknown capability type */
}
}
/*
* If there are no symbol capabilities, or this objects
* capabilities aren't being transformed into a symbol
* capabilities, then we're done.
*/
if ((symcapndx == -1) &&
return (1);
}
/*
* If these capabilities don't originate from a relocatable object
* there's no further processing required.
*/
return (1);
/*
* If this object only defines an object capabilities group, and the
* -z symbolcap option is in effect, then all global function symbols
* and initialized global data symbols are renamed and assigned to the
* transformed symbol capabilities group.
*/
if ((objcapndx == 0) &&
/*
* Allocate a capabilities descriptor to collect the capabilities data
* for this input file. Allocate a mirror of the raw capabilities data
* that points to the individual symbol capabilities groups. An APlist
* is used, although it will be sparsely populated, as the list provides
* a convenient mechanism for traversal later.
*/
return (S_ERROR);
/*
* Clear the allocated APlist data array, and assign the number of
* items as the total number of array items.
*/
(cnum * sizeof (void *)));
/*
* Traverse the capabilities data, unpacking the data into a
* capabilities set. Process each capabilities set as a unique group.
*/
descapndx = -1;
nulls = 0;
case CA_SUNW_NULL:
nulls++;
/*
* Process the capabilities group that this null entry
* terminates. The capabilities group that is returned
* will either point to this file's data, or to a
* matching capabilities group that has already been
* processed.
*
* Note, if this object defines object capabilities,
* the first group descriptor points to these object
* capabilities. It is only necessary to save this
* descriptor when object capabilities are being
* transformed into symbol capabilities (-z symbolcap).
*/
if (descapndx != -1) {
if ((nulls > 1) ||
return (S_ERROR);
}
/*
* Clean up the capabilities data in preparation
* for processing additional groups. If the
* collected capabilities strings were used to
* establish a new output group, they will have
* been saved in get_cap_group(). If these
* descriptors still exist, then an existing
* descriptor has been used to associate with
* this file, and these string descriptors can
* be freed.
*/
}
}
descapndx = -1;
}
continue;
case CA_SUNW_HW_1:
break;
case CA_SUNW_SF_1:
break;
case CA_SUNW_HW_2:
break;
case CA_SUNW_PLAT:
return (S_ERROR);
break;
case CA_SUNW_MACH:
return (S_ERROR);
break;
case CA_SUNW_ID:
break;
}
/*
* Save the start of this new group.
*/
if (descapndx == -1)
}
return (1);
}
/*
* Capture any symbol capabilities symbols. An object file that contains symbol
* capabilities has an associated .SUNW_capinfo section. This section
* identifies which symbols are associated to which capabilities, together with
* their associated lead symbol. Each of these symbol pairs are recorded for
* processing later.
*/
static uintptr_t
{
return (0);
continue;
/*
* Catch any anomalies. A capabilities symbol should be valid,
* and the capabilities lead symbol should also be global.
* Note, ld(1) -z symbolcap would create local capabilities
* symbols, but we don't enforce this so as to give the
* compilation environment a little more freedom.
*/
continue;
}
lndx);
continue;
}
/*
* Indicate that this is a capabilities symbol.
*/
/*
* Save any global capability symbols. Global capability
* symbols are identified with a CAPINFO_SUNW_GLOB group id.
* The lead symbol for this global capability symbol is either
* the symbol itself, or an alias.
*/
if (gndx == CAPINFO_SUNW_GLOB) {
return (S_ERROR);
continue;
}
/*
* Track the number of non-global capabilities symbols, as these
* are used to size any symbol tables. If we're generating a
* dynamic object, this symbol will be added to the dynamic
* symbol table, therefore ensure there is space in the dynamic
* string table.
*/
ofl->ofl_caploclcnt++;
return (S_ERROR);
/*
* As we're tracking this local symbol as a capabilities symbol,
* reduce the local symbol count to compensate.
*/
ofl->ofl_locscnt--;
/*
* Determine whether the associated lead symbol indicates
* NODYNSORT. If so, remove this local entry from the
* SUNW_dynsort section too. NODYNSORT tagging can only be
* obtained from a mapfile symbol definition, and thus any
* global definition that has this tagging has already been
* instantiated and this instance resolved to it.
*/
}
/*
* Track this family member, together with its associated group.
*/
return (S_ERROR);
}
return (0);
}
/*
* Simply process the section so that we have pointers to the data for use
* in later routines, however don't add the section to the output section
* list as we will be creating our own replacement sections later (ie.
* symtab and relocation).
*/
static uintptr_t
/* ARGSUSED5 */
{
}
/*
* Keep a running count of relocation entries from input relocatable objects for
* sizing relocation buckets later. If we're building an executable, save any
* relocations from shared objects to determine if any copy relocation symbol
* has a displacement relocation against it.
*/
static uintptr_t
/* ARGSUSED5 */
{
return (S_ERROR);
/* LINTED */
ofl->ofl_relocincnt +=
AL_CNT_IFL_RELSECS) == NULL)
return (S_ERROR);
}
return (1);
}
/*
* Process a string table section. A valid section contains an initial and
* final null byte.
*/
static uintptr_t
{
char *data;
/*
* Never include .stab.excl sections in any output file.
* If the -s flag has been specified strip any .stab sections.
*/
return (1);
/*
* If we got here to process a .shstrtab or .dynstr table, `ident' will
* be null. Otherwise make sure we don't have a .strtab section as this
* should not be added to the output section list either.
*/
return (error);
/*
* String tables should start and end with a NULL byte. Note, it has
* been known for the assembler to create empty string tables, so check
* the size before attempting to verify the data itself.
*/
if (size) {
} else
return (1);
}
/*
* Invalid sections produce a warning and are skipped.
*/
static uintptr_t
/* ARGSUSED3 */
{
return (1);
}
/*
* Compare an input section name to a given string, taking the ELF '%'
* section naming convention into account. If an input section name
* contains a '%' character, the '%' and all following characters are
* ignored in the comparison.
*
* entry:
* is_name - Name of input section
* match_name - Name to compare to
* match_len - strlen(match_name)
*
* exit:
* Returns True (1) if the names match, and False (0) otherwise.
*/
inline static int
{
/*
* If the start of is_name is not a match for name,
* the match fails.
*/
return (0);
/*
* The prefix matched. The next character must be either '%', or
* NULL, in order for a match to be true.
*/
}
/*
* Helper routine for process_progbits() to process allocable sections.
*
* entry:
* name, ifl, shdr, ndx, ident, ofl - As passed to process_progbits().
* is_stab_index - TRUE if section is .index.
* is_flags - Additional flags to be added to the input section.
*
* exit:
* The allocable section has been processed. *ident and *is_flags
* are updated as necessary to reflect the changes. Returns TRUE
* for success, FALSE for failure.
*/
/*ARGSUSED*/
inline static Boolean
{
if (name[0] == '.') {
switch (name[1]) {
case 'e':
break;
*is_flags |= FLG_IS_EHFRAME;
/*
* Historically, the section containing the logic to
* unwind stack frames -- the .eh_frame section -- was
* of type SHT_PROGBITS. Apparently the most
* aesthetically galling aspect of this was not the
* .eh_frame section's dubious purpose or its filthy
* implementation, but rather its section type; with the
* introduction of the AMD64 ABI, a new section header
* type (SHT_AMD64_UNWIND) was introduced for (and
* dedicated to) this section. When both the Sun
* compilers and the GNU compilers had been modified to
* generate this new section type, the linker became
* much more pedantic about .eh_frame: it refused to
* link an AMD64 object that contained a .eh_frame with
* the legacy SHT_PROGBITS. That this was too fussy is
* evidenced by searching the net for the error message
* that it generated ("section type is SHT_PROGBITS:
* expected SHT_AMD64_UNWIND"), which reveals a myriad
* of problems, including legacy objects, hand-coded
* assembly and otherwise cross-platform objects
* created on other platforms (the GNU toolchain was
* only modified to create the new section type on
* Solaris and derivatives). We therefore always accept
* a .eh_frame of SHT_PROGBITS -- regardless of
* m_sht_unwind.
*/
break;
case 'g':
MSG_SCN_GOT_SIZE)) {
break;
}
break;
}
break;
case 'p':
MSG_SCN_PLT_SIZE)) {
}
break;
}
}
if (!done) {
if (is_stab_index) {
/*
* This is a work-around for x86 compilers that have
* set SHF_ALLOC for the .stab.index section.
*
* Because of this, make sure that the .stab.index
* does not end up as the last section in the text
* segment. Older linkers can produce segmentation
* violations when they strip (ld -s) against a
* shared object whose last section in the text
* segment is a .stab.
*/
} else {
}
}
return (TRUE);
}
/*
* Process a progbits section.
*/
static uintptr_t
{
uintptr_t r;
/*
* Never include .stab.excl sections in any output file.
* If the -s flag has been specified strip any .stab sections.
*/
MSG_SCN_STAB_SIZE) == 0)) {
MSG_ORIG(MSG_SCN_EXCL)) == 0))
return (1);
MSG_ORIG(MSG_SCN_INDEX)) == 0)
}
MSG_SCN_DEBUG_SIZE) == 0) ||
return (1);
}
/*
* Update the ident to reflect the type of section we've got.
*
* If there is any .plt or .got section to generate we'll be creating
* our own version, so don't allow any input sections of these types to
* be added to the output section list (why a relocatable object would
* have a .plt or .got is a mystery, but stranger things have occurred).
*
* If there are any unwind sections, and this is a platform that uses
* SHT_PROGBITS for unwind sections, then set their ident to reflect
* that.
*/
if (ident) {
(SHF_ALLOC | SHF_EXECINSTR)) {
return (S_ERROR);
} else {
}
}
/*
* On success, process_section() creates an input section descriptor.
* Now that it exists, we can add any pending input section flags.
*/
if ((is_flags != 0) && (r == 1))
return (r);
}
/*
* Handles the SHT_SUNW_{DEBUG,DEBUGSTR) sections.
*/
static uintptr_t
{
/*
* Debug information is discarded when the 'ld -s' flag is invoked.
*/
return (1);
}
}
/*
* Process a nobits section.
*/
static uintptr_t
{
if (ident) {
#if defined(_ELF64)
#endif
else
}
}
/*
* Process a SHT_*_ARRAY section.
*/
static uintptr_t
{
if (ident)
return (error);
return (1);
}
static uintptr_t
/* ARGSUSED1 */
{
return (0);
return (1);
}
/*
* Process a SHT_SYMTAB_SHNDX section.
*/
static uintptr_t
{
return (S_ERROR);
/*
* Have we already seen the related SYMTAB - if so verify it now.
*/
return (S_ERROR);
}
}
return (1);
}
/*
* Final processing for SHT_SYMTAB_SHNDX section.
*/
static uintptr_t
/* ARGSUSED2 */
{
return (S_ERROR);
}
}
return (1);
}
/*
* Process .dynamic section from a relocatable object.
*
* Note: That the .dynamic section is only considered interesting when
* dlopen()ing a relocatable object (thus FLG_OF1_RELDYN can only get
* set when libld is called from ld.so.1).
*/
/*ARGSUSED*/
static uintptr_t
{
char *str;
/*
* Process .dynamic sections from relocatable objects ?
*/
return (1);
/*
* Find the string section associated with the .dynamic section.
*/
return (0);
}
/*
* And get the .dynamic data
*/
case DT_NEEDED:
case DT_USED:
AL_CNT_OFL_LIBS) == NULL))
return (S_ERROR);
break;
case DT_RPATH:
case DT_RUNPATH:
(const char *)S_ERROR)
return (S_ERROR);
break;
case DT_VERSYM:
/*
* The Solaris ld does not put DT_VERSYM in the
* dynamic section. If the object has DT_VERSYM,
* then it must have been produced by the GNU ld,
* and is using the GNU style of versioning.
*/
break;
}
}
return (1);
}
/*
* Expand implicit references. Dependencies can be specified in terms of the
* $ORIGIN, $MACHINE, $PLATFORM, $OSREL and $OSNAME tokens, either from their
* needed name, or via a runpath. In addition runpaths may also specify the
* $ISALIST token.
*
* Probably the most common reference to explicit dependencies (via -L) will be
* sufficient to find any associated implicit dependencies, but just in case we
* expand any occurrence of these known tokens here.
*
* Note, if any errors occur we simply return the original name.
*
*/
static char *
{
const char *optr;
while (*optr) {
if (nrem == 0)
return ((char *)name);
if (*optr != '$') {
continue;
}
_expanded = 0;
MSG_STR_ORIGIN_SIZE) == 0) {
char *eptr;
/*
* For $ORIGIN, expansion is really just a concatenation
* of the parents directory name. For example, an
*/
*nptr++ = '.';
nrem--;
} else {
return ((char *)name);
}
MSG_STR_MACHINE_SIZE) == 0) {
/*
* Establish the machine from sysconf - like uname -i.
*/
long size;
if ((size != -1) &&
} else
machine_sz = 1;
}
if (machine) {
if (machine_sz >= nrem)
return ((char *)name);
nrem -= machine_sz;
}
MSG_STR_PLATFORM_SIZE) == 0) {
/*
* Establish the platform from sysconf - like uname -i.
*/
long size;
if ((size != -1) &&
} else
platform_sz = 1;
}
if (platform) {
if (platform_sz >= nrem)
return ((char *)name);
nrem -= platform_sz;
}
MSG_STR_OSNAME_SIZE) == 0) {
/*
* Establish the os name - like uname -s.
*/
return ((char *)name);
uts->uts_osnamesz);
}
MSG_STR_OSREL_SIZE) == 0) {
/*
* Establish the os release - like uname -r.
*/
return ((char *)name);
uts->uts_osrelsz);
}
/*
* Establish instruction sets from sysconf. Note that
* this is only meaningful from runpaths.
*/
isa = conv_isalist();
char *lptr;
opt->isa_namesz);
/*
* As ISALIST expands to a number of elements,
* establish a new list to return to the caller.
* This will contain the present path being
* processed redefined for each isalist option,
* plus the original remaining list entries.
*/
if (*next)
return (0);
opt->isa_namesz);
*lptr++ = ':';
}
if (*next)
else
*--lptr = '\0';
}
}
/*
* If no expansion occurred skip the $ and continue.
*/
if (_expanded == 0)
}
/*
* If any ISALIST processing has occurred not only do we return the
* expanded node we're presently working on, but we must also update the
* remaining list so that it is effectively prepended with this node
* expanded to all remaining isalist options. Note that we can only
* handle one ISALIST per node. For more than one ISALIST to be
* processed we'd need a better algorithm than above to replace the
* newly generated list. Whether we want to encourage the number of
* pathname permutations this would provide is another question. So, for
* now if more than one ISALIST is encountered we return the original
* node untouched.
*/
if (isaflag) {
if (isaflag == 1)
else
return ((char *)name);
}
*nptr = '\0';
if (expanded) {
return ((char *)name);
return (nptr);
}
return ((char *)name);
}
/*
* The Solaris ld does not put DT_VERSYM in the dynamic section, but the
* GNU ld does, and it is used by the runtime linker to implement their
* versioning scheme. Use this fact to determine if the sharable object
* was produced by the GNU ld rather than the Solaris one, and to set
* FLG_IF_GNUVER if so. This needs to be done before the symbols are
* processed, since the answer determines whether we interpret the
* symbols versions according to Solaris or GNU rules.
*/
/*ARGSUSED*/
static uintptr_t
{
return (error);
/* Get the .dynamic data */
break;
}
}
return (1);
}
/*
* Process a dynamic section. If we are processing an explicit shared object
* then we need to determine if it has a recorded SONAME, if so, this name will
* be recorded in the output file being generated as the NEEDED entry rather
* than the shared objects filename itself.
* If the mode of the link-edit indicates that no undefined symbols should
* remain, then we also need to build up a list of any additional shared object
* dependencies this object may have. In this case save any NEEDED entries
* together with any associated run-path specifications. This information is
* recorded on the `ofl_soneed' list and will be analyzed after all explicit
* file processing has been completed (refer finish_libs()).
*/
static uintptr_t
{
/* Determine if we need to examine the runpaths and NEEDED entries */
/*
* First loop through the dynamic section looking for a run path.
*/
if (no_undef) {
continue;
continue;
break;
}
}
/*
* Now look for any needed dependencies (which may use the rpath)
* or a new SONAME.
*/
continue;
/*
* Update the input file structure with this new name.
*/
if (!no_undef)
continue;
continue;
/*
* Determine if this needed entry is already recorded on
* the shared object needed list, if not create a new
* definition for later processing (see finish_libs()).
*/
return (S_ERROR);
}
/*
* Record the runpath (Note that we take the first
* runpath which is exactly what ld.so.1 would do during
* its dependency processing).
*/
/*
* If we are building an executable, and this
* dependency is tagged as an interposer, then
* assume that it is required even if symbol
* resolution uncovers no evident use.
*
* If we are building a shared object, then an
* interposer dependency has no special meaning, and we
* treat it as a regular dependency. By definition, all
* interposers must be visible to the runtime linker
* at initialization time, and cannot be added later.
*/
/*
* Record audit string as DT_DEPAUDIT.
*/
(const char *)S_ERROR)
return (S_ERROR);
/*
* If this dependency has the DT_SUNW_RTLDINF .dynamic
* entry, then ensure no specialized dependency
* processing is in effect. This tag identifies libc,
* which provides critical startup information (TLS
* routines, threads initialization, etc.) that must
* be exercised as part of process initialization.
*/
/*
* libc is not subject to the usual guidance checks
* for lazy loading. It cannot be lazy loaded, libld
* ignores the request, and rtld would ignore the
* setting if it were present.
*/
}
}
/*
* Perform some SONAME sanity checks.
*/
/*
* Determine if anyone else will cause the same SONAME to be
* used (this is either caused by two different files having the
* same SONAME, or by one file SONAME actually matching another
* file basename (if no SONAME is specified within a shared
* library its basename will be used)). Probably rare, but some
* idiot will do it.
*/
/*
* Determine the basename of each file. Perhaps
* there are multiple copies of the same file
* being brought in using different -L search
* paths, and if so give an extra hint in the
* error message.
*/
else
iflb++;
else
siflb++;
else
return (0);
}
}
/*
* If the SONAME is the same as the name the user wishes to
* record when building a dynamic library (refer -h option),
* we also have a name clash.
*/
if (ofl->ofl_soname &&
return (0);
}
}
return (1);
}
/*
* Process a progbits section from a relocatable object (ET_REL).
* This is used on non-amd64 objects to recognize .eh_frame sections.
*/
/*ARGSUSED1*/
static uintptr_t
{
return (S_ERROR);
return (1);
}
/*
* Process a group section.
*/
static uintptr_t
{
return (error);
/*
* Indicate that this input file has groups to process. Groups are
* processed after all input sections have been processed.
*/
return (1);
}
/*
* Process a relocation entry. 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.
*/
static uintptr_t
{
/*
* Make sure this is a valid relocation we can handle.
*/
return (0);
}
/*
* From the relocation section header information determine which
* section needs the actual relocation. Determine which output section
* this input section has been assigned to and add to its relocation
* list. Note that the relocation section may be null if it is not
* required (ie. .debug, .stabs, etc).
*/
/*
* Broken input file.
*/
return (0);
}
if (rndx == 0) {
AL_CNT_OFL_RELS) == NULL)
return (S_ERROR);
/*
* Discard relocations if they are against a section
* which has been discarded.
*/
return (1);
/*
* This section is processed later in
* process_movereloc().
*/
return (S_ERROR);
return (1);
}
return (0);
}
AL_CNT_OS_RELISDESCS) == NULL)
return (S_ERROR);
}
return (1);
}
/*
* SHF_EXCLUDE flags is set for this section.
*/
static uintptr_t
{
/*
* Sections SHT_SYMTAB and SHT_DYNDYM, even if SHF_EXCLUDE is on, might
* be needed for ld processing. These sections need to be in the
* internal table. Later it will be determined whether they can be
* eliminated or not.
*/
return (0);
/*
* Other checks
*/
/*
* A conflict, issue an warning message, and ignore the section.
*/
return (0);
}
/*
* This sections is not going to the output file.
*/
}
/*
* Section processing state table. `Initial' describes the required initial
* procedure to be called (if any), `Final' describes the final processing
* procedure (ie. things that can only be done when all required sections
* have been collected).
*/
/* ET_REL ET_DYN */
};
/* ET_REL ET_DYN */
};
/*
* Process an elf file. Each section is compared against the section state
* table to determine whether it should be processed (saved), ignored, or
* is invalid for the type of input file being processed.
*/
static uintptr_t
{
int ident;
/*
* Path information buffer used by ld_place_section() and related
* routines. This information is used to evaluate entrance criteria
* with non-empty file matching lists (ec_files).
*/
/*
* First process the .shstrtab section so that later sections can
* reference their name.
*/
return (0);
}
return (0);
}
NULL) {
return (0);
}
return (S_ERROR);
/*
* Reset the name since the shdr->sh_name could have been changed as
* part of ld_sup_input_section().
*/
NULL) {
return (0);
}
return (error);
/*
* Determine the state table column from the input file type. Note,
* shared library sections are not added to the output section list.
*/
column = 1;
ofl->ofl_soscnt++;
} else {
column = 0;
ofl->ofl_objscnt++;
}
ndx = 0;
ndx++;
/*
* As we've already processed the .shstrtab don't do it again.
*/
continue;
return (0);
}
return (S_ERROR);
/*
* Reset the name since the shdr->sh_name could have been
* changed as part of ld_sup_input_section().
*/
/*
* If the section has the SHF_EXCLUDE flag on, and we're not
* generating a relocatable object, exclude the section.
*/
return (S_ERROR);
if (error == 1)
continue;
}
/*
* If this is a standard section type process it via the
* appropriate action routine.
*/
return (S_ERROR);
}
} else {
/*
* If this section is below SHT_LOSUNW then we don't
* really know what to do with it, issue a warning
* message but do the basic section processing anyway.
*/
}
/*
* Handle sections greater than SHT_LOSUNW.
*/
switch (row) {
case SHT_SUNW_dof:
return (S_ERROR);
break;
case SHT_SUNW_cap:
return (S_ERROR);
break;
case SHT_SUNW_capinfo:
return (S_ERROR);
break;
case SHT_SUNW_DEBUGSTR:
case SHT_SUNW_DEBUG:
return (S_ERROR);
break;
case SHT_SUNW_move:
return (S_ERROR);
break;
case SHT_SUNW_syminfo:
return (S_ERROR);
break;
case SHT_SUNW_ANNOTATE:
return (S_ERROR);
break;
case SHT_SUNW_COMDAT:
return (S_ERROR);
break;
case SHT_SUNW_verdef:
return (S_ERROR);
break;
case SHT_SUNW_verneed:
return (S_ERROR);
break;
case SHT_SUNW_versym:
return (S_ERROR);
break;
case SHT_SPARC_GOTDATA:
/*
* SHT_SPARC_GOTDATA (0x70000000) is in the
* SHT_LOPROC - SHT_HIPROC range reserved
* for processor-specific semantics. It is
* only meaningful for sparc targets.
*/
goto do_default;
return (S_ERROR);
break;
#if defined(_ELF64)
case SHT_AMD64_UNWIND:
/*
* SHT_AMD64_UNWIND (0x70000001) is in the
* SHT_LOPROC - SHT_HIPROC range reserved
* for processor-specific semantics. It is
* only meaningful for amd64 targets.
*/
goto do_default;
/*
* Target is x86, so this really is
* SHT_AMD64_UNWIND
*/
if (column == 0) {
/*
* column == ET_REL
*/
return (S_ERROR);
}
break;
#endif
default:
return (S_ERROR);
break;
}
}
}
/*
* Now that all input sections have been analyzed, and prior to placing
* any input sections to their output sections, process any groups.
* Groups can contribute COMDAT items, which may get discarded as part
* of placement. In addition, COMDAT names may require transformation
* to indicate different output section placement.
*/
continue;
return (S_ERROR);
}
}
/*
* Now group information has been processed, we can safely validate
* that nothing is fishy about the section COMDAT description. We
* need to do this prior to placing the section (where any
* SHT_SUNW_COMDAT sections will be restored to being PROGBITS)
*/
/*
* Now that all of the input sections have been processed, place
* them in the appropriate output sections.
*/
continue;
/*
* Place all non-ordered sections within their appropriate
* output section.
*/
return (S_ERROR);
continue;
}
/*
* Count the number of ordered sections and retain the first
* ordered section index. This will be used to optimize the
* ordered section loop that immediately follows this one.
*/
ordcnt++;
if (ordndx == 0)
}
/*
* Having placed all the non-ordered sections, it is now
* safe to place SHF_ORDERED/SHF_LINK_ORDER sections.
*/
(FLG_IS_PLACE | FLG_IS_ORDERED)) !=
(FLG_IS_PLACE | FLG_IS_ORDERED)))
continue;
/* ld_process_ordered() calls ld_place_section() */
return (S_ERROR);
/* If we've done them all, stop searching */
if (--ordcnt == 0)
break;
}
}
/*
* If this is a shared object explicitly specified on the command
* line (as opposed to being a dependency of such an object),
* determine if the user has specified a control definition. This
* descriptor may specify which version definitions can be used
* from this object. It may also update the dependency to USED and
* supply an alternative SONAME.
*/
const char *base;
/*
* Use the basename of the input file (typically this is the
* compilation environment name, ie. libfoo.so).
*/
else
base++;
}
}
/*
* Before symbol processing, process any capabilities. Capabilities
* can reference a string table, which is why this processing is
* carried out after the initial section processing. Capabilities,
* together with -z symbolcap, can require the conversion of global
* symbols to local symbols.
*/
return (S_ERROR);
/*
* Process any version dependencies. These will establish shared object
* `needed' entries in the same manner as will be generated from the
* .dynamic's NEEDED entries.
*/
return (S_ERROR);
/*
* Before processing any symbol resolution or relocations process any
* version sections.
*/
if (vsyisp)
if (ifl->ifl_versym &&
return (S_ERROR);
/*
* Having collected the appropriate sections carry out any additional
* processing if necessary.
*/
continue;
/*
* If this is a SHT_SUNW_move section from a relocatable file,
* keep track of the section for later processing.
*/
AL_CNT_OFL_MOVE) == NULL)
return (S_ERROR);
}
/*
* If this is a standard section type process it via the
* appropriate action routine.
*/
return (S_ERROR);
}
#if defined(_ELF64)
/*
* SHT_AMD64_UNWIND (0x70000001) is in the SHT_LOPROC -
* SHT_HIPROC range reserved for processor-specific
* semantics, and is only meaningful for amd64 targets.
*
* Only process unwind contents from relocatable
* objects.
*/
return (S_ERROR);
#endif
}
}
/*
* Following symbol processing, if this relocatable object input file
* provides symbol capabilities, tag the associated symbols so that
* the symbols can be re-assigned to the new capabilities symbol
* section that will be created for the output file.
*/
return (S_ERROR);
/*
* After processing any symbol resolution, and if this dependency
* indicates it contains symbols that can't be directly bound to,
* set the symbols appropriately.
*/
(FLG_IF_NEEDED | FLG_IF_NODIRECT)))
return (1);
}
/*
* Process the current input file. There are basically three types of files
* that come through here:
*
* - files explicitly defined on the command line (ie. foo.o or bar.so),
* in this case only the `name' field is valid.
*
* - libraries determined from the -l command line option (ie. -lbar),
* in this case the `soname' field contains the basename of the located
* file.
*
* Any shared object specified via the above two conventions must be recorded
* as a needed dependency.
*
* - libraries specified as dependencies of those libraries already obtained
* in this case the `soname' field contains either a full pathname (if the
* needed entry contained a `/'), or the basename of the located file.
* These libraries are processed to verify symbol binding but are not
* recorded as dependencies of the output file being generated.
*
* entry:
* name - File name
* soname - SONAME for needed sharable library, as described above
* fd - Open file descriptor
* elf - Open ELF handle
* flags - FLG_IF_ flags applicable to file
* ofl - Output file descriptor
* rej - Rejection descriptor used to record rejection reason
* ifl_ret - NULL, or address of pointer to receive reference to
* resulting input descriptor for file. If ifl_ret is non-NULL,
* the file cannot be an archive or it will be rejected.
*
* exit:
* If a error occurs in examining the file, S_ERROR is returned.
* If the file can be examined, but is not suitable, *rej is updated,
* and 0 is returned. If the file is acceptable, 1 is returned, and if
* ifl_ret is non-NULL, *ifl_ret is set to contain the pointer to the
* resulting input descriptor.
*/
{
/*
* If this file was not extracted from an archive obtain its device
* information. This will be used to determine if the file has already
* been processed (rather than simply comparing filenames, the device
* information provides a quicker comparison and detects linked files).
*/
else {
}
case ELF_K_AR:
/*
* If the caller has supplied a non-NULL ifl_ret, then
* we cannot process archives, for there will be no
* input file descriptor for us to return. In this case,
* reject the attempt.
*/
}
return (0);
}
/*
* Determine if we've already come across this archive file.
*/
if (!(flags & FLG_IF_EXTRACT)) {
continue;
/*
* We've seen this file before so reuse the
* original archive descriptor and discard the
* new elf descriptor. Note that a file
* descriptor is unnecessary, as the file is
* already available in memory.
*/
return (S_ERROR);
return (1);
}
}
/*
* As we haven't processed this file before establish a new
* archive descriptor.
*/
/*
* Indicate that the ELF descriptor no longer requires a file
* descriptor by reading the entire file. The file is already
* read via the initial mmap(2) behind elf_begin(3elf), thus
* this operation is effectively a no-op. However, a side-
* effect is that the internal file descriptor, maintained in
* the ELF descriptor, is set to -1. This setting will not
* be compared with any file descriptor that is passed to
* elf_begin(), should this archive, or one of the archive
* members, be processed again from the command line or
* because of a -z rescan.
*/
name);
return (0);
}
return (S_ERROR);
return (1);
case ELF_K_ELF:
/*
* Obtain the elf header so that we can determine what type of
* elf ELF_K_ELF file this is.
*/
/*
* This can fail for a number of reasons. Typically
* the object class is incorrect (ie. user is building
* 64-bit but managed to point at 32-bit libraries).
* Other ELF errors can include a truncated or corrupt
* file. Try to get the best error message possible.
*/
} else {
}
}
return (0);
}
/*
* Determine if we've already come across this file.
*/
if (!(flags & FLG_IF_EXTRACT)) {
else
/*
* Traverse the appropriate file list and determine if
*/
/*
* Ifl_desc generated via -Nneed, therefore no
* actual file behind it.
*/
continue;
continue;
/*
* Disregard (skip) this image.
*/
/*
* If the file was explicitly defined on the
* command line (this is always the case for
* relocatable objects, and is true for shared
* objects when they weren't specified via -l or
* were dragged in as an implicit dependency),
* then warn the user.
*/
if ((flags & FLG_IF_CMDLINE) ||
const char *errmsg;
/*
* Determine whether this is the same
* file name as originally encountered
* so as to provide the most
* descriptive diagnostic.
*/
errmsg =
}
if (ifl_ret)
return (1);
}
}
/*
* At this point, we know we need the file. Establish an input
* file descriptor and continue processing.
*/
/*
* If -zignore is in effect, mark this file as a potential
* candidate (the files use isn't actually determined until
* symbol resolution and relocation processing are completed).
*/
case ET_REL:
break;
case ET_DYN:
return (0);
}
/*
* Record any additional shared object information.
* If no soname is specified (eg. this file was
* derived from a explicit filename declaration on the
* command line, ie. bar.so) use the pathname.
* This entry may be overridden if the files dynamic
* section specifies an DT_SONAME value.
*/
else
/*
* If direct bindings, lazy loading, group permissions,
* or deferred dependencies need to be established, mark
* this object.
*/
/*
* Determine whether this dependency requires a syminfo.
*/
/*
* Guidance: Use -z lazyload/nolazyload.
* libc is exempt from this advice, because it cannot
* be lazy loaded, and requests to do so are ignored.
*/
}
/*
*/
}
break;
default:
(void) elf_errno();
}
return (0);
}
break;
default:
(void) elf_errno();
}
return (0);
}
return (error);
if (ifl_ret)
return (1);
}
/*
* Having successfully opened a file, set up the necessary elf structures to
* process it further. This small section of processing is slightly different
* from the elf initialization required to process a relocatable object from an
* archive (see libs.c: ld_process_archive()).
*/
{
return (0);
}
/*
* Determine whether the support library wishes to process this open.
* The support library may return:
* . a different ELF descriptor (in which case they should have
* closed the original)
* . a different file descriptor (in which case they should have
* closed the original)
* . a different path and file name (presumably associated with
* a different file descriptor)
*
* A file descriptor of -1, or and ELF descriptor of zero indicates
* the file should be ignored.
*/
return (0);
ifl_ret));
}
/*
* Having successfully mapped a file, set up the necessary elf structures to
* process it further. This routine is patterned after ld_process_open() and
* is only called by ld.so.1(1) to process a relocatable object.
*/
Ifl_desc *
{
return (0);
}
if (open_ret != 1)
return (ifl);
}
/*
* Process a required library (i.e. the dependency of a shared object).
* Combine the directory and filename, check the resultant path size, and try
* opening the pathname.
*/
static Ifl_desc *
{
int fd;
/*
* Determine the sizes of the directory and filename to insure we don't
* exceed our buffer.
*/
dlen = 1;
}
dlen++;
return (0);
}
/*
* Build the entire pathname and try and open the file.
*/
return (0);
else {
char *_path;
if (fd != -1)
if (open_ret != 1)
return (ifl);
}
}
/*
* Finish any library processing. Walk the list of so's that have been listed
* as "included" by shared objects we have previously processed. Examine them,
* without adding them as explicit dependents of this program, in order to
* complete our symbol definition process. The search path rules are:
*
* - use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
*
* - use any RPATH defined within the parent shared object, then
*
* - use the default directories, i.e. LIBPATH or -YP.
*/
{
/*
* Make sure we are back in dynamic mode.
*/
int fd;
/*
* See if this file has already been processed. At the time
* this implicit dependency was determined there may still have
* been more explicit dependencies to process. Note, if we ever
* do parse the command line three times we would be able to
* do all this checking when processing the dynamic section.
*/
continue;
break;
}
}
continue;
/*
* If the current path name element embeds a "/", then it's to
* be taken "as is", with no searching involved. Process all
* "/" occurrences, so that we can deduce the base file name.
*/
if (*path == '/')
}
if (slash) {
} else {
if (fd != -1)
return (S_ERROR);
} else
}
continue;
}
/*
* Now search for this file in any user defined directories.
*/
return (S_ERROR);
}
}
}
if (ifl) {
break;
}
}
continue;
/*
* Next use the local rules defined within the parent shared
* object.
*/
return (S_ERROR);
do {
&next);
return (S_ERROR);
}
}
if (ifl) {
break;
}
}
}
continue;
/*
* Finally try the default library search directories.
*/
return (S_ERROR);
}
}
}
if (ifl) {
break;
}
}
continue;
/*
* If we've got this far we haven't found the shared object.
* If an object was found, but was rejected for some reason,
* print a diagnostic to that effect, otherwise generate a
* generic "not found" diagnostic.
*/
} else {
}
}
/*
* Finally, now that all objects have been input, make sure any version
* requirements have been met.
*/
return (ld_vers_verify(ofl));
}