From 167f70294e2e3bb299c60af678d56d0393e6288f Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Sat, 5 Feb 2005 22:54:49 +0000 Subject: [PATCH] - Add support for DT_FLAGS. - Define various things from the most recent ELF spec. rtld.c, 1.83 rtld.h, 1.28 map_object.c, 1.14 sys/elf_common.h, 1.12 --- libexec/rtld-elf/map_object.c | 3 +- libexec/rtld-elf/rtld.c | 21 +++++++++++-- libexec/rtld-elf/rtld.h | 4 ++- sys/sys/elf_common.h | 59 +++++++++++++++++++++++++++++++---- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c index ba55a9ce44..6726869d45 100644 --- a/libexec/rtld-elf/map_object.c +++ b/libexec/rtld-elf/map_object.c @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/libexec/rtld-elf/map_object.c,v 1.7.2.2 2002/12/28 19:49:41 dillon Exp $ - * $DragonFly: src/libexec/rtld-elf/map_object.c,v 1.4 2004/11/18 10:01:47 dillon Exp $ + * $DragonFly: src/libexec/rtld-elf/map_object.c,v 1.5 2005/02/05 22:54:49 joerg Exp $ */ #include @@ -299,6 +299,7 @@ obj_free(Obj_Entry *obj) { Objlist_Entry *elm; + free(obj->origin_path); free(obj->path); while (obj->needed != NULL) { Needed_Entry *needed = obj->needed; diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 461d1862bb..b97b7866f0 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/libexec/rtld-elf/rtld.c,v 1.43.2.15 2003/02/20 20:42:46 kan Exp $ - * $DragonFly: src/libexec/rtld-elf/rtld.c,v 1.12 2005/02/04 01:33:48 joerg Exp $ + * $DragonFly: src/libexec/rtld-elf/rtld.c,v 1.13 2005/02/05 22:54:49 joerg Exp $ */ /* @@ -677,6 +677,7 @@ digest_dynamic(Obj_Entry *obj) break; case DT_RPATH: + case DT_RUNPATH: /* XXX: process separately */ /* * We have to wait until later to process this, because we * might not have gotten the address of the string table yet. @@ -702,6 +703,22 @@ digest_dynamic(Obj_Entry *obj) ((Elf_Dyn*)dynp)->d_un.d_ptr = (Elf_Addr) &r_debug; break; + case DT_FLAGS: + if (dynp->d_un.d_val & DF_ORIGIN) { + obj->origin_path = xmalloc(PATH_MAX); + if (rtld_dirname(obj->path, obj->origin_path) == -1) + die(); + } + if (dynp->d_un.d_val & DF_SYMBOLIC) + obj->symbolic = true; + if (dynp->d_un.d_val & DF_TEXTREL) + obj->textrel = true; + if (dynp->d_un.d_val & DF_BIND_NOW) + obj->bind_now = true; + if (dynp->d_un.d_val & DF_STATIC_TLS) + ; + break; + default: dbg("Ignoring d_tag %d = %#x", dynp->d_tag, dynp->d_tag); break; @@ -1474,7 +1491,7 @@ relocate_objects(Obj_Entry *first, bool bind_now) if (reloc_plt(obj) == -1) return -1; /* Relocate the jump slots if we are doing immediate binding. */ - if (bind_now) + if (obj->bind_now || bind_now) if (reloc_jmpslots(obj) == -1) return -1; diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index 4a3749dc9d..65cbd095ba 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/libexec/rtld-elf/rtld.h,v 1.15.2.6 2003/02/20 20:42:46 kan Exp $ - * $DragonFly: src/libexec/rtld-elf/rtld.h,v 1.5 2005/02/03 23:28:24 joerg Exp $ + * $DragonFly: src/libexec/rtld-elf/rtld.h,v 1.6 2005/02/05 22:54:49 joerg Exp $ */ #ifndef RTLD_H /* { */ @@ -109,6 +109,7 @@ typedef struct Struct_Obj_Entry { struct Struct_Obj_Entry *next; char *path; /* Pathname of underlying file (%) */ + char *origin_path; /* Directory path of origin file */ int refcount; int dl_refcount; /* Number of times loaded by dlopen */ @@ -153,6 +154,7 @@ typedef struct Struct_Obj_Entry { bool rtld; /* True if this is the dynamic linker */ bool textrel; /* True if there are relocations to text seg */ bool symbolic; /* True if generated with "-Bsymbolic" */ + bool bind_now; /* True if all relocations should be made first */ bool traced; /* Already printed in ldd trace output */ bool jmpslots_done; /* Already have relocated the jump slots */ bool init_done; /* Already have added object to init list */ diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h index c14d7e7bc1..a6c4192f77 100644 --- a/sys/sys/elf_common.h +++ b/sys/sys/elf_common.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/sys/elf_common.h,v 1.5.2.3 2001/02/28 02:30:46 obrien Exp $ - * $DragonFly: src/sys/sys/elf_common.h,v 1.2 2003/06/17 04:28:58 dillon Exp $ + * $DragonFly: src/sys/sys/elf_common.h,v 1.3 2005/02/05 22:54:49 joerg Exp $ */ #ifndef _SYS_ELF_COMMON_H_ @@ -161,6 +161,9 @@ typedef struct { #define SHT_REL 9 /* relation section without addends */ #define SHT_SHLIB 10 /* reserved - purpose unknown */ #define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_NUM 12 /* number of section types */ +#define SHT_LOOS 0x60000000 /* First of OS specific semantics */ +#define SHT_HIOS 0x6fffffff /* Last of OS specific semantics */ #define SHT_LOPROC 0x70000000 /* reserved range for processor */ #define SHT_HIPROC 0x7fffffff /* specific section header types */ #define SHT_LOUSER 0x80000000 /* reserved range for application */ @@ -180,9 +183,12 @@ typedef struct { #define PT_NOTE 4 /* Auxiliary information. */ #define PT_SHLIB 5 /* Reserved (not used). */ #define PT_PHDR 6 /* Location of program header itself. */ +#define PT_TLS 7 /* Thread local storage segment */ -#define PT_COUNT 7 /* Number of defined p_type values. */ +#define PT_COUNT 8 /* Number of defined p_type values. */ +#define PT_LOOS 0x60000000 /* OS-specific */ +#define PT_HIOS 0x6fffffff /* OS-specific */ #define PT_LOPROC 0x70000000 /* First processor-specific type. */ #define PT_HIPROC 0x7fffffff /* Last processor-specific type. */ @@ -209,18 +215,59 @@ typedef struct { #define DT_FINI 13 /* Address of finalization function. */ #define DT_SONAME 14 /* String table offset of shared object name. */ -#define DT_RPATH 15 /* String table offset of library path. */ -#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. */ +#define DT_RPATH 15 /* String table offset of library path. [sup] */ +#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. [sup] */ #define DT_REL 17 /* Address of ElfNN_Rel relocations. */ #define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */ #define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */ #define DT_PLTREL 20 /* Type of relocation used for PLT. */ #define DT_DEBUG 21 /* Reserved (not used). */ #define DT_TEXTREL 22 /* Indicates there may be relocations in - non-writable segments. */ + non-writable segments. [sup] */ #define DT_JMPREL 23 /* Address of PLT relocations. */ +#define DT_BIND_NOW 24 /* [sup] */ +#define DT_INIT_ARRAY 25 /* Address of the array of pointers to + initialization functions */ +#define DT_FINI_ARRAY 26 /* Address of the array of pointers to + termination functions */ +#define DT_INIT_ARRAYSZ 27 /* Size in bytes of the array of + initialization functions. */ +#define DT_FINI_ARRAYSZ 28 /* Size in bytes of the array of + terminationfunctions. */ +#define DT_RUNPATH 29 /* String table offset of a null-terminated + library search path string. */ +#define DT_FLAGS 30 /* Object specific flag values. +#define DT_ENCODING 32 /* Values greater than or equal to DT_ENCODING + and less than DT_LOOS follow the rules for + the interpretation of the d_un union + as follows: even == 'd_ptr', even == 'd_val' + or none */ +#define DT_PREINIT_ARRAY 32 /* Address of the array of pointers to + pre-initialization functions. */ +#define DT_PREINIT_ARRAYSZ 33 /* Size in bytes of the array of + pre-initialization functions. */ + +#define DT_COUNT 33 /* Number of defined d_tag values. */ -#define DT_COUNT 24 /* Number of defined d_tag values. */ +#define DT_LOOS 0x6000000d /* First OS-specific */ +#define DT_HIOS 0x6fff0000 /* Last OS-specific */ +#define DT_LOPROC 0x70000000 /* First processor-specific type. */ +#define DT_HIPROC 0x7fffffff /* Last processor-specific type. */ + +/* Values for DT_FLAGS */ +#define DF_ORIGIN 0x0001 /* Indicates that the object being loaded may + make reference to the $ORIGIN substitution + string */ +#define DF_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */ +#define DF_TEXTREL 0x0004 /* Indicates there may be relocations in + non-writable segments. */ +#define DF_BIND_NOW 0x0008 /* Indicates that the dynamic linker should + process all relocations for the object + containing this entry before transferring + control to the program. */ +#define DF_STATIC_TLS 0x0010 /* Indicates that the shared object or + executable contains code using a static + thread-local storage scheme. */ /* Values for n_type. Used in core files. */ #define NT_PRSTATUS 1 /* Process status. */ -- 2.41.0