Index: build32.sh =========================================================================== *** /dev/null Fri Mar 19 17:50:29 2004 --- build32.sh Fri Mar 19 17:51:35 2004 *************** *** 0 **** --- 1,42 ---- + #! /bin/sh + # $P4: //depot/projects/hammer/build32.sh#4 $ + # + # This script is for running on a self-hosted amd64 machine, with an up-to-date + # world and toolchain etc. ie: the installed world is assumed to match the sources. + # It is rude, crude and brutal. But its the only option for now. + # + # Its purpose is to build a 32 bit library set and a ld-elf32.so.1. + + # XXX beware.. some of the library targets have no way to disable + # XXX installation of includes. ie: it will re-install some files in + # XXX /usr/include for you. + + # Set up an obj tree + chflags -R noschg /tmp/i386 + rm -rf /tmp/i386 + + # and a place to put the alternate include tree into. + mkdir -p /tmp/i386/root + make MAKEOBJDIRPREFIX=/tmp/i386 DESTDIR=/tmp/i386/root MACHINE_ARCH=i386 hierarchy + + # Now build includes + make MAKEOBJDIRPREFIX=/tmp/i386 DESTDIR=/tmp/i386/root MACHINE_ARCH=i386 obj + make MAKEOBJDIRPREFIX=/tmp/i386 DESTDIR=/tmp/i386/root MACHINE_ARCH=i386 includes + + # libncurses needs a build-tools pass first. I wish build-tools was a recursive target. + (cd lib/libncurses; make MAKEOBJDIRPREFIX=/tmp/i386 build-tools) + + # Now the libraries. This doesn't work for bind, gnuregex and stdc++ yet. hence -k + make -DNOMAN -DNODOC -DNOINFO MAKEOBJDIRPREFIX=/tmp/i386 LIBDIR=/usr/lib32 SHLIBDIR=/usr/lib32 MACHINE_ARCH=i386 CC="cc -m32 -I/tmp/i386/root/usr/include -L/usr/lib32 -B/usr/lib32" CXX="c++ -m32 -I/tmp/i386/root/usr/include/c++/3.3 -L/usr/lib32 -B/usr/lib32" LD="ld -m elf_i386_fbsd -Y P,/usr/lib32" -k libraries + + # bind isn't a problem, its an internal no-install lib, so let it fail. + # libstdc++ is a curious one. it looks like "c++ -m32" doesn't work. + # Hack to fix gnuregex which does evil hacks to the -I paths. + (cd gnu/lib/libregex; make -DNOMAN -DNODOC -DNOINFO MAKEOBJDIRPREFIX=/tmp/i386 LIBDIR=/usr/lib32 SHLIBDIR=/usr/lib32 MACHINE_ARCH=i386 CC="cc -m32 -I/tmp/i386/root/usr/include/gnu -I/tmp/i386/root/usr/include -L/usr/lib32 -B/usr/lib32" CXX="c++ -m32 -I/tmp/i386/root/usr/include/c++/3.3 -L/usr/lib32 -B/usr/lib32" LD="ld -m elf_i386_fbsd -Y P,/usr/lib32" all install) + + # and now that we have enough libraries, build ld-elf32.so.1 + cd libexec/rtld-elf + make -DNOMAN -DNODOC -DNOINFO PROG=ld-elf32.so.1 MAKEOBJDIRPREFIX=/tmp/i386 LIBDIR=/usr/lib32 SHLIBDIR=/usr/lib32 MACHINE_ARCH=i386 CC="cc -m32 -I/tmp/i386/root/usr/include -L/usr/lib32 -B/usr/lib32 -DCOMPAT_32BIT" LD="ld -m elf_i386_fbsd -Y P,/usr/lib32" obj + make -DNOMAN -DNODOC -DNOINFO PROG=ld-elf32.so.1 MAKEOBJDIRPREFIX=/tmp/i386 LIBDIR=/usr/lib32 SHLIBDIR=/usr/lib32 MACHINE_ARCH=i386 CC="cc -m32 -I/tmp/i386/root/usr/include -L/usr/lib32 -B/usr/lib32 -DCOMPAT_32BIT" LD="ld -m elf_i386_fbsd -Y P,/usr/lib32" depend + make -DNOMAN -DNODOC -DNOINFO PROG=ld-elf32.so.1 MAKEOBJDIRPREFIX=/tmp/i386 LIBDIR=/usr/lib32 SHLIBDIR=/usr/lib32 MACHINE_ARCH=i386 CC="cc -m32 -I/tmp/i386/root/usr/include -L/usr/lib32 -B/usr/lib32 -DCOMPAT_32BIT" LD="ld -m elf_i386_fbsd -Y P,/usr/lib32" + make -DNOMAN -DNODOC -DNOINFO PROG=ld-elf32.so.1 MAKEOBJDIRPREFIX=/tmp/i386 LIBDIR=/usr/lib32 SHLIBDIR=/usr/lib32 MACHINE_ARCH=i386 CC="cc -m32 -I/tmp/i386/root/usr/include -L/usr/lib32 -B/usr/lib32 -DCOMPAT_32BIT" LD="ld -m elf_i386_fbsd -Y P,/usr/lib32" install Index: etc/mtree/BSD.local.dist =========================================================================== --- etc/mtree/BSD.local.dist 2004/03/19 17:51:05 #29 +++ etc/mtree/BSD.local.dist 2004/03/19 17:51:05 @@ -19,6 +19,8 @@ .. lib .. + lib32 + .. libdata .. libexec Index: etc/mtree/BSD.root.dist =========================================================================== --- etc/mtree/BSD.root.dist 2004/03/19 17:51:05 #12 +++ etc/mtree/BSD.root.dist 2004/03/19 17:51:05 @@ -63,6 +63,8 @@ .. lib .. + lib32 + .. libexec .. mnt Index: etc/mtree/BSD.usr.dist =========================================================================== --- etc/mtree/BSD.usr.dist 2004/03/19 17:51:05 #56 +++ etc/mtree/BSD.usr.dist 2004/03/19 17:51:05 @@ -19,6 +19,8 @@ .. .. .. + lib32 + .. libdata doscmd fonts Index: etc/mtree/BSD.x11-4.dist =========================================================================== --- etc/mtree/BSD.x11-4.dist 2004/03/19 17:51:05 #6 +++ etc/mtree/BSD.x11-4.dist 2004/03/19 17:51:05 @@ -347,6 +347,8 @@ .. .. .. + lib32 + .. libdata pkgconfig .. Index: etc/mtree/BSD.x11.dist =========================================================================== --- etc/mtree/BSD.x11.dist 2004/03/19 17:51:05 #3 +++ etc/mtree/BSD.x11.dist 2004/03/19 17:51:05 @@ -191,6 +191,8 @@ modules .. .. + lib32 + .. libdata .. libexec Index: gnu/usr.bin/binutils/ld/Makefile.amd64 =========================================================================== --- gnu/usr.bin/binutils/ld/Makefile.amd64 2004/03/19 17:51:05 #5 +++ gnu/usr.bin/binutils/ld/Makefile.amd64 2004/03/19 17:51:05 @@ -20,7 +20,7 @@ "${NATIVE_EMULATION}" "" ${NATIVE_EMULATION} "${TARGET_TUPLE}" X86_EMULATION= elf_i386_fbsd -_i386_path= \"${TOOLS_PREFIX}/usr/lib/i386\" +_i386_path= \"${TOOLS_PREFIX}/lib32\":\"${TOOLS_PREFIX}/usr/lib32\" EMS+= ${X86_EMULATION} LDSCRIPTS+= ${X86_EMULATION}.x ${X86_EMULATION}.xbn ${X86_EMULATION}.xn ${X86_EMULATION}.xr \ ${X86_EMULATION}.xs ${X86_EMULATION}.xu ${X86_EMULATION}.xc ${X86_EMULATION}.xsc Index: libexec/rtld-elf/Makefile =========================================================================== --- libexec/rtld-elf/Makefile 2004/03/19 17:51:05 #10 +++ libexec/rtld-elf/Makefile 2004/03/19 17:51:05 @@ -1,6 +1,6 @@ # $FreeBSD: src/libexec/rtld-elf/Makefile,v 1.25 2003/09/13 21:50:35 mdodd Exp $ -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 Index: libexec/rtld-elf/debug.h =========================================================================== --- libexec/rtld-elf/debug.h 2004/03/19 17:51:05 #2 +++ libexec/rtld-elf/debug.h 2004/03/19 17:51:05 @@ -50,10 +50,17 @@ #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 */ Index: libexec/rtld-elf/libmap.c =========================================================================== --- libexec/rtld-elf/libmap.c 2004/03/19 17:51:05 #10 +++ libexec/rtld-elf/libmap.c 2004/03/19 17:51:05 @@ -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 @@ 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 @@ 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 @@ 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); } Index: libexec/rtld-elf/libmap.h =========================================================================== --- libexec/rtld-elf/libmap.h 2004/03/19 17:51:05 #2 +++ libexec/rtld-elf/libmap.h 2004/03/19 17:51:05 @@ -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 Index: libexec/rtld-elf/rtld.c =========================================================================== --- libexec/rtld-elf/rtld.c 2004/03/19 17:51:05 #39 +++ libexec/rtld-elf/rtld.c 2004/03/19 17:51:05 @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; Index: libexec/rtld-elf/rtld.h =========================================================================== --- libexec/rtld-elf/rtld.h 2004/03/19 17:51:05 #10 +++ libexec/rtld-elf/rtld.h 2004/03/19 17:51:05 @@ -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))) Index: sbin/ldconfig/ldconfig.c =========================================================================== --- sbin/ldconfig/ldconfig.c 2004/03/19 17:51:05 #5 +++ sbin/ldconfig/ldconfig.c 2004/03/19 17:51:05 @@ -63,6 +63,9 @@ #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 @@ { 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) { Index: sys/compat/ia32/ia32_sysvec.c =========================================================================== --- sys/compat/ia32/ia32_sysvec.c 2004/03/19 17:51:05 #11 +++ sys/compat/ia32/ia32_sysvec.c 2004/03/19 17:51:05 @@ -136,7 +136,7 @@ NULL, "/libexec/ld-elf.so.1", &ia32_freebsd_sysvec, - "/libexec/ld-elf-32.so.1", + "/libexec/ld-elf32.so.1", }; SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_ANY, @@ -150,7 +150,7 @@ NULL, "/usr/libexec/ld-elf.so.1", &ia32_freebsd_sysvec, - "/usr/libexec/ld-elf-32.so.1", + "/usr/libexec/ld-elf32.so.1", }; SYSINIT(oia32, SI_SUB_EXEC, SI_ORDER_ANY,