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.
This commit is contained in:
Peter Wemm 2004-03-21 01:21:26 +00:00
parent 3915888a54
commit c905e45dc0
7 changed files with 103 additions and 30 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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);
}

View File

@ -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

View File

@ -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;

View File

@ -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)))

View File

@ -63,6 +63,9 @@ static const char rcsid[] =
#define _PATH_ELF_HINTS "./ld-elf.so.hints"
#endif
#define _PATH_LD32_HINTS "/var/run/ld32.so.hints"
#define _PATH_ELF32_HINTS "/var/run/ld-elf32.so.hints"
#undef major
#undef minor
@ -102,20 +105,31 @@ char *argv[];
{
int i, c;
int rval = 0;
int is_aout;
int is_aout = 0;
int is_32 = 0;
is_aout = 0;
if (argc > 1 && strcmp(argv[1], "-aout") == 0) {
is_aout = 1;
argc--;
argv++;
} else if (argc > 1 && strcmp(argv[1], "-elf") == 0) {
/* skip over legacy -elf arg */
argc--;
argv++;
while (argc > 1) {
if (strcmp(argv[1], "-aout") == 0) {
is_aout = 1;
argc--;
argv++;
} else if (strcmp(argv[1], "-elf") == 0) {
is_aout = 0;
argc--;
argv++;
} else if (strcmp(argv[1], "-32") == 0) {
is_32 = 1;
argc--;
argv++;
} else {
break;
}
}
hints_file = is_aout ? _PATH_LD_HINTS : _PATH_ELF_HINTS;
if (is_32)
hints_file = is_aout ? _PATH_LD32_HINTS : _PATH_ELF32_HINTS;
else
hints_file = is_aout ? _PATH_LD_HINTS : _PATH_ELF_HINTS;
if (argc == 1)
rescan = 1;
else while((c = getopt(argc, argv, "Rf:imrsv")) != -1) {