libld.h revision d579eb63ae5b8d8c65917b341e8c19a4df710606
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _LIBLD_H
#define _LIBLD_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <libelf.h>
#include <sgs.h>
#include <machdep.h>
#include <string_table.h>
#include <alist.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Default directory search path manipulation for the link-editor. YLDIR
* indicates which directory in LIBPATH is replaced by the -YL option to cc
* and ld. YUDIR indicates which directory is replaced by -YU.
*/
#define YLDIR 1
#define YUDIR 2
/*
* Define a hash value that can never be returned from elf_hash().
*/
#define SYM_NOHASH (~(Word)0)
/*
* Macro that can be used to represent both ORDER flags
* in a section header.
*/
/*
* The linker merges (concatenates) sections with the same name and
* compatible section header flags. When comparing these flags,
* there are some that should not be included in the decision.
* The ALL_SHF_IGNORE constant defines these flags.
*
* NOTE: SHF_MERGE|SHF_STRINGS:
* The compiler is allowed to set the SHF_MERGE|SHF_STRINGS flags in
* order to tell the linker that:
*
* 1) There is nothing in the section except null terminated strings.
* 2) If two compatible sections both have these flags set, it is
* OK to combine identical strings into single instances.
* In this case, the two sections would be modified to both
* reference a single string copy.
*
* This is a different meaning than the simple concatenating of sections
* that the linker always does. It is a hint that an additional optimization
* is possible, but not required. This means that sections that do not
* share the same SHF_MERGE|SHF_STRINGS values can be merged (concatenated),
* but cannot have their duplicate strings combined. Hence, the values
* of SHF_MERGE|SHF_STRINGS should be ignored when deciding whether two
* sections can be merged (concatenated).
*
* We do not currently implement the SHF_MERGE|SHF_STRINGS optimization,
* but it is possible to add it. If we did, the procedure would be to
* first combine the compatible sections that have these flag bits set,
* and then to concatenate any others to the result.
*/
/*
* Define symbol reference types for use in symbol resolution.
*/
typedef enum {
REF_DYN_SEEN, /* a .so symbol has been seen */
REF_DYN_NEED, /* a .so symbol satisfies a .o symbol */
REF_REL_NEED, /* a .o symbol */
REF_NUM /* the number of symbol references */
} Symref;
/*
* GOT reference models
*/
typedef enum {
GOT_REF_GENERIC, /* generic symbol reference */
GOT_REF_TLSIE, /* TLS initial exec (gnu) reference */
GOT_REF_TLSLD, /* TLS local dynamic reference */
GOT_REF_TLSGD /* TLS general dynamic reference */
} Gotref;
typedef struct {
} Gotndx;
/*
* Got debugging structure. The got index is defined as a signed value as we
* do so much mucking around with negative and positive gots on SPARC, and sign
* extension is necessary when building 64-bit objects. On intel we explicitly
* cast this variable to an unsigned value.
*/
typedef struct {
} Gottable;
/*
* Output file processing structure
*/
struct ofl_desc {
char *ofl_sgsid; /* link-editor identification */
const char *ofl_name; /* full file name */
int ofl_fd; /* file descriptor */
/* for syminfo processing */
/* targeting to expanded area */
/* a NULL sh_info */
#endif
void *ofl_entry; /* entry point (-e and Sym_desc *) */
char *ofl_filtees; /* shared objects we are a filter for */
const char *ofl_soname; /* (-h option) output file name for */
/* dynamic structure */
const char *ofl_interp; /* interpreter name used by exec() */
char *ofl_rpath; /* run path to store in .dynamic */
char *ofl_config; /* config path to store in .dynamic */
/* skip (-zignore) */
/* relocations */
/* partially expanded. */
/* Ref. at perform_outreloc() in */
/* libld/{mach}/machrel.c */
char *ofl_depaudit; /* dependency auditing required (-P) */
char *ofl_audit; /* object auditing required (-p) */
};
/* global symbols to locals */
/* effecting the symbol table */
/* output and relocations */
/*
* In the flags1 arena, establish any options that are applicable to archive
* extraction first, and associate a mask. These values are recorded with any
* archive descriptor so that they may be reset should the archive require a
* rescan to try and resolve undefined symbols.
*/
/* archive file */
/* resolve weak references */
/* unspecified global symbols */
/* GROUPPERM enabled */
/* of 32-bit libld */
/* section */
/* section */
/* the output file */
/* exported interfaces. */
/*
* Test to see if the output file would allow the presence of
* a .dynsym section.
*/
/*
* Test to see if the output file would allow the presence of
* a .SUNW_ldynsym section. The requirements are that a .dynsym
* is allowed, and -znoldynsym has not been specified. Note that
* even if the answer is True (1), we will only generate one if there
* are local symbols that require it.
*/
/*
* Relocation (active & output) processing structure - transparent to common
* code.
*/
struct rel_desc {
const char *rel_sname; /* symbol name (may be "unknown") */
};
/*
* common flags used on the Rel_desc structure (defined in machrel.h).
*/
/* only relevent to SPARC and */
/* R_SPARC_RELATIVE */
/* relevant to RELA relocations, */
/* not REL (i386) relocations */
/* adjustments required before */
/* actual relocation */
/* with a null sh_info field */
/* 1st part of FD */
/* 2nd part of FD */
/* static TLS GOT index */
/* dynamic TLS GOT index */
/* to static tls index */
/* which needs updating */
/* which needs updating */
/*
* Structure to hold a cache of Relocations.
*/
struct rel_cache {
};
/*
* Symbol value descriptor. For relocatable objects, each symbols value is
* its offset within its associated section. Therefore, to uniquely define
* each symbol within a reloctable object, record and sort the sh_offset and
* symbol value. This information is used to seach for displacement
* relocations as part of copy relocation validation.
*/
typedef struct {
} Ssv_desc;
/*
* Input file processing structures.
*/
struct ifl_desc { /* input file descriptor */
const char *ifl_name; /* full file name */
const char *ifl_soname; /* shared object name */
};
/* command line (no -l) */
/* object */
/* required */
/* symbol references */
/* flag */
/* cannot be directly bound to. */
/* lazy loaded */
/* DF_P1_GROUPPERM flag set */
/* in the ld time. */
/* at the run time */
/* is included in the output */
/* allocatable image */
struct is_desc { /* input section descriptor */
const char *is_name; /* the section name */
const char *is_basename; /* original section name (without */
/* .<sect>%<func> munging */
/* input section */
/* where to insert section when */
/* reordering sections */
/* sections. */
};
/* sh_info of a SHF_ORDERED section */
/*
* Map file and output file processing structures
*/
struct os_desc { /* Output section descriptor */
const char *os_name; /* the section name */
/* for this output section */
/* in current output section */
/* symbol for this section */
/* where to insert section when */
/* reordering sections */
};
/*
* For sorting sections.
*/
struct sort_desc {
};
struct sg_desc { /* output segment descriptor */
const char *sg_name; /* segment name */
/* segment is not specified */
/* for the segment */
};
/* this segment. */
/* i.e. ?[O] option in mapfile */
/* this segment */
/* no input sections will be */
/* associated to this section */
/* header */
struct sec_order {
const char *sco_secname; /* section name to be ordered */
};
struct ent_desc { /* input section entrance criteria */
/* sections */
const char *ec_name; /* name to match (NULL if none) */
/* meeting this criteria should */
/* inserted. Used for reordering */
/* of sections. */
};
/*
* Move supplementary structures
*/
typedef struct psym_info {
} Psym_info;
/*
* One structure is allocated for a move entry.
*/
typedef struct mv_itm {
} Mv_itm;
/*
* Define a move descripter used within relocation structures.
*/
struct mv_desc {
};
struct sym_desc {
/* used only for local partial */
/* pointer to parsym_info */
const char *sd_name; /* symbols name */
};
/*
* The auxiliary symbol descriptor contains the additional information (beyond
* the symbol descriptor) required to process global symbols. These symbols are
* accessed via an internal symbol hash table where locality of reference is
* important for performance.
*/
struct sym_aux {
const char *sa_vfile; /* first unavailable definition */
const char *sa_rfile; /* file with first symbol referenced */
/* ET_DYN file */
};
/*
* Nodes used to track symbols in the global AVL symbol dictionary.
*/
struct sym_avlnode {
const char *sav_name; /* symbol name */
};
/*
* These are the ids for processing of `Special symbols'. They are used
* to set the sym->sd_aux->sa_symspec field.
*/
/*
* Flags for sym_desc.sd_flags
*/
/* this is a result of a */
/* copy reloc against sym */
/* input file (read-only). */
/* either it's used as an entry */
/* point or for relocation, but */
/* it must be updated even if */
/* the -s flag is in effect */
/* application either because it */
/* originates from an implicitly */
/* referenced shared object, or */
/* because it is not part of a */
/* specified version. */
/* promoted to output file */
/* from mapfile */
/* due to a copy-relocs */
/* weak-strong pairing */
/* sparc only */
/* only used with direct bindings */
/* parent object */
/* section (COMDAT) */
/* expanded */
/* this symbol */
/* error suppression */
/* within a relocatable object) */
/* allocated */
/* command line. (ld -u <>, */
/* ld -zrtldinfo=<>, ...) */
/* ABS, COMMON, ... */
/*
* Sym_desc.sd_flags1
*/
/* The above mask indicates that */
/* a symbol has been explicitly */
/* scoped, and therefore is not */
/* a candidate for auto-reduction */
/*
* create a mask for (Sym.St_other & visibility) since the
* gABI does not yet define a ELF*_ST_OTHER macro.
*/
#define MSK_SYM_VISIBILITY 0x03
/*
* Structure to manage the shared object definition lists. There are two lists
* that use this structure:
*
* o ofl_soneed; maintain the list of implicitly required dependencies
* (ie. shared objects needed by other shared objects). These definitions
* may include RPATH's required to locate the dependencies, and any
* version requirements.
*
* o ofl_socntl; maintains the shared object control definitions. These are
* provided by the user (via a mapfile) and are used to indicate any
* SONAME translations and verion control requirements.
*/
struct sdf_desc {
const char *sdf_name; /* the shared objects file name */
const char *sdf_soname; /* the shared objects SONAME */
char *sdf_rpath; /* library search path DT_RPATH */
const char *sdf_rfile; /* referencing file for diagnostics */
/* from this object */
/* this object (via SPECVERS or */
/* ADDVERS) */
};
/* required */
/*
* Structure to manage shared object version usage requirements.
*/
struct sdv_desc {
const char *sdv_name; /* version name */
const char *sdv_ref; /* versions reference */
};
/*
* Structures to manage versioning information. Two versioning structures are
* defined:
*
* o a version descriptor maintains a linked list of versions and their
* associated dependencies. This is used to build the version definitions
* for an image being created (see map_symbol), and to determine the
* version dependency graph for any input files that are versioned.
*
* o a version index array contains each version of an input file that is
* being processed. It informs us which versions are available for
* binding, and is used to generate any version dependency information.
*/
struct ver_desc {
const char *vd_name; /* version name */
};
struct ver_index {
const char *vi_name; /* dependency version name */
};
/*
* Define any internal version descriptor flags ([vd|vi]_flags). Note that the
* first byte is reserved for user visible flags (refer VER_FLG's in link.h).
*/
/*
* isalist(1) descriptor - used to break an isalist string into its component
* options.
*/
struct isa_opt {
char *isa_name; /* individual isa option name */
};
struct isa_desc {
char *isa_list; /* sysinfo(SI_ISALIST) list */
};
/*
* uname(2) descriptor - used to break a utsname structure into its component
* options (at least those that we're interested in).
*/
struct uts_desc {
char *uts_osname; /* operating system name */
char *uts_osrel; /* operating system release */
};
/*
* SHT_GROUP descriptor - used to track group sections at the global
*/
struct group_desc {
const char *gd_gsectname; /* group section name */
const char *gd_symname; /* symbol name */
};
/*
* Indexes into the ld_support_funcs[] table.
*/
typedef enum {
LDS_VERSION = 0,
} Support_ndx;
/*
* Structure to manage archive member caching. Each archive has an archive
* descriptor (Ar_desc) associated with it. This contains pointers to the
* archive symbol table (obtained by elf_getarsyms(3e)) and an auxiliary
* structure (Ar_uax[]) that parallels this symbol table. The member element
* of this auxiliary table indicates whether the archive member associated with
* the symbol offset has already been extracted (AREXTRACTED) or partially
* processed (refer process_member()).
*/
typedef struct ar_mem {
char *am_name; /* members name */
char *am_path; /* path (ie. lib(foo.o)) */
char *am_strs; /* associated string table start */
} Ar_mem;
typedef struct ar_aux {
} Ar_aux;
typedef struct ar_desc {
const char *ad_name; /* archive file name */
} Ar_desc;
/*
* Define any archive descriptor flags. NOTE, make sure they do not clash with
* any output file descriptor archive extraction flags, as these are saved in
* the same entry (see MSK_OF1_ARCHIVE).
*/
/*
* Function Declarations.
*/
#if defined(_ELF64)
#define ld_create_outfile ld64_create_outfile
#define ld_ent_setup ld64_ent_setup
#define ld_init_strings ld64_init_strings
#define ld_make_sections ld64_make_sections
#define ld_ofl_cleanup ld64_ofl_cleanup
#define ld_process_open ld64_process_open
#define ld_reloc_init ld64_reloc_init
#define ld_reloc_process ld64_reloc_process
#define ld_sym_validate ld64_sym_validate
#define ld_update_outfile ld64_update_outfile
#else
#define ld_create_outfile ld32_create_outfile
#define ld_ent_setup ld32_ent_setup
#define ld_init_strings ld32_init_strings
#define ld_make_sections ld32_make_sections
#define ld_ofl_cleanup ld32_ofl_cleanup
#define ld_process_open ld32_process_open
#define ld_reloc_init ld32_reloc_init
#define ld_reloc_process ld32_reloc_process
#define ld_sym_validate ld32_sym_validate
#define ld_update_outfile ld32_update_outfile
#endif
extern int ld32_main(int, char **);
extern int ld64_main(int, char **);
extern void ld_ofl_cleanup(Ofl_desc *);
extern Ifl_desc *ld_process_open(const char *, const char *, int *,
#ifdef __cplusplus
}
#endif
#endif /* _LIBLD_H */