diff options
| -rw-r--r-- | ChangeLog | 49 | ||||
| -rw-r--r-- | Makerules | 64 | ||||
| -rw-r--r-- | config.h.in | 3 | ||||
| -rw-r--r-- | csu/Makefile | 13 | ||||
| -rw-r--r-- | csu/abi-note.S | 6 | ||||
| -rw-r--r-- | elf/Makefile | 2 | ||||
| -rw-r--r-- | elf/cache.c | 62 | ||||
| -rw-r--r-- | elf/dl-load.c | 75 | ||||
| -rw-r--r-- | elf/dl-minimal.c | 4 | ||||
| -rw-r--r-- | elf/ldconfig.c | 35 | ||||
| -rw-r--r-- | elf/readlib.c | 25 | ||||
| -rw-r--r-- | posix/fnmatch_loop.c | 2 | ||||
| -rw-r--r-- | sysdeps/generic/dl-cache.c | 2 | ||||
| -rw-r--r-- | sysdeps/generic/dl-cache.h | 2 | ||||
| -rw-r--r-- | sysdeps/generic/ldconfig.h | 10 | ||||
| -rw-r--r-- | sysdeps/generic/ldsodefs.h | 3 | ||||
| -rw-r--r-- | sysdeps/generic/readelflib.c | 22 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/configure | 5 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/configure.in | 2 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/dl-librecon.h | 49 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/dl-osinfo.h | 2 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/i386/dl-librecon.h | 23 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/i386/readelflib.c | 19 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/ia64/readelflib.c | 19 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/init-first.c | 1 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/sparc/readelflib.c | 21 |
26 files changed, 412 insertions, 108 deletions
@@ -1,3 +1,52 @@ +2001-03-12 Jakub Jelinek <jakub@redhat.com> + + * csu/Makefile (abi-tag.h): Define OS and version separately, allow + version to be overriden from config.h. + * csu/abi-note.S: Use OS and version separately, include config.h. + * elf/dl-load.c (_dl_osversion): New. + (_dl_map_object_from_fd): Kill some warnings. + (open_verify): Check .note.ABI-tag of the library if present. + * elf/Makefile (CPPFLAGS-dl-load.c): Add -I$(csu-objpfx). + * elf/cache.c (struct cache_entry): Add osversion. + (print_entry): Print osversion. + (print_cache): Pass osversion to it. + (compare): Sort according to osversion. + (save_cache): Set osversion. + (add_to_cache): Add osversion argument. + * sysdeps/generic/ldconfig.h (add_to_cache, process_file, + process_elf_file): Add osversion argument. + * elf/readlib.c (process_file): Likewise. + * sysdeps/generic/readelflib.c (process_elf_file): Likewise. + * sysdeps/unix/sysv/linux/ia64/readelflib.c (process_elf_file, + process_elf32_file, process_elf64_file): Likewise. + * sysdeps/unix/sysv/linux/i386/readelflib.c (process_elf_file, + process_elf32_file, process_elf64_file): Likewise. + * sysdeps/unix/sysv/linux/sparc/readelflib.c (process_elf_file, + process_elf32_file, process_elf64_file): Likewise. + * elf/ldconfig.c (manual_link): Pass it. + (search_dir): Issue diagnostic if two libs with the same soname in + the same directory have different .note.ABI-tag. Record osversion in + dlib_entry and use it from there. + (struct lib_entry): Remove. + (struct dlib_entry): Add osversion. + * sysdeps/generic/dl-cache.c (_dl_load_cache_lookup): Check + osversion. + * sysdeps/generic/dl-cache.h (struct file_entry_new): Replace __unused + field with osversion. + * sysdeps/generic/ldsodefs.h (_dl_osversion): Declare. + * sysdeps/unix/sysv/linux/init-first.c: Include ldsodefs.h. + * sysdeps/unix/sysv/linux/dl-osinfo.h (DL_SYSDEP_OSCHECK): Save kernel + version in _dl_osversion. + * sysdeps/unix/sysv/linux/configure.in: Define __ABI_TAG_VERSION. + * Makerules (build-shlib-helper, build-module-helper): New. + (build-shlib, build-module-helper): Make sure .note.ABI-tag comes + early. + * config.h.in (__ABI_TAG_VERSION): Add. + * elf/dl-minimal.c (__strtoul_internal): Set endptr on return. + * sysdeps/unix/sysv/linux/i386/dl-librecon.h (EXTRA_LD_ENVVARS): + Handle LD_ASSUME_KERNEL. + * sysdeps/unix/sysv/linux/dl-librecon.h: New. + 2001-03-15 Ulrich Drepper <drepper@redhat.com> * timezone/antarctica: Update from tzdata2001a. @@ -413,29 +413,75 @@ endif lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp) $(build-shlib) -define build-shlib -$(LINK.o) -shared -Wl,-O1 -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \ +define build-shlib-helper +$(LINK.o) -shared -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \ $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \ $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \ -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \ $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \ - -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \ - -Wl,--whole-archive \ + -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) +endef + +ifeq (yes,$(elf)) +# binutils only position loadable notes into the first page for binaries, +# not for shared objects +define build-shlib +$(build-shlib-helper) \ + -o $@.new $(csu-objpfx)/abi-note.o -Wl,--verbose \ + $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \ + sed -e '/^=========/,/^=========/!d;/^=========/d' \ + -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \ + > $@.lds; \ + rm -f $@.new; \ + $(build-shlib-helper) -o $@ -T $@.lds \ + -Wl,--whole-archive $(csu-objpfx)/abi-note.o \ + $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \ + $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so); \ + rm -f $@.lds +endef +else +define build-shlib +$(build-shlib-helper) \ + -o $@ -Wl,--whole-archive \ $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \ $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so) endef +endif + +define build-module-helper +$(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) \ + -B$(csu-objpfx) $(load-map-file) \ + $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \ + -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) +endef # This macro is similar to build-shlib but it does not define a soname # and it does not depend on the destination name to start with `lib'. +ifeq (yes,$(elf)) +# binutils only position loadable notes into the first page for binaries, +# not for shared objects define build-module -$(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \ - -B$(csu-objpfx) $(load-map-file) \ - $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \ - -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \ - -Wl,--whole-archive \ +$(build-module-helper) \ + -o $@.new $(csu-objpfx)/abi-note.o -Wl,--verbose \ + $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \ + sed -e '/^=========/,/^=========/!d;/^=========/d' \ + -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \ + > $@.lds; \ + rm -f $@.new; \ + $(build-module-helper) -o $@ -T $@.lds \ + -Wl,--whole-archive $(csu-objpfx)/abi-note.o \ + $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \ + $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so); \ + rm -f $@.lds +endef +else +define build-module +$(build-module-helper) \ + -o $@ -Wl,--whole-archive \ $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \ $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so) endef +endif # Don't try to use -lc when making libc.so itself. # Also omits crti.o and crtn.o, which we do not want diff --git a/config.h.in b/config.h.in index b6223d73d4..14e15505dd 100644 --- a/config.h.in +++ b/config.h.in @@ -93,6 +93,9 @@ /* Linux specific: minimum supported kernel version. */ #undef __LINUX_KERNEL_VERSION +/* Override abi-tags ABI version if necessary. */ +#undef __ABI_TAG_VERSION + /* An extension in gcc 2.96 and up allows the subtraction of two local labels. */ #undef HAVE_SUBTRACT_LOCAL_LABELS diff --git a/csu/Makefile b/csu/Makefile index ad59404c4a..838e14163f 100644 --- a/csu/Makefile +++ b/csu/Makefile @@ -168,12 +168,17 @@ $(objpfx)abi-tag.h: $(..)abi-tags $(make-target-directory) rm -f $@.new sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \ - while read conf tag; do \ + while read conf tagos tagver; do \ test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \ : "$$conf"` != 0 || continue; \ - echo "$$tag" | \ - sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \ - -e 's/ /,/g' -e 's/^ */#define ABI_TAG /' > $@.new; \ + ( echo "$$tagos" | \ + sed -e 's/[^0-9xXa-fA-F ]//' \ + -e 's/^/#define __ABI_TAG_OS /'; \ + echo "#ifndef __ABI_TAG_VERSION"; \ + echo "$$tagver" | \ + sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \ + -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \ + echo "#endif" ) > $@.new; \ done if test -r $@.new; then mv -f $@.new $@; \ else echo >&2 'This configuration not matched in $<'; exit 1; fi diff --git a/csu/abi-note.S b/csu/abi-note.S index 6050883d34..3ad3a470f8 100644 --- a/csu/abi-note.S +++ b/csu/abi-note.S @@ -1,5 +1,5 @@ /* Special .init and .fini section support. - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it @@ -54,6 +54,7 @@ offset length contents identify the earliest release of that OS that supports this ABI. See abi-tags (top level) for details. */ +#include <config.h> #include <abi-tag.h> /* OS-specific ABI tag value */ /* The linker (GNU ld 2.8 and later) recognizes an allocated section whose @@ -67,5 +68,6 @@ offset length contents .long 1 /* note type */ 0: .asciz "GNU" /* vendor name */ 1: .align 4 -2: .long ABI_TAG /* note data: the ABI tag */ +2: .long __ABI_TAG_OS /* note data: the ABI tag */ + .long __ABI_TAG_VERSION 3: .align 4 /* pad out section */ diff --git a/elf/Makefile b/elf/Makefile index a4f0a1063e..dff36c9371 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -188,7 +188,7 @@ $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T}; $(move-if-change) ${@:st=T} ${@:st=h} touch $@ -CPPFLAGS-dl-load.c = -I$(objpfx). +CPPFLAGS-dl-load.c = -I$(objpfx). -I$(csu-objpfx). ifeq (yes,$(build-shared)) $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force) diff --git a/elf/cache.c b/elf/cache.c index 378ce8f69c..19237bbe79 100644 --- a/elf/cache.c +++ b/elf/cache.c @@ -39,6 +39,7 @@ struct cache_entry char *lib; /* Library name. */ char *path; /* Path to find library. */ int flags; /* Flags to indicate kind of library. */ + unsigned int osversion; /* Required OS version. */ uint64_t hwcap; /* Important hardware capabilities. */ int bits_hwcap; /* Number of bits set in hwcap. */ struct cache_entry *next; /* Next entry in list. */ @@ -52,7 +53,8 @@ static const char *flag_descr[] = /* Print a single entry. */ static void -print_entry (const char *lib, int flag, uint64_t hwcap, const char *key) +print_entry (const char *lib, int flag, unsigned int osversion, + uint64_t hwcap, const char *key) { printf ("\t%s (", lib); switch (flag & FLAG_TYPE_MASK) @@ -61,7 +63,7 @@ print_entry (const char *lib, int flag, uint64_t hwcap, const char *key) case FLAG_ELF: case FLAG_ELF_LIBC5: case FLAG_ELF_LIBC6: - fputs (flag_descr [flag & FLAG_TYPE_MASK], stdout); + fputs (flag_descr[flag & FLAG_TYPE_MASK], stdout); break; default: fputs ("unknown", stdout); @@ -85,6 +87,23 @@ print_entry (const char *lib, int flag, uint64_t hwcap, const char *key) } if (hwcap != 0) printf (", hwcap: 0x%" PRIx64, hwcap); + if (osversion != 0) + { + static const char *const abi_tag_os[] = + { + [0] = "Linux", + [1] = "Hurd", + [2] = "Solaris", + [3] = "Unknown OS" + }; + unsigned int os = osversion >> 24; + + printf (", OS ABI: %s %d.%d.%d", + abi_tag_os[os > 3 ? 3 : os], + (osversion >> 16) & 0xff, + (osversion >> 8) & 0xff, + osversion & 0xff); + } printf (") => %s\n", key); } @@ -139,7 +158,8 @@ print_cache (const char *cache_name) else { size_t offset = ALIGN_CACHE (sizeof (struct cache_file) - + cache->nlibs * sizeof (struct file_entry)); + + (cache->nlibs + * sizeof (struct file_entry))); /* This is where the strings start. */ cache_data = (const char *) &cache->libs[cache->nlibs]; @@ -150,9 +170,10 @@ print_cache (const char *cache_name) cache_new = (struct cache_file_new *) ((void *)cache + offset); - if (!memcmp (cache_new->magic, CACHEMAGIC_NEW, sizeof CACHEMAGIC_NEW - 1) - && !memcmp (cache_new->version, CACHE_VERSION, - sizeof CACHE_VERSION - 1)) + if (memcmp (cache_new->magic, CACHEMAGIC_NEW, + sizeof CACHEMAGIC_NEW - 1) == 0 + && memcmp (cache_new->version, CACHE_VERSION, + sizeof CACHE_VERSION - 1) == 0) { cache_data = (const char *) cache_new; format = 1; @@ -167,17 +188,19 @@ print_cache (const char *cache_name) /* Print everything. */ for (i = 0; i < cache->nlibs; i++) print_entry (cache_data + cache->libs[i].key, - cache->libs[i].flags, 0, + cache->libs[i].flags, 0, 0, cache_data + cache->libs[i].value); } else if (format == 1) { - printf (_("%d libs found in cache `%s'\n"), cache_new->nlibs, cache_name); + printf (_("%d libs found in cache `%s'\n"), + cache_new->nlibs, cache_name); /* Print everything. */ for (i = 0; i < cache_new->nlibs; i++) print_entry (cache_data + cache_new->libs[i].key, cache_new->libs[i].flags, + cache_new->libs[i].osversion, cache_new->libs[i].hwcap, cache_data + cache_new->libs[i].value); } @@ -217,6 +240,10 @@ int compare (const struct cache_entry *e1, const struct cache_entry *e2) return 1; else if (e2->hwcap < e1->hwcap) return -1; + if (e2->osversion > e1->osversion) + return 1; + if (e2->osversion < e1->osversion) + return -1; } return res; } @@ -280,12 +307,15 @@ save_cache (const char *cache_name) /* And the list of all entries in the new format. */ file_entries_new_size = sizeof (struct cache_file_new) + cache_entry_count * sizeof (struct file_entry_new); - file_entries_new = (struct cache_file_new *) xmalloc (file_entries_new_size); + file_entries_new = + (struct cache_file_new *) xmalloc (file_entries_new_size); /* Fill in the header. */ memset (file_entries_new, 0, sizeof (struct cache_file_new)); - memcpy (file_entries_new->magic, CACHEMAGIC_NEW, sizeof CACHEMAGIC_NEW - 1); - memcpy (file_entries_new->version, CACHE_VERSION, sizeof CACHE_VERSION - 1); + memcpy (file_entries_new->magic, CACHEMAGIC_NEW, + sizeof CACHEMAGIC_NEW - 1); + memcpy (file_entries_new->version, CACHE_VERSION, + sizeof CACHE_VERSION - 1); file_entries_new->nlibs = cache_entry_count; file_entries_new->len_strings = total_strlen; @@ -319,9 +349,9 @@ save_cache (const char *cache_name) always begins at the beginning of the the new cache struct. */ file_entries_new->libs[idx_new].flags = entry->flags; + file_entries_new->libs[idx_new].osversion = entry->osversion; file_entries_new->libs[idx_new].hwcap = entry->hwcap; file_entries_new->libs[idx_new].key = str_offset; - file_entries_new->libs[idx_new].__unused = 0; } len = strlen (entry->lib); str = stpcpy (str, entry->lib); @@ -363,7 +393,8 @@ save_cache (const char *cache_name) /* Write contents. */ if (opt_format != 2) { - if (write (fd, file_entries, file_entries_size) != (ssize_t)file_entries_size) + if (write (fd, file_entries, file_entries_size) + != (ssize_t)file_entries_size) error (EXIT_FAILURE, errno, _("Writing of cache data failed")); } if (opt_format != 0) @@ -371,7 +402,7 @@ save_cache (const char *cache_name) /* Align cache. */ if (opt_format != 2) { - char zero [pad]; + char zero[pad]; if (write (fd, zero, pad) != (ssize_t)pad) error (EXIT_FAILURE, errno, _("Writing of cache data failed")); } @@ -414,7 +445,7 @@ save_cache (const char *cache_name) /* Add one library to the cache. */ void add_to_cache (const char *path, const char *lib, int flags, - uint64_t hwcap) + unsigned int osversion, uint64_t hwcap) { struct cache_entry *new_entry, *ptr, *prev; char *full_path; @@ -430,6 +461,7 @@ add_to_cache (const char *path, const char *lib, int flags, new_entry->lib = xstrdup (lib); new_entry->path = full_path; new_entry->flags = flags; + new_entry->osversion = osversion; new_entry->hwcap = hwcap; new_entry->bits_hwcap = 0; diff --git a/elf/dl-load.c b/elf/dl-load.c index 6e4c972b00..0a5603f092 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -30,6 +30,8 @@ #include <sys/stat.h> #include <sys/types.h> #include "dynamic-link.h" +#include <abi-tag.h> +#include <dl-osinfo.h> #include <dl-dst.h> @@ -111,6 +113,8 @@ struct filebuf size_t _dl_pagesize; +unsigned int _dl_osversion; + int _dl_clktck; extern const char *_dl_platform; @@ -1061,12 +1065,12 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp, if (__builtin_expect (_dl_debug_mask & DL_DEBUG_FILES, 0)) _dl_debug_printf (" dynamic: 0x%0*lx base: 0x%0*lx size: 0x%0*Zx\n" " entry: 0x%0*lx phdr: 0x%0*lx phnum: %*u\n\n", - sizeof (void *) * 2, (unsigned long int) l->l_ld, - sizeof (void *) * 2, (unsigned long int) l->l_addr, - sizeof (void *) * 2, maplength, - sizeof (void *) * 2, (unsigned long int) l->l_entry, - sizeof (void *) * 2, (unsigned long int) l->l_phdr, - sizeof (void *) * 2, l->l_phnum); + (int) sizeof (void *) * 2, (unsigned long int) l->l_ld, + (int) sizeof (void *) * 2, (unsigned long int) l->l_addr, + (int) sizeof (void *) * 2, maplength, + (int) sizeof (void *) * 2, (unsigned long int) l->l_entry, + (int) sizeof (void *) * 2, (unsigned long int) l->l_phdr, + (int) sizeof (void *) * 2, l->l_phnum); elf_get_dynamic_info (l); @@ -1213,6 +1217,10 @@ open_verify (const char *name, struct filebuf *fbp) [EI_OSABI] = ELFOSABI_SYSV, [EI_ABIVERSION] = 0 }; + static const struct { + ElfW(Word) vendorlen, datalen, type; + char vendor [4]; + } expected_note = { 4, 16, 1, "GNU" }; int fd; /* Open the file. We always open files read-only. */ @@ -1220,6 +1228,10 @@ open_verify (const char *name, struct filebuf *fbp) if (fd != -1) { ElfW(Ehdr) *ehdr; + ElfW(Phdr) *phdr, *ph; + ElfW(Word) *abi_note, abi_note_buf[8]; + unsigned int osversion; + size_t maplength; /* We successfully openened the file. Now verify it is a file we can use. */ @@ -1287,12 +1299,7 @@ open_verify (const char *name, struct filebuf *fbp) lose (0, fd, name, NULL, NULL, N_("ELF file version does not match current one")); if (! __builtin_expect (elf_machine_matches_host (ehdr), 1)) - { - close_and_out: - __close (fd); - __set_errno (ENOENT); - fd = -1; - } + goto close_and_out; else if (__builtin_expect (ehdr->e_phentsize, sizeof (ElfW(Phdr))) != sizeof (ElfW(Phdr))) lose (0, fd, name, NULL, NULL, @@ -1301,6 +1308,50 @@ open_verify (const char *name, struct filebuf *fbp) && __builtin_expect (ehdr->e_type, ET_EXEC) != ET_EXEC) lose (0, fd, name, NULL, NULL, N_("only ET_DYN and ET_EXEC can be loaded")); + + maplength = ehdr->e_phnum * sizeof (ElfW(Phdr)); + if (ehdr->e_phoff + maplength <= fbp->len) + phdr = (void *) (fbp->buf + ehdr->e_phoff); + else + { + phdr = alloca (maplength); + __lseek (fd, SEEK_SET, ehdr->e_phoff); + if (__libc_read (fd, (void *) phdr, maplength) != maplength) + lose (errno, fd, name, NULL, NULL, N_("cannot read file data")); + } |
