]> git.pld-linux.org Git - packages/glibc.git/blob - 0055_all_glibc-2.12-static-shared-getpagesize.patch
- rel 1; fixed typo - builds now; one new todo item
[packages/glibc.git] / 0055_all_glibc-2.12-static-shared-getpagesize.patch
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
4
5 a simple statically linked app fails with glibc-2.12:
6         $ cat test.c
7         main(){getpwnam("root");}
8         $ gcc -static test.c
9         $ ./a.out
10         a.out: ../sysdeps/unix/sysv/linux/getpagesize.c:32: __getpagesize:
11                 Assertion `_rtld_global_ro._dl_pagesize != 0' failed.
12         Aborted (core dumped)
13
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
22 field stays at 0.
23
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.
29
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
32 on __getpagesize().
33
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.
39
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.
43
44 2010-08-18  Mike Frysinger  <vapier@gentoo.org>
45
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.
55
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
62  endif
63  
64 -ifeq ($(subdir),elf)
65 -sysdep-dl-routines += dl-static
66 -sysdep_routines += $(sysdep-dl-routines)
67 -sysdep-rtld-routines += $(sysdep-dl-routines)
68 -endif
69 -
70  ifeq ($(subdir),rt)
71  librt-routines += rt-sysdep
72  endif
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 @@ -148,8 +148,10 @@
78  endif
79  
80  ifeq ($(subdir),elf)
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 \
84 -                       dl-fxstatat64
85 +                       dl-fxstatat64 dl-static
86  
87  CPPFLAGS-lddlibc4 += -DNOT_IN_libc
88  endif
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
93 +++ /dev/null
94 @@ -1,69 +0,0 @@
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.
98 -
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.
103 -
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.
108 -
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
112 -   02111-1307 USA.  */
113 -
114 -#include <ldsodefs.h>
115 -
116 -#ifdef SHARED
117 -
118 -void
119 -_dl_var_init (void *array[])
120 -{
121 -  /* It has to match "variables" below. */
122 -  enum
123 -    {
124 -      DL_PAGESIZE = 0,
125 -      DL_CLKTCK
126 -    };
127 -
128 -  GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
129 -  GLRO(dl_clktck) = *((int *) array[DL_CLKTCK]);
130 -}
131 -
132 -#else
133 -#include <bits/libc-lock.h>
134 -
135 -__libc_lock_define_initialized_recursive (static, _dl_static_lock)
136 -
137 -static void *variables[] =
138 -{
139 -  &GLRO(dl_pagesize),
140 -  &GLRO(dl_clktck)
141 -};
142 -
143 -void
144 -_dl_static_init (struct link_map *map)
145 -{
146 -  const ElfW(Sym) *ref = NULL;
147 -  lookup_t loadbase;
148 -  void (*f) (void *[]);
149 -
150 -  __libc_lock_lock_recursive (_dl_static_lock);
151 -
152 -  loadbase = _dl_lookup_symbol_x ("_dl_var_init", map, &ref,
153 -                                 map->l_local_scope, NULL, 0, 1, NULL);
154 -  if (ref != NULL)
155 -    {
156 -      f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
157 -      f (variables);
158 -    }
159 -
160 -  __libc_lock_unlock_recursive (_dl_static_lock);
161 -}
162 -
163 -#endif
164 diff --git a/sysdeps/unix/sysv/linux/dl-static.c b/sysdeps/unix/sysv/linux/dl-static.c
165 new file mode 100644
166 index 0000000..fa70811
167 --- /dev/null
168 +++ b/sysdeps/unix/sysv/linux/dl-static.c
169 @@ -0,0 +1,69 @@
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.
173 +
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.
178 +
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.
183 +
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
187 +   02111-1307 USA.  */
188 +
189 +#include <ldsodefs.h>
190 +
191 +#ifdef SHARED
192 +
193 +void
194 +_dl_var_init (void *array[])
195 +{
196 +  /* It has to match "variables" below. */
197 +  enum
198 +    {
199 +      DL_PAGESIZE = 0,
200 +      DL_CLKTCK
201 +    };
202 +
203 +  GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
204 +  GLRO(dl_clktck) = *((int *) array[DL_CLKTCK]);
205 +}
206 +
207 +#else
208 +#include <bits/libc-lock.h>
209 +
210 +__libc_lock_define_initialized_recursive (static, _dl_static_lock)
211 +
212 +static void *variables[] =
213 +{
214 +  &GLRO(dl_pagesize),
215 +  &GLRO(dl_clktck)
216 +};
217 +
218 +void
219 +_dl_static_init (struct link_map *map)
220 +{
221 +  const ElfW(Sym) *ref = NULL;
222 +  lookup_t loadbase;
223 +  void (*f) (void *[]);
224 +
225 +  __libc_lock_lock_recursive (_dl_static_lock);
226 +
227 +  loadbase = _dl_lookup_symbol_x ("_dl_var_init", map, &ref,
228 +                                 map->l_local_scope, NULL, 0, 1, NULL);
229 +  if (ref != NULL)
230 +    {
231 +      f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
232 +      f (variables);
233 +    }
234 +
235 +  __libc_lock_unlock_recursive (_dl_static_lock);
236 +}
237 +
238 +#endif
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
243 +++ /dev/null
244 @@ -1,33 +0,0 @@
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.
248 -
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.
253 -
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.
258 -
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
262 -   02111-1307 USA.  */
263 -
264 -#ifndef        _LDSODEFS_H
265 -
266 -/* Get the real definitions.  */
267 -#include_next <ldsodefs.h>
268 -
269 -/* Now define our stuff.  */
270 -
271 -/* We need special support to initialize DSO loaded for statically linked
272 -   binaries.  */
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)
276 -
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;
285  
286 +/* We need special support to initialize DSO loaded for statically linked
287 +   binaries.  */
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)
291 +
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.  */
294  #if __ASSUME_AT_XID
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
299 +++ /dev/null
300 @@ -1,39 +0,0 @@
301 -/* Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
302 -   This file is part of the GNU C Library.
303 -
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.
308 -
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.
313 -
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
317 -   02111-1307 USA.  */
318 -
319 -#include <assert.h>
320 -#include <unistd.h>
321 -#include <sys/param.h>
322 -
323 -#include <ldsodefs.h>
324 -#include <sysdep.h>
325 -#include <sys/syscall.h>
326 -
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 */
331 -
332 -int
333 -__getpagesize ()
334 -{
335 -  assert (GLRO(dl_pagesize) != 0);
336 -  return GLRO(dl_pagesize);
337 -}
338 -libc_hidden_def (__getpagesize)
339 -weak_alias (__getpagesize, getpagesize)
This page took 0.161836 seconds and 3 git commands to generate.