...but now
H . J . Lu
hjl@valinux.com
Fri Jan 5 11:09:00 GMT 2001
On Fri, Jan 05, 2001 at 09:36:06AM -0800, Ulrich Drepper wrote:
> "H . J . Lu" <hjl@valinux.com> writes:
>
> > I have a second thought on the aux vector with static binaries.
> > Right now, non_dynamic_init is called from __libc_init_first
> > in libc-start.c. It is no way to know when non_dynamic_init will
> > be called.
>
> It's easy enough to add a direct call in __libc_start_main. No big
> code shuffling necessary.
>
> > If _dl_pagesize is not set before getpagesize is first
> > used, I don't think it will be good, especially on ia64. Also I think
> > _dl_important_hwcaps may be also useful for loading DSO from static
> > binaries.
>
> That's unimportant. Static applications depending on DSOs are
> questionable. Those depending on DSO in global constructors are
> plainly broken. Dynamic loading in static applications will never
> ever fully work, this cannot be used as an argument.
Ok. I removed AT_PLATFORM since it was not used at all.
>
> > BTW, non_dynamic_init is incorrect for PPC.
>
> This is not helpful.
>
Here is a patch to address those problems.
--
H.J. Lu (hjl@valinux.com)
---
2001-01-05 H.J. Lu <hjl@gnu.org>
* elf/dl-support.c (non_dynamic_init): Move the auxiliary
vector checking to ...
(_dl_aux_init): Here. New function. Defined only if
HAVE_AUX_VECTOR is defined.
* sysdeps/generic/libc-start.c (__libc_start_main): Call
_dl_aux_init for static binaries if HAVE_AUX_VECTOR is defined.
* sysdeps/powerpc/elf/libc-start.c (__libc_start_main): Call
_dl_aux_init.
* sysdeps/unix/sysv/linux/ldsodefs.h (DL_FIND_AUXV): Removed.
(HAVE_AUX_VECTOR): Defined.
(_dl_aux_init): Declared.
Index: elf/dl-support.c
===================================================================
RCS file: /work/cvs/gnu/glibc/elf/dl-support.c,v
retrieving revision 1.1.1.8
diff -u -p -r1.1.1.8 dl-support.c
--- elf/dl-support.c 2001/01/05 17:42:06 1.1.1.8
+++ elf/dl-support.c 2001/01/05 18:56:09
@@ -108,34 +108,31 @@ int _dl_starting_up = 1;
__libc_lock_define_initialized_recursive (, _dl_load_lock)
+#ifdef HAVE_AUX_VECTOR
extern int _dl_clktck;
-static void non_dynamic_init (int argc, char **argv, char **envp)
- __attribute__ ((unused));
-
-static void
-non_dynamic_init (int argc, char **argv, char **envp)
+void
+internal_function
+_dl_aux_init (ElfW(auxv_t) *av)
{
-#ifdef DL_FIND_AUXV
- ElfW(auxv_t) *av;
-
- DL_FIND_AUXV (av, envp);
-
for (; av->a_type != AT_NULL; ++av)
switch (av->a_type)
{
case AT_PAGESZ:
_dl_pagesize = av->a_un.a_val;
break;
- case AT_PLATFORM:
- _dl_platform = av->a_un.a_ptr;
- break;
case AT_CLKTCK:
_dl_clktck = av->a_un.a_val;
break;
}
+}
#endif
+static void non_dynamic_init (void) __attribute__ ((unused));
+
+static void
+non_dynamic_init (void)
+{
if (!_dl_pagesize)
_dl_pagesize = __getpagesize ();
Index: sysdeps/generic/libc-start.c
===================================================================
RCS file: /work/cvs/gnu/glibc/sysdeps/generic/libc-start.c,v
retrieving revision 1.1.1.6
diff -u -p -r1.1.1.6 libc-start.c
--- sysdeps/generic/libc-start.c 2000/11/21 02:15:43 1.1.1.6
+++ sysdeps/generic/libc-start.c 2001/01/05 18:47:47
@@ -59,6 +59,10 @@ BP_SYM (__libc_start_main) (int (*main)
#endif
#ifndef SHARED
+# ifdef HAVE_AUX_VECTOR
+ void *__unbounded *__unbounded auxvec;
+# endif
+
/* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
If the address would be taken inside the expression the optimizer
would try to be too smart and throws it away. Grrr. */
@@ -85,6 +89,13 @@ BP_SYM (__libc_start_main) (int (*main)
loader did the work already. */
if (__builtin_expect (__libc_enable_secure, 0))
__libc_check_standard_fds ();
+
+# ifdef HAVE_AUX_VECTOR
+ for (auxvec = (void *__unbounded *__unbounded) ubp_ev;
+ *auxvec; auxvec++);
+ ++auxvec;
+ _dl_aux_init ((ElfW(auxv_t) *) auxvec);
+# endif
#endif
/* Register the destructor of the dynamic linker if there is any. */
Index: sysdeps/powerpc/elf/libc-start.c
===================================================================
RCS file: /work/cvs/gnu/glibc/sysdeps/powerpc/elf/libc-start.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 libc-start.c
--- sysdeps/powerpc/elf/libc-start.c 2000/07/25 23:43:18 1.1.1.2
+++ sysdeps/powerpc/elf/libc-start.c 2001/01/05 18:36:54
@@ -76,6 +76,7 @@ BP_SYM (__libc_start_main) (int argc, ch
while (*(char *__unbounded *__unbounded) auxvec != NULL)
++auxvec;
++auxvec;
+ _dl_aux_init ((ElfW(auxv_t) *) auxvec);
rtld_fini = NULL;
}
Index: sysdeps/unix/sysv/linux/ldsodefs.h
===================================================================
RCS file: /work/cvs/gnu/glibc/sysdeps/unix/sysv/linux/ldsodefs.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 ldsodefs.h
--- sysdeps/unix/sysv/linux/ldsodefs.h 2001/01/05 17:43:41 1.1.1.1
+++ sysdeps/unix/sysv/linux/ldsodefs.h 2001/01/05 18:16:25
@@ -24,15 +24,10 @@
/* Now define our stuff. */
-/* Locating the auxiliary vector. */
-#ifndef DL_FIND_AUXV
-# define DL_FIND_AUXV(auxp, envp) \
- do { \
- void **_tmp; \
- for (_tmp = (void **) (envp); *_tmp; ++_tmp) \
- continue; \
- (auxp) = (void *) ++_tmp; \
- } while (0)
-#endif
+/* We have the auxiliary vector. */
+#define HAVE_AUX_VECTOR
+
+/* Used by static binaries to check the auxiliary vector. */
+extern void _dl_aux_init (ElfW(auxv_t) *av) internal_function;
#endif /* ldsodefs.h */
More information about the Libc-hacker
mailing list