1 http://thread.gmane.org/gmane.comp.lib.glibc.user/579
2 http://sources.redhat.com/bugzilla/show_bug.cgi?id=11929
3 http://bugs.gentoo.org/332927
5 a simple statically linked app fails with glibc-2.12:
7 main(){getpwnam("root");}
10 a.out: ../sysdeps/unix/sysv/linux/getpagesize.c:32: __getpagesize:
11 Assertion `_rtld_global_ro._dl_pagesize != 0' failed.
14 the crux of the matter seems to be the fact that static apps with
15 glibc will dynamically load nss shared libraries when necessary. the
16 static code will initialize GLRO(dl_pagesize) just fine from the
17 kernel auxv, but this being the static code paths, GLRO(dl_pagesize)
18 expands into _dl_pagesize. when the nss shared libraries are loaded
19 up, the ldso is also mapped in, but it doesnt process the kernel auxv
20 (_dl_sysdep_start() is not called). so the shared library
21 GLRO(dl_pagesize) expands into _rtld_global_ro._dl_pagesize and that
24 then when the nss shared libs process the request and gets to the
25 standard "passwd" database, it calls the shared lib versions of
26 malloc/stdio which rely on the __getpagesize() function. but this
27 being in the shared library, it reads the shared GLRO(dl_pagesize)
28 which is 0, and the assert() is triggered.
30 i think running nscd makes things work because its nss module that
31 talks to the nscd daemon doesnt call any routines that implicitly rely
34 this all started happening after this commit:
35 From 8f4a5048eea6536ee85c0f2670adbb97d71e427d Mon Sep 17 00:00:00 2001
36 From: Ulrich Drepper <drepper@redhat.com>
37 Date: Sat, 27 Mar 2010 06:19:50 -0700
38 Subject: [PATCH] Optimize __getpagesize a bit.
40 if we look at the ia64 port, we see that it has had similar logic for
41 its __getpagesize function forever. so take its DL_STATIC_INIT code
42 and move it up to the common linux tree.
44 2010-08-18 Mike Frysinger <vapier@gentoo.org>
46 * sysdeps/unix/sysv/linux/ia64/Makefile: Move dl-static addition to
47 sysdep vars for subdir==elf to ...
48 * sysdeps/unix/sysv/linux/Makefile: ... here.
49 * sysdeps/unix/sysv/linux/ia64/dl-static.c: Move file to ...
50 * sysdeps/unix/sysv/linux/dl-static.c: ... here.
51 * sysdeps/unix/sysv/linux/ia64/ldsodefs.h: Delete, and move the
52 DL_STATIC_INIT defines to ...
53 * sysdeps/unix/sysv/linux/ldsodefs.h: ... here.
54 * sysdeps/unix/sysv/linux/ia64/getpagesize.c: Delete.
56 diff --git a/sysdeps/unix/sysv/linux/ia64/Makefile b/sysdeps/unix/sysv/linux/ia64/Makefile
57 index d9a35a7..3bb1ce0 100644
58 --- a/sysdeps/unix/sysv/linux/ia64/Makefile
59 +++ b/sysdeps/unix/sysv/linux/ia64/Makefile
60 @@ -12,12 +12,6 @@ sysdep_headers += sys/io.h
61 sysdep_routines += ioperm clone2
65 -sysdep-dl-routines += dl-static
66 -sysdep_routines += $(sysdep-dl-routines)
67 -sysdep-rtld-routines += $(sysdep-dl-routines)
71 librt-routines += rt-sysdep
73 diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
74 index 4302bd3..37c56a3 100644
75 --- a/sysdeps/unix/sysv/linux/Makefile
76 +++ b/sysdeps/unix/sysv/linux/Makefile
81 +sysdep-dl-routines += dl-static
82 +sysdep_routines += dl-static
83 sysdep-rtld-routines += dl-brk dl-sbrk dl-getcwd dl-openat64 dl-opendir \
85 + dl-fxstatat64 dl-static
87 CPPFLAGS-lddlibc4 += -DNOT_IN_libc
89 diff --git a/sysdeps/unix/sysv/linux/ia64/dl-static.c b/sysdeps/unix/sysv/linux/ia64/dl-static.c
90 deleted file mode 100644
91 index 4efc077..0000000
92 --- a/sysdeps/unix/sysv/linux/ia64/dl-static.c
95 -/* Variable initialization. IA-64 version.
96 - Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
97 - This file is part of the GNU C Library.
99 - The GNU C Library is free software; you can redistribute it and/or
100 - modify it under the terms of the GNU Lesser General Public
101 - License as published by the Free Software Foundation; either
102 - version 2.1 of the License, or (at your option) any later version.
104 - The GNU C Library is distributed in the hope that it will be useful,
105 - but WITHOUT ANY WARRANTY; without even the implied warranty of
106 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
107 - Lesser General Public License for more details.
109 - You should have received a copy of the GNU Lesser General Public
110 - License along with the GNU C Library; if not, write to the Free
111 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
114 -#include <ldsodefs.h>
119 -_dl_var_init (void *array[])
121 - /* It has to match "variables" below. */
128 - GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
129 - GLRO(dl_clktck) = *((int *) array[DL_CLKTCK]);
133 -#include <bits/libc-lock.h>
135 -__libc_lock_define_initialized_recursive (static, _dl_static_lock)
137 -static void *variables[] =
139 - &GLRO(dl_pagesize),
144 -_dl_static_init (struct link_map *map)
146 - const ElfW(Sym) *ref = NULL;
148 - void (*f) (void *[]);
150 - __libc_lock_lock_recursive (_dl_static_lock);
152 - loadbase = _dl_lookup_symbol_x ("_dl_var_init", map, &ref,
153 - map->l_local_scope, NULL, 0, 1, NULL);
156 - f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
160 - __libc_lock_unlock_recursive (_dl_static_lock);
164 diff --git a/sysdeps/unix/sysv/linux/dl-static.c b/sysdeps/unix/sysv/linux/dl-static.c
166 index 0000000..fa70811
168 +++ b/sysdeps/unix/sysv/linux/dl-static.c
170 +/* Variable initialization.
171 + Copyright (C) 2001, 2002, 2003, 2004, 2010 Free Software Foundation, Inc.
172 + This file is part of the GNU C Library.
174 + The GNU C Library is free software; you can redistribute it and/or
175 + modify it under the terms of the GNU Lesser General Public
176 + License as published by the Free Software Foundation; either
177 + version 2.1 of the License, or (at your option) any later version.
179 + The GNU C Library is distributed in the hope that it will be useful,
180 + but WITHOUT ANY WARRANTY; without even the implied warranty of
181 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
182 + Lesser General Public License for more details.
184 + You should have received a copy of the GNU Lesser General Public
185 + License along with the GNU C Library; if not, write to the Free
186 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
189 +#include <ldsodefs.h>
194 +_dl_var_init (void *array[])
196 + /* It has to match "variables" below. */
203 + GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
204 + GLRO(dl_clktck) = *((int *) array[DL_CLKTCK]);
208 +#include <bits/libc-lock.h>
210 +__libc_lock_define_initialized_recursive (static, _dl_static_lock)
212 +static void *variables[] =
214 + &GLRO(dl_pagesize),
219 +_dl_static_init (struct link_map *map)
221 + const ElfW(Sym) *ref = NULL;
223 + void (*f) (void *[]);
225 + __libc_lock_lock_recursive (_dl_static_lock);
227 + loadbase = _dl_lookup_symbol_x ("_dl_var_init", map, &ref,
228 + map->l_local_scope, NULL, 0, 1, NULL);
231 + f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
235 + __libc_lock_unlock_recursive (_dl_static_lock);
239 diff --git a/sysdeps/unix/sysv/linux/ia64/ldsodefs.h b/sysdeps/unix/sysv/linux/ia64/ldsodefs.h
240 deleted file mode 100644
241 index 31af624..0000000
242 --- a/sysdeps/unix/sysv/linux/ia64/ldsodefs.h
245 -/* Run-time dynamic linker data structures for loaded ELF shared objects. IA64.
246 - Copyright (C) 2001 Free Software Foundation, Inc.
247 - This file is part of the GNU C Library.
249 - The GNU C Library is free software; you can redistribute it and/or
250 - modify it under the terms of the GNU Lesser General Public
251 - License as published by the Free Software Foundation; either
252 - version 2.1 of the License, or (at your option) any later version.
254 - The GNU C Library is distributed in the hope that it will be useful,
255 - but WITHOUT ANY WARRANTY; without even the implied warranty of
256 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
257 - Lesser General Public License for more details.
259 - You should have received a copy of the GNU Lesser General Public
260 - License along with the GNU C Library; if not, write to the Free
261 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
266 -/* Get the real definitions. */
267 -#include_next <ldsodefs.h>
269 -/* Now define our stuff. */
271 -/* We need special support to initialize DSO loaded for statically linked
273 -extern void _dl_static_init (struct link_map *map);
274 -#undef DL_STATIC_INIT
275 -#define DL_STATIC_INIT(map) _dl_static_init (map)
277 -#endif /* ldsodefs.h */
278 diff --git a/sysdeps/unix/sysv/linux/ldsodefs.h b/sysdeps/unix/sysv/linux/ldsodefs.h
279 index 5d5b1b4..ecb5d4f 100644
280 --- a/sysdeps/unix/sysv/linux/ldsodefs.h
281 +++ b/sysdeps/unix/sysv/linux/ldsodefs.h
282 @@ -36,6 +36,12 @@ extern void _dl_aux_init (ElfW(auxv_t) *av) internal_function;
283 /* Initialization which is normally done by the dynamic linker. */
284 extern void _dl_non_dynamic_init (void) internal_function;
286 +/* We need special support to initialize DSO loaded for statically linked
288 +extern void _dl_static_init (struct link_map *map);
289 +#undef DL_STATIC_INIT
290 +#define DL_STATIC_INIT(map) _dl_static_init (map)
292 /* We can assume that the kernel always provides the AT_UID, AT_EUID,
293 AT_GID, and AT_EGID values in the auxiliary vector from 2.4.0 or so on. */
295 diff --git a/sysdeps/unix/sysv/linux/ia64/getpagesize.c b/sysdeps/unix/sysv/linux/ia64/getpagesize.c
296 deleted file mode 100644
297 index 1155dfd..0000000
298 --- a/sysdeps/unix/sysv/linux/ia64/getpagesize.c
301 -/* Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
302 - This file is part of the GNU C Library.
304 - The GNU C Library is free software; you can redistribute it and/or
305 - modify it under the terms of the GNU Lesser General Public
306 - License as published by the Free Software Foundation; either
307 - version 2.1 of the License, or (at your option) any later version.
309 - The GNU C Library is distributed in the hope that it will be useful,
310 - but WITHOUT ANY WARRANTY; without even the implied warranty of
311 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
312 - Lesser General Public License for more details.
314 - You should have received a copy of the GNU Lesser General Public
315 - License along with the GNU C Library; if not, write to the Free
316 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
321 -#include <sys/param.h>
323 -#include <ldsodefs.h>
325 -#include <sys/syscall.h>
327 -/* Return the system page size. The return value will depend on how
328 - the kernel is configured. A program must use this call to
329 - determine the page size to ensure proper alignment for calls such
330 - as mmap and friends. --davidm 99/11/30 */
335 - assert (GLRO(dl_pagesize) != 0);
336 - return GLRO(dl_pagesize);
338 -libc_hidden_def (__getpagesize)
339 -weak_alias (__getpagesize, getpagesize)