commit 91b392a4bab0c2dc90e7e3ff914dec20b97adca8 Author: Ulrich Drepper Date: Sun Aug 21 13:52:28 2011 -0400 Use ifuncs for time and gettimeofday on x86-64 2011-08-21 Ulrich Drepper * sysdeps/unix/sysv/linux/x86_64/gettimeofday.S: Removed. * sysdeps/unix/sysv/linux/x86_64/time.S: Removed. * sysdeps/unix/sysv/linux/x86_64/gettimeofday.c: New file. * sysdeps/unix/sysv/linux/x86_64/time.c: New file. * sysdeps/unix/sysv/linux/x86_64/bits/libc-vdso.h: Remove declaration of __vdso_gettimeofday. * sysdeps/unix/sysv/linux/x86_64/init-first.c: Remove definition of __vdso_gettimeofday and __vdso_time. Define __vdso_getcpu with attribute_hidden. (_libc_vdso_platform_setup): Remove initialization of __vdso_gettimeofday and __vdso_time. diff --git a/sysdeps/unix/sysv/linux/x86_64/bits/libc-vdso.h b/sysdeps/unix/sysv/linux/x86_64/bits/libc-vdso.h index d7123c9..f9bf84e 100644 --- a/sysdeps/unix/sysv/linux/x86_64/bits/libc-vdso.h +++ b/sysdeps/unix/sysv/linux/x86_64/bits/libc-vdso.h @@ -1,5 +1,5 @@ /* Resolve function pointers to VDSO functions. - Copyright (C) 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2005, 2007, 2011 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 @@ -25,9 +25,6 @@ #ifdef SHARED -extern long int (*__vdso_gettimeofday) (struct timeval *, void *) - attribute_hidden; - extern long int (*__vdso_clock_gettime) (clockid_t, struct timespec *); #endif diff --git a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.S b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.S deleted file mode 100644 index f618e73..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.S +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 2002, 2003, 2007 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 - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#define _ERRNO_H 1 -#include - -/* For the calculation see asm/vsyscall.h. */ -#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000 - - -ENTRY (__gettimeofday) - /* Align stack. */ - sub $0x8, %rsp - cfi_adjust_cfa_offset(8) -#ifdef SHARED - movq __vdso_gettimeofday(%rip), %rax - PTR_DEMANGLE (%rax) -#else - movq $VSYSCALL_ADDR_vgettimeofday, %rax -#endif - callq *%rax - /* Check error return. */ - cmpl $-4095, %eax - jae SYSCALL_ERROR_LABEL - -L(pseudo_end): - add $0x8, %rsp - cfi_adjust_cfa_offset(-8) - ret -PSEUDO_END(__gettimeofday) - -strong_alias (__gettimeofday, __gettimeofday_internal) -weak_alias (__gettimeofday, gettimeofday) diff --git a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c new file mode 100644 index 0000000..1a773d6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c @@ -0,0 +1,49 @@ +/* Copyright (C) 2002, 2003, 2007, 2011 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000ul + + +#ifdef SHARED +void *gettimeofday_ifunc (void) __asm__ ("__gettimeofday"); + +void * +gettimeofday_ifunc (void) +{ + PREPARE_VERSION (linux26, "LINUX_2.6", 61765110); + + /* If the vDSO is not available we fall back on the old vsyscall. */ + return (_dl_vdso_vsym ("gettimeofday", &linux26) + ?: (void *) VSYSCALL_ADDR_vgettimeofday); +} +__asm (".type __gettimeofday, %gnu_indirect_function"); +#else +# include + +int +__gettimeofday (struct timeval *tv, struct timezone *tz) +{ + return ((int (*) (struct timeval *, struct timezone *)) VSYSCALL_ADDR_vgettimeofday) (tv, tz); +} +#endif + +weak_alias (__gettimeofday, gettimeofday) +strong_alias (__gettimeofday, __gettimeofday_internal) diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c index e676f62..25cf08b 100644 --- a/sysdeps/unix/sysv/linux/x86_64/init-first.c +++ b/sysdeps/unix/sysv/linux/x86_64/init-first.c @@ -20,15 +20,11 @@ # include # include -long int (*__vdso_gettimeofday) (struct timeval *, void *) attribute_hidden; - long int (*__vdso_clock_gettime) (clockid_t, struct timespec *) __attribute__ ((nocommon)); strong_alias (__vdso_clock_gettime, __GI___vdso_clock_gettime attribute_hidden) -long int (*__vdso_getcpu) (unsigned *, unsigned *, void *); - -long int (*__vdso_time) (time_t *) attribute_hidden; +long int (*__vdso_getcpu) (unsigned *, unsigned *, void *) attribute_hidden; static inline void @@ -36,15 +32,7 @@ _libc_vdso_platform_setup (void) { PREPARE_VERSION (linux26, "LINUX_2.6", 61765110); - void *p = _dl_vdso_vsym ("gettimeofday", &linux26); - /* If the vDSO is not available we fall back on the old vsyscall. */ -#define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000ul - if (p == NULL) - p = (void *) VSYSCALL_ADDR_vgettimeofday; - PTR_MANGLE (p); - __vdso_gettimeofday = p; - - p = _dl_vdso_vsym ("clock_gettime", &linux26); + void *p = _dl_vdso_vsym ("clock_gettime", &linux26); PTR_MANGLE (p); __GI___vdso_clock_gettime = p; @@ -55,14 +43,6 @@ _libc_vdso_platform_setup (void) p = (void *) VSYSCALL_ADDR_vgetcpu; PTR_MANGLE (p); __vdso_getcpu = p; - - p = _dl_vdso_vsym ("time", &linux26); - /* If the vDSO is not available we fall back on the old vsyscall. */ -#define VSYSCALL_ADDR_vtime 0xffffffffff600400 - if (p == NULL) - p = (void *) VSYSCALL_ADDR_vtime; - PTR_MANGLE (p); - __vdso_time = p; } # define VDSO_SETUP _libc_vdso_platform_setup diff --git a/sysdeps/unix/sysv/linux/x86_64/time.S b/sysdeps/unix/sysv/linux/x86_64/time.S deleted file mode 100644 index 66d7498..0000000 --- a/sysdeps/unix/sysv/linux/x86_64/time.S +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (C) 2001,02, 2003, 2011 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 - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#define _ERRNO_H 1 -#include - -/* For the calculation see asm/vsyscall.h. */ -#define VSYSCALL_ADDR_vtime 0xffffffffff600400 - - -/* Return the current time as a `time_t' and also put it in *T if T is - not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */ - -ENTRY (time) - /* Align stack. */ - sub $0x8, %rsp - cfi_adjust_cfa_offset(8) - -#ifdef SHARED - movq __vdso_time(%rip), %rax - PTR_DEMANGLE (%rax) -#else - movq $VSYSCALL_ADDR_vtime, %rax -#endif - callq *%rax - - add $0x8, %rsp - cfi_adjust_cfa_offset(-8) - ret -PSEUDO_END_NOERRNO(time) -libc_hidden_def (time) diff --git a/sysdeps/unix/sysv/linux/x86_64/time.c b/sysdeps/unix/sysv/linux/x86_64/time.c new file mode 100644 index 0000000..698d561 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/time.c @@ -0,0 +1,47 @@ +/* Copyright (C) 2001,02, 2003, 2011 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include + + +#define VSYSCALL_ADDR_vtime 0xffffffffff600400 + + +#ifdef SHARED +void *time_ifunc (void) __asm__ ("time"); + +void * +time_ifunc (void) +{ + PREPARE_VERSION (linux26, "LINUX_2.6", 61765110); + + /* If the vDSO is not available we fall back on the old vsyscall. */ + return _dl_vdso_vsym ("time", &linux26) ?: (void *) VSYSCALL_ADDR_vtime; +} +__asm (".type time, %gnu_indirect_function"); +#else +# include + +time_t +time (time_t *t) +{ + return ((time_t (*) (time_t *)) VSYSCALL_ADDR_vtime) (t); +} +#endif + +strong_alias (time, __GI_time) commit 2bc174332ba6ddbd1b855dced33889bef56e8ba3 Author: Andreas Schwab Date: Tue Aug 30 15:37:54 2011 +0200 Relocate objects in dependency order 2011-08-30 Andreas Schwab * elf/rtld.c (dl_main): Relocate objects in dependency order. diff --git a/elf/rtld.c b/elf/rtld.c index 87bb5f0..4f6bbfd 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -2255,13 +2255,12 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", /* If we are profiling we also must do lazy reloaction. */ GLRO(dl_lazy) |= consider_profiling; - struct link_map *l = main_map; - while (l->l_next) - l = l->l_next; - HP_TIMING_NOW (start); - do + unsigned i = main_map->l_searchlist.r_nlist; + while (i-- > 0) { + struct link_map *l = main_map->l_initfini[i]; + /* While we are at it, help the memory handling a bit. We have to mark some data structures as allocated with the fake malloc() implementation in ld.so. */ @@ -2280,10 +2279,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", /* Add object to slot information data if necessasy. */ if (l->l_tls_blocksize != 0 && tls_init_tp_called) _dl_add_to_slotinfo (l); - - l = l->l_prev; } - while (l); HP_TIMING_NOW (stop); HP_TIMING_DIFF (relocate_time, start, stop); commit e888bcbe4fb8ad538ec640bfb18b687d51e001e7 Author: Andreas Schwab Date: Mon Aug 22 16:08:16 2011 -0400 Correct cycle detection during dependency sorting 2011-08-16 Andreas Schwab [BZ #11724] * elf/dl-deps.c (_dl_map_object_deps): Only assume cycle when object is seen twice. * elf/dl-fini.c (_dl_sort_fini): Likewise. * elf/Makefile (distribute): Add tst-initorder2.c. (tests): Add tst-initorder2. (modules-names): Add tst-initorder2a tst-initorder2b tst-initorder2c tst-initorder2d. Add rules to build them. ($(objpfx)tst-initorder2.out): New rule. * elf/tst-initorder2.c: New file. * elf/tst-initorder2.exp: New file. 2011-08-21 Ulrich Drepper * sysdeps/unix/sysv/linux/x86_64/gettimeofday.S: Removed. diff --git a/elf/Makefile b/elf/Makefile index 709b61d..aeb6393 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -120,9 +120,10 @@ distribute := rtld-Rules \ ifuncmain7pie.c ifuncmain7static.c \ tst-unique1.c tst-unique1mod1.c tst-unique1mod2.c \ tst-unique2.c tst-unique2mod1.c tst-unique2mod2.c \ - tst-initordera1.c tst-initordera2.c tst-initorderb1.c \ - tst-initorderb2.c tst-initordera3.c tst-initordera4.c \ - tst-initorder.c + tst-initordera1.c tst-initordera2.c tst-initorderb1.c \ + tst-initorderb2.c tst-initordera3.c tst-initordera4.c \ + tst-initorder.c \ + tst-initorder2.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-initorder tst-initorder2 # reldep9 test-srcs = tst-pathopt selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null) @@ -288,7 +289,8 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-unique4lib \ tst-initordera1 tst-initorderb1 \ tst-initordera2 tst-initorderb2 \ - tst-initordera3 tst-initordera4 + tst-initordera3 tst-initordera4 \ + tst-initorder2a tst-initorder2b tst-initorder2c tst-initorder2d ifeq (yes,$(have-initfini-array)) modules-names += tst-array2dep tst-array5dep endif @@ -1157,6 +1159,23 @@ $(objpfx)tst-initorder.out: $(objpfx)tst-initorder $< > $@ cmp $@ tst-initorder.exp > /dev/null +$(objpfx)tst-initorder2: $(objpfx)tst-initorder2a.so $(objpfx)tst-initorder2d.so $(objpfx)tst-initorder2c.so +$(objpfx)tst-initorder2a.so: $(objpfx)tst-initorder2b.so +$(objpfx)tst-initorder2b.so: $(objpfx)tst-initorder2c.so +$(objpfx)tst-initorder2c.so: $(objpfx)tst-initorder2d.so +define o-iterator-doit +$(objpfx)tst-initorder2$o.os: tst-initorder2.c; \ +$$(compile-command.c) -DNAME=\"$o\" +endef +object-suffixes-left := a b c d +include $(o-iterator) + +$(objpfx)tst-initorder2.out: $(objpfx)tst-initorder2 + $(elf-objpfx)${rtld-installed-name} \ + --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ + $< > $@ + cmp $@ tst-initorder2.exp > /dev/null + ifeq (yes,$(config-cflags-avx)) AVX-CFLAGS=-mavx ifeq (yes,$(config-cflags-novzeroupper)) diff --git a/elf/dl-deps.c b/elf/dl-deps.c index 0b03b90..cc0023d 100644 --- a/elf/dl-deps.c +++ b/elf/dl-deps.c @@ -626,12 +626,12 @@ Filters not supported with LD_TRACE_PRELINKING")); /* We can skip looking for the binary itself which is at the front of the search list. */ i = 1; - bool seen[nlist]; - memset (seen, false, nlist * sizeof (seen[0])); + char seen[nlist]; + memset (seen, 0, nlist * sizeof (seen[0])); while (1) { /* Keep track of which object we looked at this round. */ - seen[i] = true; + seen[i] += seen[i] < 2; struct link_map *thisp = l_initfini[i]; /* Find the last object in the list for which the current one is @@ -652,15 +652,16 @@ Filters not supported with LD_TRACE_PRELINKING")); (k - i) * sizeof (l_initfini[0])); l_initfini[k] = thisp; - if (seen[i + 1]) + 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] = true; + seen[k] = this_seen; goto next; } @@ -671,7 +672,7 @@ Filters not supported with LD_TRACE_PRELINKING")); if (++i == nlist) break; next_clear: - memset (&seen[i], false, (nlist - i) * sizeof (seen[0])); + memset (&seen[i], 0, (nlist - i) * sizeof (seen[0])); next:; } diff --git a/elf/dl-fini.c b/elf/dl-fini.c index 0a138e9..bafc83a 100644 --- a/elf/dl-fini.c +++ b/elf/dl-fini.c @@ -39,12 +39,12 @@ _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used, Lmid_t ns) /* We can skip looking for the binary itself which is at the front of the search list for the main namespace. */ unsigned int i = ns == LM_ID_BASE; - bool seen[nmaps]; - memset (seen, false, nmaps * sizeof (seen[0])); + char seen[nmaps]; + memset (seen, 0, nmaps * sizeof (seen[0])); while (1) { /* Keep track of which object we looked at this round. */ - seen[i] = true; + seen[i] += seen[i] < 2; struct link_map *thisp = maps[i]; /* Do not handle ld.so in secondary namespaces and object which @@ -79,14 +79,15 @@ _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used, Lmid_t ns) used[k] = here_used; } - if (seen[i + 1]) + 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] = true; + seen[k] = this_seen; goto next; } @@ -96,7 +97,7 @@ _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used, Lmid_t ns) unsigned int m = maps[k]->l_reldeps->act; struct link_map **relmaps = &maps[k]->l_reldeps->list[0]; - /* Look through the relocation dependencies of the object. */ + /* Look through the relocation dependencies of the object. */ while (m-- > 0) if (__builtin_expect (relmaps[m] == thisp, 0)) goto move; @@ -109,7 +110,7 @@ _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used, Lmid_t ns) if (++i == nmaps) break; next_clear: - memset (&seen[i], false, (nmaps - i) * sizeof (seen[0])); + memset (&seen[i], 0, (nmaps - i) * sizeof (seen[0])); next:; } diff --git a/elf/tst-initorder2.c b/elf/tst-initorder2.c new file mode 100644 index 0000000..050f956 --- /dev/null +++ b/elf/tst-initorder2.c @@ -0,0 +1,20 @@ +#include + +#ifndef NAME +int +main (void) +{ + puts ("main"); +} +#else +static void __attribute__ ((constructor)) +init (void) +{ + puts ("init: " NAME); +} +static void __attribute__ ((destructor)) +fini (void) +{ + puts ("fini: " NAME); +} +#endif diff --git a/elf/tst-initorder2.exp b/elf/tst-initorder2.exp new file mode 100644 index 0000000..5169489 --- /dev/null +++ b/elf/tst-initorder2.exp @@ -0,0 +1,9 @@ +init: d +init: c +init: b +init: a +main +fini: a +fini: b +fini: c +fini: d