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
77 @@ -147,8 +147,10 @@ sysdep_routines += xstatconv internal_statvfs internal_statvfs64 \
81 -sysdep-rtld-routines += dl-brk dl-sbrk dl-getcwd dl-openat64 dl-opendir \
83 +sysdep-dl-routines += dl-static
84 +sysdep_routines += dl-static
85 +sysdep-rtld-routines += dl-brk dl-sbrk dl-getcwd dl-openat64 dl-opendir \
86 + dl-fxstatat64 dl-static
88 CPPFLAGS-lddlibc4 += -DNOT_IN_libc
90 diff --git a/sysdeps/unix/sysv/linux/ia64/dl-static.c b/sysdeps/unix/sysv/linux/ia64/dl-static.c
91 deleted file mode 100644
92 index 4efc077..0000000
93 --- a/sysdeps/unix/sysv/linux/ia64/dl-static.c
96 -/* Variable initialization. IA-64 version.
97 - Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
98 - This file is part of the GNU C Library.
100 - The GNU C Library is free software; you can redistribute it and/or
101 - modify it under the terms of the GNU Lesser General Public
102 - License as published by the Free Software Foundation; either
103 - version 2.1 of the License, or (at your option) any later version.
105 - The GNU C Library is distributed in the hope that it will be useful,
106 - but WITHOUT ANY WARRANTY; without even the implied warranty of
107 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
108 - Lesser General Public License for more details.
110 - You should have received a copy of the GNU Lesser General Public
111 - License along with the GNU C Library; if not, write to the Free
112 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
115 -#include <ldsodefs.h>
120 -_dl_var_init (void *array[])
122 - /* It has to match "variables" below. */
129 - GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
130 - GLRO(dl_clktck) = *((int *) array[DL_CLKTCK]);
134 -#include <bits/libc-lock.h>
136 -__libc_lock_define_initialized_recursive (static, _dl_static_lock)
138 -static void *variables[] =
140 - &GLRO(dl_pagesize),
145 -_dl_static_init (struct link_map *map)
147 - const ElfW(Sym) *ref = NULL;
149 - void (*f) (void *[]);
151 - __libc_lock_lock_recursive (_dl_static_lock);
153 - loadbase = _dl_lookup_symbol_x ("_dl_var_init", map, &ref,
154 - map->l_local_scope, NULL, 0, 1, NULL);
157 - f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
161 - __libc_lock_unlock_recursive (_dl_static_lock);
165 diff --git a/sysdeps/unix/sysv/linux/dl-static.c b/sysdeps/unix/sysv/linux/dl-static.c
167 index 0000000..fa70811
169 +++ b/sysdeps/unix/sysv/linux/dl-static.c
171 +/* Variable initialization.
172 + Copyright (C) 2001, 2002, 2003, 2004, 2010 Free Software Foundation, Inc.
173 + This file is part of the GNU C Library.
175 + The GNU C Library is free software; you can redistribute it and/or
176 + modify it under the terms of the GNU Lesser General Public
177 + License as published by the Free Software Foundation; either
178 + version 2.1 of the License, or (at your option) any later version.
180 + The GNU C Library is distributed in the hope that it will be useful,
181 + but WITHOUT ANY WARRANTY; without even the implied warranty of
182 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
183 + Lesser General Public License for more details.
185 + You should have received a copy of the GNU Lesser General Public
186 + License along with the GNU C Library; if not, write to the Free
187 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
190 +#include <ldsodefs.h>
195 +_dl_var_init (void *array[])
197 + /* It has to match "variables" below. */
204 + GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
205 + GLRO(dl_clktck) = *((int *) array[DL_CLKTCK]);
209 +#include <bits/libc-lock.h>
211 +__libc_lock_define_initialized_recursive (static, _dl_static_lock)
213 +static void *variables[] =
215 + &GLRO(dl_pagesize),
220 +_dl_static_init (struct link_map *map)
222 + const ElfW(Sym) *ref = NULL;
224 + void (*f) (void *[]);
226 + __libc_lock_lock_recursive (_dl_static_lock);
228 + loadbase = _dl_lookup_symbol_x ("_dl_var_init", map, &ref,
229 + map->l_local_scope, NULL, 0, 1, NULL);
232 + f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
236 + __libc_lock_unlock_recursive (_dl_static_lock);
240 diff --git a/sysdeps/unix/sysv/linux/ia64/ldsodefs.h b/sysdeps/unix/sysv/linux/ia64/ldsodefs.h
241 deleted file mode 100644
242 index 31af624..0000000
243 --- a/sysdeps/unix/sysv/linux/ia64/ldsodefs.h
246 -/* Run-time dynamic linker data structures for loaded ELF shared objects. IA64.
247 - Copyright (C) 2001 Free Software Foundation, Inc.
248 - This file is part of the GNU C Library.
250 - The GNU C Library is free software; you can redistribute it and/or
251 - modify it under the terms of the GNU Lesser General Public
252 - License as published by the Free Software Foundation; either
253 - version 2.1 of the License, or (at your option) any later version.
255 - The GNU C Library is distributed in the hope that it will be useful,
256 - but WITHOUT ANY WARRANTY; without even the implied warranty of
257 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
258 - Lesser General Public License for more details.
260 - You should have received a copy of the GNU Lesser General Public
261 - License along with the GNU C Library; if not, write to the Free
262 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
267 -/* Get the real definitions. */
268 -#include_next <ldsodefs.h>
270 -/* Now define our stuff. */
272 -/* We need special support to initialize DSO loaded for statically linked
274 -extern void _dl_static_init (struct link_map *map);
275 -#undef DL_STATIC_INIT
276 -#define DL_STATIC_INIT(map) _dl_static_init (map)
278 -#endif /* ldsodefs.h */
279 diff --git a/sysdeps/unix/sysv/linux/ldsodefs.h b/sysdeps/unix/sysv/linux/ldsodefs.h
280 index 5d5b1b4..ecb5d4f 100644
281 --- a/sysdeps/unix/sysv/linux/ldsodefs.h
282 +++ b/sysdeps/unix/sysv/linux/ldsodefs.h
283 @@ -36,6 +36,12 @@ extern void _dl_aux_init (ElfW(auxv_t) *av) internal_function;
284 /* Initialization which is normally done by the dynamic linker. */
285 extern void _dl_non_dynamic_init (void) internal_function;
287 +/* We need special support to initialize DSO loaded for statically linked
289 +extern void _dl_static_init (struct link_map *map);
290 +#undef DL_STATIC_INIT
291 +#define DL_STATIC_INIT(map) _dl_static_init (map)
293 /* We can assume that the kernel always provides the AT_UID, AT_EUID,
294 AT_GID, and AT_EGID values in the auxiliary vector from 2.4.0 or so on. */
296 diff --git a/sysdeps/unix/sysv/linux/ia64/getpagesize.c b/sysdeps/unix/sysv/linux/ia64/getpagesize.c
297 deleted file mode 100644
298 index 1155dfd..0000000
299 --- a/sysdeps/unix/sysv/linux/ia64/getpagesize.c
302 -/* Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
303 - This file is part of the GNU C Library.
305 - The GNU C Library is free software; you can redistribute it and/or
306 - modify it under the terms of the GNU Lesser General Public
307 - License as published by the Free Software Foundation; either
308 - version 2.1 of the License, or (at your option) any later version.
310 - The GNU C Library is distributed in the hope that it will be useful,
311 - but WITHOUT ANY WARRANTY; without even the implied warranty of
312 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
313 - Lesser General Public License for more details.
315 - You should have received a copy of the GNU Lesser General Public
316 - License along with the GNU C Library; if not, write to the Free
317 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
322 -#include <sys/param.h>
324 -#include <ldsodefs.h>
326 -#include <sys/syscall.h>
328 -/* Return the system page size. The return value will depend on how
329 - the kernel is configured. A program must use this call to
330 - determine the page size to ensure proper alignment for calls such
331 - as mmap and friends. --davidm 99/11/30 */
336 - assert (GLRO(dl_pagesize) != 0);
337 - return GLRO(dl_pagesize);
339 -libc_hidden_def (__getpagesize)
340 -weak_alias (__getpagesize, getpagesize)