diff options
author | peter <peter@FreeBSD.org> | 2004-03-21 01:21:26 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2004-03-21 01:21:26 +0000 |
commit | ccd389b7a3813a60939dfe53407367fc91ef3df8 (patch) | |
tree | ded17068c1bf0dea014f27d5b6b5ccda995841f0 /libexec/rtld-elf | |
parent | 14202432d8f8324b424c7568b2a142567d110dfb (diff) | |
download | FreeBSD-src-ccd389b7a3813a60939dfe53407367fc91ef3df8.zip FreeBSD-src-ccd389b7a3813a60939dfe53407367fc91ef3df8.tar.gz |
Add initial support for compiling a special 32 bit version of
ld-elf.so.1 on 64 bit systems. Most of this involves using alternate
paths, environment variables and diagnostic messages.
The build glue is seperate.
Diffstat (limited to 'libexec/rtld-elf')
-rw-r--r-- | libexec/rtld-elf/Makefile | 2 | ||||
-rw-r--r-- | libexec/rtld-elf/debug.h | 11 | ||||
-rw-r--r-- | libexec/rtld-elf/libmap.c | 32 | ||||
-rw-r--r-- | libexec/rtld-elf/libmap.h | 3 | ||||
-rw-r--r-- | libexec/rtld-elf/rtld.c | 37 | ||||
-rw-r--r-- | libexec/rtld-elf/rtld.h | 12 |
6 files changed, 78 insertions, 19 deletions
diff --git a/libexec/rtld-elf/Makefile b/libexec/rtld-elf/Makefile index bcf0a25..6168374 100644 --- a/libexec/rtld-elf/Makefile +++ b/libexec/rtld-elf/Makefile @@ -1,6 +1,6 @@ # $FreeBSD$ -PROG= ld-elf.so.1 +PROG?= ld-elf.so.1 SRCS= rtld_start.S rtld.c rtld_lock.c map_object.c malloc.c \ xmalloc.c debug.c reloc.c libmap.c MAN= rtld.1 diff --git a/libexec/rtld-elf/debug.h b/libexec/rtld-elf/debug.h index 04314a9..3708df6 100644 --- a/libexec/rtld-elf/debug.h +++ b/libexec/rtld-elf/debug.h @@ -50,10 +50,17 @@ extern int debug; #define dbg(format, args...) ((void) 0) #endif +#ifndef COMPAT_32BIT +#define _MYNAME "ld-elf.so.1" +#else +#define _MYNAME "ld-elf32.so.1" +#endif + #define assert(cond) ((cond) ? (void) 0 : \ - (msg("ld-elf.so.1: assert failed: " __FILE__ ":" \ + (msg(_MYNAME ": assert failed: " __FILE__ ":" \ __XSTRING(__LINE__) "\n"), abort())) #define msg(s) write(STDOUT_FILENO, s, strlen(s)) -#define trace() msg("ld-elf.so.1: " __XSTRING(__LINE__) "\n") +#define trace() msg(_MYNAME ": " __XSTRING(__LINE__) "\n") + #endif /* DEBUG_H */ diff --git a/libexec/rtld-elf/libmap.c b/libexec/rtld-elf/libmap.c index 37a6d6b..e710fd5 100644 --- a/libexec/rtld-elf/libmap.c +++ b/libexec/rtld-elf/libmap.c @@ -17,6 +17,11 @@ #define _PATH_LIBMAP_CONF "/etc/libmap.conf" #endif +#ifdef COMPAT_32BIT +#undef _PATH_LIBMAP_CONF +#define _PATH_LIBMAP_CONF "/etc/libmap32.conf" +#endif + TAILQ_HEAD(lm_list, lm); struct lm { char *f; @@ -211,6 +216,27 @@ lm_find (const char *p, const char *f) return (NULL); } +#ifdef COMPAT_32BIT +char * +lm_findn (const char *p, const char *f, const int n) +{ + char pathbuf[64], *s, *t; + + if (n < sizeof(pathbuf) - 1) { + memcpy(pathbuf, f, n); + pathbuf[n] = '\0'; + s = pathbuf; + } else { + s = xmalloc(n + 1); + strcpy(s, f); + } + t = lm_find(p, s); + if (s != pathbuf) + free(s); + return (t); +} +#endif + static char * lml_find (struct lm_list *lmh, const char *f) { @@ -219,8 +245,7 @@ lml_find (struct lm_list *lmh, const char *f) dbg("%s(%p, \"%s\")", __func__, lmh, f); TAILQ_FOREACH(lm, lmh, lm_link) - if ((strncmp(f, lm->f, strlen(lm->f)) == 0) && - (strlen(f) == strlen(lm->f))) + if (strcmp(f, lm->f) == 0) return (lm->t); return NULL; } @@ -233,8 +258,7 @@ lmp_find (const char *n) dbg("%s(\"%s\")", __func__, n); TAILQ_FOREACH(lmp, &lmp_head, lmp_link) - if ((strncmp(n, lmp->p, strlen(lmp->p)) == 0) && - (strlen(n) == strlen(lmp->p))) + if (strcmp(n, lmp->p) == 0) return (&lmp->lml); return (NULL); } diff --git a/libexec/rtld-elf/libmap.h b/libexec/rtld-elf/libmap.h index f42df44..e4bd0ae 100644 --- a/libexec/rtld-elf/libmap.h +++ b/libexec/rtld-elf/libmap.h @@ -5,3 +5,6 @@ int lm_init (void); void lm_fini (void); char * lm_find (const char *, const char *); +#ifdef COMPAT_32BIT +char * lm_findn (const char *, const char *, const int); +#endif diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 7b1394b..e47deec 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -54,7 +54,11 @@ #include "rtld.h" #include "libmap.h" +#ifndef COMPAT_32BIT #define PATH_RTLD "/libexec/ld-elf.so.1" +#else +#define PATH_RTLD "/libexec/ld-elf32.so.1" +#endif /* Types. */ typedef void (*func_ptr_type)(); @@ -261,14 +265,14 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) trust = !issetugid(); - ld_bind_now = getenv("LD_BIND_NOW"); + ld_bind_now = getenv(LD_ "BIND_NOW"); if (trust) { - ld_debug = getenv("LD_DEBUG"); - libmap_disable = getenv("LD_LIBMAP_DISABLE") != NULL; - ld_library_path = getenv("LD_LIBRARY_PATH"); - ld_preload = getenv("LD_PRELOAD"); + ld_debug = getenv(LD_ "DEBUG"); + libmap_disable = getenv(LD_ "LIBMAP_DISABLE") != NULL; + ld_library_path = getenv(LD_ "LIBRARY_PATH"); + ld_preload = getenv(LD_ "PRELOAD"); } - ld_tracing = getenv("LD_TRACE_LOADED_OBJECTS"); + ld_tracing = getenv(LD_ "TRACE_LOADED_OBJECTS"); if (ld_debug != NULL && *ld_debug != '\0') debug = 1; @@ -360,7 +364,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) exit(0); } - if (getenv("LD_DUMP_REL_PRE") != NULL) { + if (getenv(LD_ "DUMP_REL_PRE") != NULL) { dump_relocations(obj_main); exit (0); } @@ -373,7 +377,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) if (do_copy_relocations(obj_main) == -1) die(); - if (getenv("LD_DUMP_REL_POST") != NULL) { + if (getenv(LD_ "DUMP_REL_POST") != NULL) { dump_relocations(obj_main); exit (0); } @@ -1460,6 +1464,9 @@ rtld_exit(void) static void * path_enumerate(const char *path, path_enum_proc callback, void *arg) { +#ifdef COMPAT_32BIT + const char *trans; +#endif if (path == NULL) return (NULL); @@ -1469,6 +1476,12 @@ path_enumerate(const char *path, path_enum_proc callback, void *arg) char *res; len = strcspn(path, ":;"); +#ifdef COMPAT_32BIT + trans = lm_findn(NULL, path, len); + if (trans) + res = callback(trans, strlen(trans), arg); + else +#endif res = callback(path, len, arg); if (res != NULL) @@ -2259,16 +2272,16 @@ trace_loaded_objects(Obj_Entry *obj) char *fmt1, *fmt2, *fmt, *main_local, *list_containers; int c; - if ((main_local = getenv("LD_TRACE_LOADED_OBJECTS_PROGNAME")) == NULL) + if ((main_local = getenv(LD_ "TRACE_LOADED_OBJECTS_PROGNAME")) == NULL) main_local = ""; - if ((fmt1 = getenv("LD_TRACE_LOADED_OBJECTS_FMT1")) == NULL) + if ((fmt1 = getenv(LD_ "TRACE_LOADED_OBJECTS_FMT1")) == NULL) fmt1 = "\t%o => %p (%x)\n"; - if ((fmt2 = getenv("LD_TRACE_LOADED_OBJECTS_FMT2")) == NULL) + if ((fmt2 = getenv(LD_ "TRACE_LOADED_OBJECTS_FMT2")) == NULL) fmt2 = "\t%o (%x)\n"; - list_containers = getenv("LD_TRACE_LOADED_OBJECTS_ALL"); + list_containers = getenv(LD_ "TRACE_LOADED_OBJECTS_ALL"); for (; obj; obj = obj->next) { Needed_Entry *needed; diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index 86df99d..0a8dfe1 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -39,9 +39,21 @@ #include "rtld_lock.h" #include "rtld_machdep.h" +#ifdef COMPAT_32BIT +#undef STANDARD_LIBRARY_PATH +#undef _PATH_ELF_HINTS +#define _PATH_ELF_HINTS "/var/run/ld-elf32.so.hints" +/* For running 32 bit binaries */ +#define STANDARD_LIBRARY_PATH "/lib32:/usr/lib32" +#define LD_ "LD_32_" +#endif + #ifndef STANDARD_LIBRARY_PATH #define STANDARD_LIBRARY_PATH "/lib:/usr/lib" #endif +#ifndef LD_ +#define LD_ "LD_" +#endif #define NEW(type) ((type *) xmalloc(sizeof(type))) #define CNEW(type) ((type *) xcalloc(sizeof(type))) |