# HG changeset patch # User Christophe Lincoln # Date 1336061231 -7200 # Node ID cf41f89ddb40b863802f8ac7cae65aa05d2f19d6 # Parent 6fef0ccec3319bca0f7d4062786451fc1dac13f0 Add: cross-arm-glibc (2.14.1) diff -r 6fef0ccec331 -r cf41f89ddb40 cross-arm-glibc/receipt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross-arm-glibc/receipt Thu May 03 18:07:11 2012 +0200 @@ -0,0 +1,74 @@ +# SliTaz package receipt. + +PACKAGE="cross-arm-glibc" +VERSION="2.14.1" +CATEGORY="system-tools" +SHORT_DESC="The GNU C libraries for the ARM cross toolchain" +MAINTAINER="pankso@slitaz.org" +SOURCE="glibc" +TARBALL="$SOURCE-$VERSION.tar.gz" +WEB_SITE="http://www.gnu.org/software/libc/" +WGET_URL="$GNU_MIRROR/$PACKAGE/$TARBALL" + +DEPENDS="" +BUILD_DEPENDS="linux-arm-api-headers cross-arm-binutils cross-arm-gcc \ +autoconf bash gawk" + +# Cross toolchain variables. +CROSS_TARGET="arm-slitaz-linux-gnueabi" +CROSS_PREFIX="/usr/cross/arm" +CROSS_TRIPLET="--build=$HOST_SYSTEM --host=$HOST_SYSTEM --target=$CROSS_TARGET" + +# CFLAGS and CXXFLAGS must not be set during the building of cross-tools. +unset CFLAGS CXXFLAGS CONFIG_SITE + +# Path to cross tools +export PATH=$PATH:$CROSS_PREFIX/bin + +# Rules to configure and make the package. +compile_rules() +{ + echo "cook: make linux/version.h" + cd $CROSS_PREFIX/include + make linux/version.h + + cd $src + + # Glibc ports. + if [ ! -f "$SRC/glibc-ports-$VERSION.tar.bz2" ]; then + wget $GNU_MIRROR/$SOURCE/glibc-ports-$VERSION.tar.bz2 \ + -O $SRC/glibc-ports-$VERSION.tar.bz2 + fi + echo "Extracting glibc-ports..." + tar xjf $SRC/glibc-ports-$VERSION.tar.bz2 + mv glibc-ports-$VERSION ports + + # #define TLS_DTV_UNALLOCATED ((void *) -1l) is already in dl-tls.h + #echo "#define TLS_DTV_UNALLOCATED ((void *) -1l)" \ + # >> ports/sysdeps/arm/dl-tls.h + + mkdir ../glibc-build && cd ../glibc-build + CC=$CROSS_PREFIX/bin/$CROSS_TARGET-gcc + echo "libc_cv_forced_unwind=yes" > config.cache + echo "libc_cv_c_cleanup=yes" >> config.cache + $src/configure \ + --prefix=$CROSS_PREFIX \ + --enable-add-ons \ + --with-headers=$CROSS_PREFIX/include \ + --with-binutils=$CROSS_PREFIX/bin \ + --config-cache \ + --build=$HOST_SYSTEM \ + --host=$CROSS_TARGET && + make && make install_root=$DESTDIR install +} + +# Rules to gen a SliTaz package suitable for Tazpkg. +genpkg_rules() +{ + mkdir -p $fs/usr + cp -a $install/usr/cross $fs/usr + #cd ${fs}${CROSS_PREFIX}/$CROSS_TARGET + #rm -rf lib include + #ln -s ../lib lib + #ln -s ../include include +} diff -r 6fef0ccec331 -r cf41f89ddb40 cross-arm-glibc/stuff/glibc-2.14-reexport-rpc-interface.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross-arm-glibc/stuff/glibc-2.14-reexport-rpc-interface.patch Thu May 03 18:07:11 2012 +0200 @@ -0,0 +1,26 @@ +diff --git a/include/libc-symbols.h b/include/libc-symbols.h +index 67e1ca2..5e7cca5 100644 +--- a/include/libc-symbols.h ++++ b/include/libc-symbols.h +@@ -635,7 +635,7 @@ for linking") + # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) + # define libc_hidden_def(name) hidden_def (name) + # define libc_hidden_weak(name) hidden_weak (name) +-# define libc_hidden_nolink(name, version) hidden_nolink (name, libc, version) ++# define libc_hidden_nolink(name, version) hidden_def (name) + # define libc_hidden_ver(local, name) hidden_ver (local, name) + # define libc_hidden_data_def(name) hidden_data_def (name) + # define libc_hidden_data_weak(name) hidden_data_weak (name) +diff --git a/sunrpc/Makefile b/sunrpc/Makefile +index 5134ce9..40c73d1 100644 +--- a/sunrpc/Makefile ++++ b/sunrpc/Makefile +@@ -53,7 +53,7 @@ headers-in-tirpc = $(addprefix rpc/,auth.h auth_unix.h clnt.h pmap_clnt.h \ + des_crypt.h) + headers-not-in-tirpc = $(addprefix rpc/,key_prot.h rpc_des.h) \ + $(rpcsvc:%=rpcsvc/%) rpcsvc/bootparam.h +-headers = rpc/netdb.h ++headers = rpc/netdb.h $(headers-in-tirpc) $(headers-not-in-tirpc) + install-others = $(inst_sysconfdir)/rpc + generated = $(rpcsvc:%.x=rpcsvc/%.h) $(rpcsvc:%.x=x%.c) $(rpcsvc:%.x=x%.stmp) \ + $(rpcsvc:%.x=rpcsvc/%.stmp) rpcgen diff -r 6fef0ccec331 -r cf41f89ddb40 cross-arm-glibc/stuff/glibc-2.14-reinstall-nis-rpc-headers.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross-arm-glibc/stuff/glibc-2.14-reinstall-nis-rpc-headers.patch Thu May 03 18:07:11 2012 +0200 @@ -0,0 +1,28 @@ +From bdd816a366c4e5bba5de7157d948e0c0737fb4fb Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Tue, 17 May 2011 17:42:30 +0200 +Subject: [PATCH] Reinstall NIS RPC headers + +--- + nis/Makefile | 4 ++-- + 1 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/nis/Makefile b/nis/Makefile +index b5c9609..d2934d9 100644 +--- a/nis/Makefile ++++ b/nis/Makefile +@@ -23,9 +23,9 @@ subdir := nis + + aux := nis_hash + ++headers := $(wildcard rpcsvc/*.[hx]) + distribute := nss-nis.h nss-nisplus.h nis_intern.h Banner \ +- nisplus-parser.h nis_xdr.h nss \ +- $(wildcard rpcsvc/*.[hx]) ++ nisplus-parser.h nis_xdr.h nss + + # These are the databases available for the nis (and perhaps later nisplus) + # service. This must be a superset of the services in nss. +-- +1.7.5.4 + diff -r 6fef0ccec331 -r cf41f89ddb40 cross-arm-glibc/stuff/glibc-2.14-revert-4768ae77.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross-arm-glibc/stuff/glibc-2.14-revert-4768ae77.patch Thu May 03 18:07:11 2012 +0200 @@ -0,0 +1,37 @@ +diff -Naur glibc-orig//resolv/res_send.c glibc/resolv/res_send.c +--- glibc-orig//resolv/res_send.c 2011-06-10 18:59:03.041436996 +1000 ++++ glibc/resolv/res_send.c 2011-06-10 19:08:09.379309323 +1000 +@@ -549,7 +549,7 @@ + ns, ansp, ansp2, nansp2, resplen2); + if (n < 0) + return (-1); +- if (n == 0 && (buf2 == NULL || *resplen2 == 0)) ++ if (n == 0) + goto next_ns; + } else { + /* Use datagrams. */ +@@ -559,7 +559,7 @@ + ansp2, nansp2, resplen2); + if (n < 0) + return (-1); +- if (n == 0 && (buf2 == NULL || *resplen2 == 0)) ++ if (n == 0) + goto next_ns; + if (v_circuit) + // XXX Check whether both requests failed or +@@ -1275,14 +1275,10 @@ + (*thisresplenp > *thisanssizp) + ? *thisanssizp : *thisresplenp); + +- if (recvresp1 || (buf2 != NULL && recvresp2)) { +- *resplen2 = 0; ++ if (recvresp1 || (buf2 != NULL && recvresp2)) + return resplen; +- } + if (buf2 != NULL) + { +- /* No data from the first reply. */ +- resplen = 0; + /* We are waiting for a possible second reply. */ + if (hp->id == anhp->id) + recvresp1 = 1; diff -r 6fef0ccec331 -r cf41f89ddb40 cross-arm-glibc/stuff/glibc-2.14.1-fixes-1.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross-arm-glibc/stuff/glibc-2.14.1-fixes-1.patch Thu May 03 18:07:11 2012 +0200 @@ -0,0 +1,159 @@ +Submitted By: Matt Burgess +Date: 2011-10-07 +Initial Package Version: 2.14.1 +Upstream Status: From upstream +Origin: Matt Burgess +Description: Fixes Firefox crashes and a bug when programs link to + SDL. + +diff -Naur glibc-2.14.1.orig/elf/dl-close.c glibc-2.14.1/elf/dl-close.c +--- glibc-2.14.1.orig/elf/dl-close.c 2011-10-07 09:48:55.000000000 +0000 ++++ glibc-2.14.1/elf/dl-close.c 2011-10-07 19:43:10.346411120 +0000 +@@ -119,17 +119,8 @@ + if (map->l_direct_opencount > 0 || map->l_type != lt_loaded + || dl_close_state != not_pending) + { +- if (map->l_direct_opencount == 0) +- { +- if (map->l_type == lt_loaded) +- dl_close_state = rerun; +- else if (map->l_type == lt_library) +- { +- struct link_map **oldp = map->l_initfini; +- map->l_initfini = map->l_orig_initfini; +- _dl_scope_free (oldp); +- } +- } ++ if (map->l_direct_opencount == 0 && map->l_type == lt_loaded) ++ dl_close_state = rerun; + + /* There are still references to this object. Do nothing more. */ + if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0)) +diff -Naur glibc-2.14.1.orig/elf/dl-deps.c glibc-2.14.1/elf/dl-deps.c +--- glibc-2.14.1.orig/elf/dl-deps.c 2011-10-07 09:48:55.000000000 +0000 ++++ glibc-2.14.1/elf/dl-deps.c 2011-10-07 19:43:10.348432639 +0000 +@@ -478,6 +478,7 @@ + nneeded * sizeof needed[0]); + atomic_write_barrier (); + l->l_initfini = l_initfini; ++ l->l_free_initfini = 1; + } + + /* If we have no auxiliary objects just go on to the next map. */ +@@ -678,6 +679,7 @@ + l_initfini[nlist] = NULL; + atomic_write_barrier (); + map->l_initfini = l_initfini; ++ map->l_free_initfini = 1; + if (l_reldeps != NULL) + { + atomic_write_barrier (); +@@ -686,7 +688,7 @@ + _dl_scope_free (old_l_reldeps); + } + if (old_l_initfini != NULL) +- map->l_orig_initfini = old_l_initfini; ++ _dl_scope_free (old_l_initfini); + + if (errno_reason) + _dl_signal_error (errno_reason == -1 ? 0 : errno_reason, objname, +diff -Naur glibc-2.14.1.orig/elf/dl-libc.c glibc-2.14.1/elf/dl-libc.c +--- glibc-2.14.1.orig/elf/dl-libc.c 2011-10-07 09:48:55.000000000 +0000 ++++ glibc-2.14.1/elf/dl-libc.c 2011-10-07 19:43:10.352411141 +0000 +@@ -279,6 +279,10 @@ + if (! old->dont_free) + free (old); + } ++ ++ /* Free the initfini dependency list. */ ++ if (l->l_free_initfini) ++ free (l->l_initfini); + } + + if (__builtin_expect (GL(dl_ns)[ns]._ns_global_scope_alloc, 0) != 0 +diff -Naur glibc-2.14.1.orig/elf/rtld.c glibc-2.14.1/elf/rtld.c +--- glibc-2.14.1.orig/elf/rtld.c 2011-10-07 09:48:55.000000000 +0000 ++++ glibc-2.14.1/elf/rtld.c 2011-10-07 19:43:10.355406263 +0000 +@@ -2263,6 +2263,7 @@ + lnp->dont_free = 1; + lnp = lnp->next; + } ++ l->l_free_initfini = 0; + + if (l != &GL(dl_rtld_map)) + _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy) ? RTLD_LAZY : 0, +diff -Naur glibc-2.14.1.orig/include/link.h glibc-2.14.1/include/link.h +--- glibc-2.14.1.orig/include/link.h 2011-10-07 09:48:55.000000000 +0000 ++++ glibc-2.14.1/include/link.h 2011-10-07 19:43:10.357462703 +0000 +@@ -192,6 +192,9 @@ + during LD_TRACE_PRELINKING=1 + contains any DT_SYMBOLIC + libraries. */ ++ unsigned int l_free_initfini:1; /* Nonzero if l_initfini can be ++ freed, ie. not allocated with ++ the dummy malloc in ld.so. */ + + /* Collected information about own RPATH directories. */ + struct r_search_path_struct l_rpath_dirs; +@@ -240,9 +243,6 @@ + + /* List of object in order of the init and fini calls. */ + struct link_map **l_initfini; +- /* The init and fini list generated at startup, saved when the +- object is also loaded dynamically. */ +- struct link_map **l_orig_initfini; + + /* List of the dependencies introduced through symbol binding. */ + struct link_map_reldeps +diff -Naur glibc-2.14.1.orig/resolv/res_query.c glibc-2.14.1/resolv/res_query.c +--- glibc-2.14.1.orig/resolv/res_query.c 2011-10-07 09:48:55.000000000 +0000 ++++ glibc-2.14.1/resolv/res_query.c 2011-10-07 19:43:10.361412711 +0000 +@@ -122,6 +122,7 @@ + int *resplen2) + { + HEADER *hp = (HEADER *) answer; ++ HEADER *hp2; + int n, use_malloc = 0; + u_int oflags = statp->_flags; + +@@ -239,26 +240,25 @@ + /* __libc_res_nsend might have reallocated the buffer. */ + hp = (HEADER *) *answerp; + +- /* We simplify the following tests by assigning HP to HP2. It +- is easy to verify that this is the same as ignoring all +- tests of HP2. */ +- HEADER *hp2 = answerp2 ? (HEADER *) *answerp2 : hp; +- +- if (n < (int) sizeof (HEADER) && answerp2 != NULL +- && *resplen2 > (int) sizeof (HEADER)) ++ /* We simplify the following tests by assigning HP to HP2 or ++ vice versa. It is easy to verify that this is the same as ++ ignoring all tests of HP or HP2. */ ++ if (answerp2 == NULL || *resplen2 < (int) sizeof (HEADER)) + { +- /* Special case of partial answer. */ +- assert (hp != hp2); +- hp = hp2; ++ hp2 = hp; + } +- else if (answerp2 != NULL && *resplen2 < (int) sizeof (HEADER) +- && n > (int) sizeof (HEADER)) ++ else + { +- /* Special case of partial answer. */ +- assert (hp != hp2); +- hp2 = hp; ++ hp2 = (HEADER *) *answerp2; ++ if (n < (int) sizeof (HEADER)) ++ { ++ hp = hp2; ++ } + } + ++ /* Make sure both hp and hp2 are defined */ ++ assert((hp != NULL) && (hp2 != NULL)); ++ + if ((hp->rcode != NOERROR || ntohs(hp->ancount) == 0) + && (hp2->rcode != NOERROR || ntohs(hp2->ancount) == 0)) { + #ifdef DEBUG diff -r 6fef0ccec331 -r cf41f89ddb40 cross-arm-glibc/stuff/glibc-2.14.1-gcc_fix-1.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross-arm-glibc/stuff/glibc-2.14.1-gcc_fix-1.patch Thu May 03 18:07:11 2012 +0200 @@ -0,0 +1,49 @@ +Submitted By: Matt Burgess +Date: 2010-04-18 +Initial Package Version: 2.11.1 +Upstream Status: Not Submitted +Origin: http://www.eglibc.org/archives/patches/msg00073.html +Description: Fixes the following build problem with GCC-4.5.0: + +/mnt/lfs/sources/libc-build/math/s_frexp.os.dt -MT /mnt/lfs/sources/libc-build/math/s_frexp.os +./sysdeps/i386/fpu/s_frexp.S: Assembler messages: +./sysdeps/i386/fpu/s_frexp.S:66: Error: invalid identifier for ".ifdef" +./sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1' +./sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1' +./sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1' +./sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `.' +./sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1' +./sysdeps/i386/fpu/s_frexp.S:66: Error: expected comma after name `' in .size directive +./sysdeps/i386/fpu/s_frexp.S:66: Error: ".endif" without ".if" +./sysdeps/i386/fpu/s_frexp.S:66: Error: junk `.get_pc_thunk.dx' after expression +make[2]: *** [/mnt/lfs/sources/libc-build/math/s_frexp.os] Error 1 + +diff -Naur glibc-2.11.1.orig/nptl/sysdeps/pthread/pt-initfini.c glibc-2.11.1/nptl/sysdeps/pthread/pt-initfini.c +--- glibc-2.11.1.orig/nptl/sysdeps/pthread/pt-initfini.c 2009-12-08 20:10:20.000000000 +0000 ++++ glibc-2.11.1/nptl/sysdeps/pthread/pt-initfini.c 2010-04-17 11:34:06.882681001 +0000 +@@ -45,6 +45,11 @@ + /* Embed an #include to pull in the alignment and .end directives. */ + asm ("\n#include \"defs.h\""); + ++asm ("\n#if defined __i686 && defined __ASSEMBLER__"); ++asm ("\n#undef __i686"); ++asm ("\n#define __i686 __i686"); ++asm ("\n#endif"); ++ + /* The initial common code ends here. */ + asm ("\n/*@HEADER_ENDS*/"); + +diff -Naur glibc-2.11.1.orig/sysdeps/unix/sysv/linux/i386/sysdep.h glibc-2.11.1/sysdeps/unix/sysv/linux/i386/sysdep.h +--- glibc-2.11.1.orig/sysdeps/unix/sysv/linux/i386/sysdep.h 2009-12-08 20:10:20.000000000 +0000 ++++ glibc-2.11.1/sysdeps/unix/sysv/linux/i386/sysdep.h 2010-04-17 11:34:06.882681001 +0000 +@@ -29,6 +29,10 @@ + #include + #include + ++#if defined __i686 && defined __ASSEMBLER__ ++#undef __i686 ++#define __i686 __i686 ++#endif + + /* For Linux we can use the system call table in the header file + /usr/include/asm/unistd.h diff -r 6fef0ccec331 -r cf41f89ddb40 cross-arm-glibc/stuff/glibc-2.14.1-sort-1.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cross-arm-glibc/stuff/glibc-2.14.1-sort-1.patch Thu May 03 18:07:11 2012 +0200 @@ -0,0 +1,273 @@ +Submitted By: Bruce Dubbs +Date: 2012-02-24 +Initial Package Version: 2.14.1 +Upstream Status: From upstream +Origin: Upstream +Description: Sort objects by dependency before relocation. + Fixes segfault in dlopen for several programs. + +diff --git a/Makeconfig b/Makeconfig +index 2db2821..68547b2 100644 +--- a/Makeconfig ++++ b/Makeconfig +@@ -938,6 +938,12 @@ libdl = + endif + endif + ++ifeq ($(build-shared),yes) ++libm = $(common-objpfx)math/libm.so$(libm.so-version) ++else ++libm = $(common-objpfx)math/libm.a ++endif ++ + # These are the subdirectories containing the library source. The order + # is more or less arbitrary. The sorting step will take care of the + # dependencies. +diff --git a/elf/Makefile b/elf/Makefile +index 052e763..3f1772a 100644 +--- a/elf/Makefile ++++ b/elf/Makefile +@@ -124,7 +124,8 @@ distribute := rtld-Rules \ + tst-initordera1.c tst-initordera2.c tst-initorderb1.c \ + tst-initorderb2.c tst-initordera3.c tst-initordera4.c \ + tst-initorder.c \ +- tst-initorder2.c ++ tst-initorder2.c \ ++ tst-relsort1.c tst-relsort1mod1.c tst-relsort1mod2.c + + CFLAGS-dl-runtime.c = -fexceptions -fasynchronous-unwind-tables + CFLAGS-dl-lookup.c = -fexceptions -fasynchronous-unwind-tables +@@ -227,7 +228,7 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \ + tst-audit1 tst-audit2 \ + tst-stackguard1 tst-addr1 tst-thrlock \ + tst-unique1 tst-unique2 tst-unique3 tst-unique4 \ +- tst-initorder tst-initorder2 ++ tst-initorder tst-initorder2 tst-relsort1 + # reldep9 + test-srcs = tst-pathopt + selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null) +@@ -290,7 +291,9 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ + tst-initordera1 tst-initorderb1 \ + tst-initordera2 tst-initorderb2 \ + tst-initordera3 tst-initordera4 \ +- tst-initorder2a tst-initorder2b tst-initorder2c tst-initorder2d ++ tst-initorder2a tst-initorder2b tst-initorder2c \ ++ tst-initorder2d \ ++ tst-relsort1mod1 tst-relsort1mod2 + ifeq (yes,$(have-initfini-array)) + modules-names += tst-array2dep tst-array5dep + endif +@@ -1195,3 +1198,9 @@ CFLAGS-tst-auditmod6b.c += $(AVX-CFLAGS) + CFLAGS-tst-auditmod6c.c += $(AVX-CFLAGS) + CFLAGS-tst-auditmod7b.c += $(AVX-CFLAGS) + endif ++ ++$(objpfx)tst-relsort1: $(libdl) ++$(objpfx)tst-relsort1mod1.so: $(libm) $(objpfx)tst-relsort1mod2.so ++$(objpfx)tst-relsort1mod2.so: $(libm) ++$(objpfx)tst-relsort1.out: $(objpfx)tst-relsort1mod1.so \ ++ $(objpfx)tst-relsort1mod2.so +diff --git a/elf/dl-open.c b/elf/dl-open.c +index a0b5c50..a56bdc1 100644 +--- a/elf/dl-open.c ++++ b/elf/dl-open.c +@@ -1,5 +1,5 @@ + /* Load a shared object at runtime, relocate it, and run its initializer. +- Copyright (C) 1996-2007, 2009, 2010, 2011 Free Software Foundation, Inc. ++ Copyright (C) 1996-2007, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or +@@ -303,45 +303,109 @@ dl_open_worker (void *a) + if (GLRO(dl_lazy)) + reloc_mode |= mode & RTLD_LAZY; + +- /* Relocate the objects loaded. We do this in reverse order so that copy +- relocs of earlier objects overwrite the data written by later objects. */ +- ++ /* Sort the objects by dependency for the relocation process. This ++ allows IFUNC relocations to work and it also means copy ++ relocation of dependencies are if necessary overwritten. */ ++ size_t nmaps = 0; + struct link_map *l = new; +- while (l->l_next) +- l = l->l_next; +- while (1) ++ do ++ { ++ if (! l->l_real->l_relocated) ++ ++nmaps; ++ l = l->l_next; ++ } ++ while (l != NULL); ++ struct link_map *maps[nmaps]; ++ nmaps = 0; ++ l = new; ++ do + { + if (! l->l_real->l_relocated) ++ maps[nmaps++] = l; ++ l = l->l_next; ++ } ++ while (l != NULL); ++ if (nmaps > 1) ++ { ++ char seen[nmaps]; ++ memset (seen, '\0', nmaps); ++ size_t i = 0; ++ while (1) + { +-#ifdef SHARED +- if (__builtin_expect (GLRO(dl_profile) != NULL, 0)) ++ ++seen[i]; ++ struct link_map *thisp = maps[i]; ++ ++ /* Find the last object in the list for which the current one is ++ a dependency and move the current object behind the object ++ with the dependency. */ ++ size_t k = nmaps - 1; ++ while (k > i) + { +- /* If this here is the shared object which we want to profile +- make sure the profile is started. We can find out whether +- this is necessary or not by observing the `_dl_profile_map' +- variable. If was NULL but is not NULL afterwars we must +- start the profiling. */ +- struct link_map *old_profile_map = GL(dl_profile_map); ++ struct link_map **runp = maps[k]->l_initfini; ++ if (runp != NULL) ++ /* Look through the dependencies of the object. */ ++ while (*runp != NULL) ++ if (__builtin_expect (*runp++ == thisp, 0)) ++ { ++ /* Move the current object to the back past the last ++ object with it as the dependency. */ ++ memmove (&maps[i], &maps[i + 1], ++ (k - i) * sizeof (maps[0])); ++ maps[k] = thisp; ++ ++ if (seen[i + 1] > 1) ++ { ++ ++i; ++ goto next_clear; ++ } ++ ++ char this_seen = seen[i]; ++ memmove (&seen[i], &seen[i + 1], ++ (k - i) * sizeof (seen[0])); ++ seen[k] = this_seen; ++ ++ goto next; ++ } ++ ++ --k; ++ } + +- _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1); ++ if (++i == nmaps) ++ break; ++ next_clear: ++ memset (&seen[i], 0, (nmaps - i) * sizeof (seen[0])); ++ next:; ++ } ++ } + +- if (old_profile_map == NULL && GL(dl_profile_map) != NULL) +- { +- /* We must prepare the profiling. */ +- _dl_start_profile (); ++ for (size_t i = nmaps; i-- > 0; ) ++ { ++ l = maps[i]; + +- /* Prevent unloading the object. */ +- GL(dl_profile_map)->l_flags_1 |= DF_1_NODELETE; +- } ++#ifdef SHARED ++ if (__builtin_expect (GLRO(dl_profile) != NULL, 0)) ++ { ++ /* If this here is the shared object which we want to profile ++ make sure the profile is started. We can find out whether ++ this is necessary or not by observing the `_dl_profile_map' ++ variable. If it was NULL but is not NULL afterwars we must ++ start the profiling. */ ++ struct link_map *old_profile_map = GL(dl_profile_map); ++ ++ _dl_relocate_object (l, l->l_scope, reloc_mode | RTLD_LAZY, 1); ++ ++ if (old_profile_map == NULL && GL(dl_profile_map) != NULL) ++ { ++ /* We must prepare the profiling. */ ++ _dl_start_profile (); ++ ++ /* Prevent unloading the object. */ ++ GL(dl_profile_map)->l_flags_1 |= DF_1_NODELETE; + } +- else +-#endif +- _dl_relocate_object (l, l->l_scope, reloc_mode, 0); + } +- +- if (l == new) +- break; +- l = l->l_prev; ++ else ++#endif ++ _dl_relocate_object (l, l->l_scope, reloc_mode, 0); + } + + /* If the file is not loaded now as a dependency, add the search +diff --git a/elf/tst-relsort1.c b/elf/tst-relsort1.c +new file mode 100644 +index 0000000..972100c +--- /dev/null ++++ b/elf/tst-relsort1.c +@@ -0,0 +1,19 @@ ++#include ++#include ++ ++ ++static int ++do_test () ++{ ++ const char lib[] = "$ORIGIN/tst-relsort1mod1.so"; ++ void *h = dlopen (lib, RTLD_NOW); ++ if (h == NULL) ++ { ++ puts (dlerror ()); ++ return 1; ++ } ++ return 0; ++} ++ ++#define TEST_FUNCTION do_test () ++#include "../test-skeleton.c" +diff --git a/elf/tst-relsort1mod1.c b/elf/tst-relsort1mod1.c +new file mode 100644 +index 0000000..9e4a943 +--- /dev/null ++++ b/elf/tst-relsort1mod1.c +@@ -0,0 +1,7 @@ ++extern int foo (double); ++ ++int ++bar (void) ++{ ++ return foo (1.2); ++} +diff --git a/elf/tst-relsort1mod2.c b/elf/tst-relsort1mod2.c +new file mode 100644 +index 0000000..a2c3e55 +--- /dev/null ++++ b/elf/tst-relsort1mod2.c +@@ -0,0 +1,7 @@ ++#include ++ ++int ++foo (double d) ++{ ++ return floor (d) != 0.0; ++} +-- +1.7.3.4 +