_libld.h revision e64d0ff97a1fb57a6e93e6d31ea549511c90b318
/*
* 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.
*/
/*
* Local include file for ld library.
*/
#ifndef _LIBLD_DOT_H
#define _LIBLD_DOT_H
#include <libld.h>
#include <_libelf.h>
#include <debug.h>
#include <conv.h>
#include <msg.h>
#include <reloc_defs.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* In order to allow for cross linking, we need to be able to build
* libld with support for multiple targets within a single object.
* This is done using a global variable (ld_targ) of type Target to
* access target-specific code for the current target via indirection.
*/
/*
* Machine information for target
*/
typedef struct {
/* Used for EM_SPARC32PLUS */
/* a machplus object */
const char *m_def_interp; /* Def. interpreter for dyn objects */
/* Relocation type codes */
/* Relocation related constants */
/* GOT related constants */
/* PLT related constants */
/* Section type of .eh_frame/.eh_frame_hdr sections */
} Target_mach;
/*
* Section identifiers, used to order sections in output object
*/
typedef struct {
/*
* Target_nullfunc supplies machine code for generating a
*
* void (*)(void)
*
* unnamed function. Such a function can be called, and returns
* immediately without doing any work. This is used to back FUNC
* symbol definitions added with a mapfile.
*
* The machine instructions are specified as an array of bytes rather
* than a larger integer type in order to avoid byte order issues that
* can otherwise occur in cross linking.
*/
typedef struct {
/*
* Target_fill supplies machine code for fill bytes in executable output
* sections. Normally, libelf fills the gaps caused by alignment and size
* requirements of the constituent input sections with 0. Depending on the
* target architecture, it may be desirable to instead fill with executable
* NOP instructions. There are two reasons to do this:
*
* - So that .init/.fini sections will not contain unexecutable gaps
* that cause the executing program to trap and die.
*
* - To eliminate confusing garbage instructions between sections containing
* executable code when viewed with a dissassembler.
*
* The ff_execfill function is allowed to be NULL if the underlying target
* does not require a special fill for executable sections.
*/
typedef struct {
/*
* Target_machrel holds pointers to the reloc_table and machrel functions
* for a given target machine.
*
* The following function pointers are allowed to be NULL, if the
* underlying target does not require the specified operation. All
* other functions must be supplied:
*
* mr_assign_got
* mr_reloc_register
* mr_reloc_GOTOP
* mr_allocate_got
*/
typedef struct {
const Rel_entry *mr_reloc_table;
Ofl_desc *);
Rel_desc *);
/*
* Target_machsym holds pointers to the machsym functions
* for a given target machine.
*
* These fields are allowed to be NULL for targets that do not require
* special handling of register symbols. Register symbols are used by
* sparc targets. If any of these fields are non-NULL, all of them are
* required to be present (use empty stub routines if necessary).
*/
typedef struct {
typedef struct {
} Target;
/*
* Structure to manage the update of weak symbols from their associated alias.
*/
typedef struct wk_desc {
} Wk_desc;
/*
* Structure to manage the support library interfaces.
*/
typedef struct func_list {
const char *fl_obj; /* name of support object */
/* function is from */
void (*fl_fptr)(); /* function pointer */
} Func_list;
typedef struct support_list {
const char *sup_name; /* ld_support function name */
} Support_list;
/*
* Structure to manage a sorted output relocation list.
*
* rl_key1 -> pointer to needed ndx
* rl_key2 -> pointer to symbol relocation is against
* rl_key3 -> virtual offset of relocation
*/
typedef struct reloc_list {
} Reloc_list;
typedef struct sym_s_list {
} Sym_s_list;
/*
* ld heap management structure
*/
struct _ld_heap {
void *lh_free;
void *lh_end;
};
/*
* Dynamic per-symbol filtee string table descriptor. This associates filtee
* strings that will be created in the .dynstr, with .dynamic entries.
*/
typedef struct {
char *dft_str; /* dynstr string */
} Dfltr_desc;
/*
* Per-symbol filtee descriptor. This associates symbol definitions with
* their filtees.
*/
typedef struct {
} Sfltr_desc;
/*
* Define Alist initialization sizes.
*/
/*
* Return codes for {tls|got}_fixups() routines
*/
typedef enum {
FIX_ERROR, /* fatal error - time to punt */
FIX_DONE, /* relocation done - no further processing required */
FIX_RELOC /* do_reloc() relocation processing required */
} Fixupret;
#ifndef FILENAME_MAX
#endif
/*
* We pad the end of the .dynstr section with a block of DYNSTR_EXTRA_PAD
* bytes, and we insert DYNAMIC_EXTRA_ELTS unused items into the
* .dynamic section (with value DT_NULL). This provides the resources needed
*/
#define DYNSTR_EXTRA_PAD 512
#define DYNAMIC_EXTRA_ELTS 10
/*
* Relocation buckets are sized based on the number of input relocations and
* the following constants.
*/
/*
* Given a symbol of a type that is allowed within a .SUNW_dynsymsort or
* .SUNW_dyntlssort section, examine the symbol attributes to determine
* if this particular symbol should be included or not.
*
* entry:
* The symbol must have an allowed type: Either a type verified by
* dynsymsort_symtype[] or STT_TLS.
*
* _sdp - Pointer to symbol descriptor
* _sym - Pointer to symbol referenced by _sdp.
*
* _sym is derivable from _sdp: _sdp->sd_sym
* However, most callers assign it to a local variable for efficiency,
* and this macro allows such a variable to be used within. If you
* don't have such a variable, supply _sdp->sd_sym.
*
* The tests used require some explanation:
*
* (_sdp->sd_flags & FLG_SY_DYNSORT)
* Some special symbols are kept even if they don't meet the
* usual requirements. These symbols have the FLG_SY_DYNSORT
* bit set. If this bit isn't set then we look at the other
* attributes.
*
* (((_sdp->sd_ref != REF_DYN_NEED) &&
* (_sdp->sd_sym->st_shndx != SHN_UNDEF))
* || (_sdp->sd_flags & FLG_SY_MVTOCOMM))
* We do not want to include symbols that are not defined within
* the object we are creating. REF_DYN_NEED corresponds to those
* UNDEF items. However, if the symbol is the target of a copy
* relocation, then it effectively becomes defined within the
* object after all. FLG_SY_MVTOCOMM indicates a copy relocation,
* and prevents us from culling those exceptions.
*
* (_sym->st_size != 0)
* Symbols with 0 length are labels injected by the compilers
* or the linker for purposes of code generation, and do
* not directly correspond to actual code. In fact, most of the
* symbols we mark with FLG_SY_DYNSORT need that flag set because
* they have size 0. This size test filters out the others.
*
* !(_sdp->sd_flags & FLG_SY_NODYNSORT)
* Some symbols are not kept, even though they do meet the usual
* requirements. These symbols have FLG_SY_NODYNSORT set.
* For example, if there are weak and non-weak versions of a given
* symbol, we only want to keep one of them. So, we set
* FLG_SY_NODYNSORT on the one we don't want.
*/
/*
* We use output section descriptor counters to add up the number of
* symbol indexes to put in the .SUNW_dynsort and .SUNW_dyntlssort sections.
* Non-TLS symbols are counted by ofl->ofl_dynsymsortcnt, while TLS symbols are
* counted by ofl->ofl_dyntlssortcnt. This computation is done inline in
* several places. The DYNSORT_COUNT macro allows us to generate this from
* a single description.
*
* entry:
* _sdp, _sym - As per DYNSORT_TEST_ATTR
* _type - Type of symbol (STT_*)
* _inc_or_dec_op - Either ++, or --. This specifies the operation
* to be applied to the counter, and determines whether we
* are adding, or removing, a symbol from .SUNW_dynsymsort.
*
* Note that _type is derivable from _sym: ELF_ST_TYPE(_sdp->sd_sym->st_info).
* Most callers already have it in a variable, so this allows us to use that
* variable. If you don't have such a variable, use ELF_ST_TYPE() as shown.
*/
{ \
\
} else { /* Don't count this symbol */ \
} \
}
/*
* The OFL_SWAP_RELOC macros are used to determine whether
* relocation processing needs to swap the data being relocated.
* It is an optimization to ld_swap_reloc_data(), as it avoids
* the function call in the case where the linker host and the
* target have the same byte order.
*/
/*
* Define an AVL node for maintaining input section descriptors. AVL trees of
* these descriptors are used to process group and COMDAT section.
*
* Pure COMDAT uses the input section name as the search key, while
* SHT_GROUP sections use the name of a special signature symbol. We
* support both by using the isd_name field to carry the name. An alternative
* design would be to use a separate type for each use, saving the cost
* of the unneeded pointer for pure COMDAT. We favor a single implementation
* because we believe that SHT_GROUP comdat will be more common going forward,
* particularly in the largest objects produced by C++ where SHT_GROUP is
* needed to manage the complex section relationships. In contrast, we think
* that pure COMDAT is both more rare, and used in smaller objects where the
* cost of an extra pointer per node is relatively unimportant.
*/
typedef struct {
const char *isd_name; /* name used as search key */
} Isd_node;
/*
* Local data items.
*/
extern char *Plibpath;
extern char *Llibdir;
extern char *Ulibdir;
extern APlist *lib_support;
extern int demangle_flag;
extern int Verbose;
extern const int ldynsym_symtype[];
extern const int dynsymsort_symtype[];
/*
* Local functions.
*/
extern char *add_string(char *, char *);
extern const char *demangle(const char *);
extern void lds_atexit(Ofl_desc *, int);
extern void libld_free(void *);
extern void *libld_malloc(size_t);
extern void *libld_realloc(void *, size_t);
extern int isdavl_compare(const void *, const void *);
#if defined(_ELF64)
#define ld_add_actrel ld64_add_actrel
#define ld_add_libdir ld64_add_libdir
#define ld_add_rel_cache ld64_add_rel_cache
#define ld_adj_movereloc ld64_adj_movereloc
#define ld_am_I_partial ld64_am_I_partial
#define ld_ar_member ld64_ar_member
#define ld_ar_setup ld64_ar_setup
#define ld_assign_got_TLS ld64_assign_got_TLS
#define ld_bswap_Word ld64_bswap_Word
#define ld_bswap_Xword ld64_bswap_Xword
#define ld_disp_errmsg ld64_disp_errmsg
#define ld_ent_check ld64_ent_check
#define ld_find_library ld64_find_library
#define ld_finish_libs ld64_finish_libs
#define ld_get_group ld64_get_group
#define ld_group_process ld64_group_process
#define ld_lib_setup ld64_lib_setup
#define ld_make_bss ld64_make_bss
#define ld_make_data ld64_make_data
#define ld_make_got ld64_make_got
#define ld_make_sunwmove ld64_make_sunmove
#define ld_make_text ld64_make_text
#define ld_map_out ld64_map_out
#define ld_map_parse ld64_map_parse
#define ld_open_outfile ld64_open_outfile
#define ld_place_section ld64_place_section
#define ld_process_files ld64_process_files
#define ld_process_flags ld64_process_flags
#define ld_process_ifl ld64_process_ifl
#define ld_process_move ld64_process_move
#define ld_process_open ld64_process_open
#define ld_reloc_plt ld64_reloc_plt
#define ld_sec_validate ld64_sec_validate
#define ld_sort_ordered ld64_sort_ordered
#define ld_sort_seg_list ld64_sort_seg_list
#define ld_sunw_ldmach ld64_sunw_ldmach
#define ld_sup_atexit ld64_sup_atexit
#define ld_sup_open ld64_sup_open
#define ld_sup_file ld64_sup_file
#define ld_sup_loadso ld64_sup_loadso
#define ld_sup_input_done ld64_sup_input_done
#define ld_sup_section ld64_sup_section
#define ld_sup_start ld64_sup_start
#define ld_sym_add_u ld64_sym_add_u
#define ld_sym_adjust_vis ld64_sym_adjust_vis
#define ld_sym_avl_comp ld64_sym_avl_comp
#define ld_sym_copy ld64_sym_copy
#define ld_sym_enter ld64_sym_enter
#define ld_sym_find ld64_sym_find
#define ld_sym_nodirect ld64_sym_nodirect
#define ld_sym_process ld64_sym_process
#define ld_sym_resolve ld64_sym_resolve
#define ld_sym_spec ld64_sym_spec
#define ld_targ_init_x86 ld64_targ_init_x86
#define ld_vers_base ld64_vers_base
#define ld_vers_desc ld64_vers_desc
#define ld_vers_find ld64_vers_find
#define ld_vers_promote ld64_vers_promote
#define ld_vers_verify ld64_vers_verify
#define ld_wrap_enter ld64_wrap_enter
#else
#define ld_add_actrel ld32_add_actrel
#define ld_add_libdir ld32_add_libdir
#define ld_add_rel_cache ld32_add_rel_cache
#define ld_adj_movereloc ld32_adj_movereloc
#define ld_am_I_partial ld32_am_I_partial
#define ld_ar_member ld32_ar_member
#define ld_ar_setup ld32_ar_setup
#define ld_assign_got_TLS ld32_assign_got_TLS
#define ld_bswap_Word ld32_bswap_Word
#define ld_bswap_Xword ld32_bswap_Xword
#define ld_disp_errmsg ld32_disp_errmsg
#define ld_ent_check ld32_ent_check
#define ld_find_library ld32_find_library
#define ld_finish_libs ld32_finish_libs
#define ld_get_group ld32_get_group
#define ld_group_process ld32_group_process
#define ld_lib_setup ld32_lib_setup
#define ld_make_bss ld32_make_bss
#define ld_make_data ld32_make_data
#define ld_make_got ld32_make_got
#define ld_make_sunwmove ld32_make_sunmove
#define ld_make_text ld32_make_text
#define ld_map_out ld32_map_out
#define ld_map_parse ld32_map_parse
#define ld_open_outfile ld32_open_outfile
#define ld_place_section ld32_place_section
#define ld_process_files ld32_process_files
#define ld_process_flags ld32_process_flags
#define ld_process_ifl ld32_process_ifl
#define ld_process_move ld32_process_move
#define ld_process_open ld32_process_open
#define ld_reloc_plt ld32_reloc_plt
#define ld_sec_validate ld32_sec_validate
#define ld_sort_ordered ld32_sort_ordered
#define ld_sort_seg_list ld32_sort_seg_list
#define ld_sunw_ldmach ld32_sunw_ldmach
#define ld_sup_atexit ld32_sup_atexit
#define ld_sup_open ld32_sup_open
#define ld_sup_file ld32_sup_file
#define ld_sup_loadso ld32_sup_loadso
#define ld_sup_input_done ld32_sup_input_done
#define ld_sup_section ld32_sup_section
#define ld_sup_start ld32_sup_start
#define ld_sym_add_u ld32_sym_add_u
#define ld_sym_adjust_vis ld32_sym_adjust_vis
#define ld_sym_avl_comp ld32_sym_avl_comp
#define ld_sym_copy ld32_sym_copy
#define ld_sym_enter ld32_sym_enter
#define ld_sym_find ld32_sym_find
#define ld_sym_nodirect ld32_sym_nodirect
#define ld_sym_process ld32_sym_process
#define ld_sym_resolve ld32_sym_resolve
#define ld_sym_spec ld32_sym_spec
#define ld_targ_init_x86 ld32_targ_init_x86
#define ld_vers_base ld32_vers_base
#define ld_vers_desc ld32_vers_desc
#define ld_vers_find ld32_vers_find
#define ld_vers_promote ld32_vers_promote
#define ld_vers_verify ld32_vers_verify
#define ld_wrap_enter ld32_wrap_enter
#endif
extern void dbg_cleanup(void);
Ar_mem *);
extern void ld_ent_check(Ofl_desc *);
extern const char *ld_stt_section_sym_name(Is_desc *);
extern void ld_init_sighandler(Ofl_desc *);
extern void ld_map_out(Ofl_desc *);
const char *);
Ofl_desc *);
extern Ifl_desc *ld_process_open(const char *, const char *, int *,
Ofl_desc *);
extern void ld_sec_validate(Ofl_desc *);
extern Half ld_sunw_ldmach();
extern void ld_sup_atexit(Ofl_desc *, int);
extern void ld_sup_open(Ofl_desc *, const char **, const char **,
const Elf_Kind);
extern void ld_sup_input_done(Ofl_desc *);
extern int ld_sym_avl_comp(const void *, const void *);
Ofl_desc *);
extern const Target *ld_targ_init_sparc(void);
extern const Target *ld_targ_init_x86(void);
Ofl_desc *);
extern int ld_vers_verify(Ofl_desc *);
/*
* Most platforms have both a 32 and 64-bit variant (e.g. EM_SPARC and
* EM_SPARCV9). To support this, there many files in libld that are built
* twice, once for ELFCLASS64 (_ELF64), and once for ELFCLASS32. In these
* files, we sometimes want to supply one value for the ELFCLASS32 case
* and another for ELFCLASS64. The LD_TARG_BYCLASS macro is used to do
* this. It is called with both both alternatives, and yields the one
* that applies to the current compilation environment.
*/
#ifdef _ELF64
#else
#endif
#ifdef __cplusplus
}
#endif
#endif /* _LIBLD_DOT_H */