Message ID | 20220228064052.3413334-4-amodra@gmail.com |
---|---|
State | New |
Headers | show |
Series | PowerPC64 static-pie | expand |
Alan Modra via Libc-alpha <libc-alpha@sourceware.org> writes: > diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-start.c b/sysdeps/unix/sysv/linux/powerpc/libc-start.c > index bb97d16145..8f0d3a0eac 100644 > --- a/sysdeps/unix/sysv/linux/powerpc/libc-start.c > +++ b/sysdeps/unix/sysv/linux/powerpc/libc-start.c > @@ -23,6 +23,10 @@ > #ifndef SHARED > #include <hwcapinfo.h> > #endif > +#if ENABLE_STATIC_PIE && !defined SHARED > +/* For elf_machine_load_address. */ > +#include <dl-machine.h> > +#endif > > /* The main work is done in the generic function. */ > #define LIBC_START_MAIN generic_start_main > @@ -95,8 +99,15 @@ __libc_start_main_impl (int argc, char **argv, > __tcb_parse_hwcap_and_convert_at_platform (); > #endif > > - return generic_start_main (stinfo->main, argc, argv, auxvec, > - stinfo->init, stinfo->fini, rtld_fini, > + void *main = stinfo->main; Some GCC versions (e.g. GCC 8) complain about the name of this variable: ../sysdeps/unix/sysv/linux/powerpc/libc-start.c: In function ‘__libc_start_main_impl’: ../sysdeps/unix/sysv/linux/powerpc/libc-start.c:102:9: error: ‘main’ is usually a function [-Werror=main] Looks good to me if this variable is either renamed or if this part of the code is built with -Wno-main. Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile index fc7c29c695..93783cae00 100644 --- a/sysdeps/unix/sysv/linux/powerpc/Makefile +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile @@ -27,3 +27,9 @@ tests += $(tests-static) tests += test-gettimebasefreq tests += test-powerpc-linux-sysconf endif + +ifeq ($(subdir),csu) +# to relocate stinfo->main +CPPFLAGS-libc-start.o += -I../elf +CPPFLAGS-libc-start.op += -I../elf +endif diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-start.c b/sysdeps/unix/sysv/linux/powerpc/libc-start.c index bb97d16145..8f0d3a0eac 100644 --- a/sysdeps/unix/sysv/linux/powerpc/libc-start.c +++ b/sysdeps/unix/sysv/linux/powerpc/libc-start.c @@ -23,6 +23,10 @@ #ifndef SHARED #include <hwcapinfo.h> #endif +#if ENABLE_STATIC_PIE && !defined SHARED +/* For elf_machine_load_address. */ +#include <dl-machine.h> +#endif /* The main work is done in the generic function. */ #define LIBC_START_MAIN generic_start_main @@ -95,8 +99,15 @@ __libc_start_main_impl (int argc, char **argv, __tcb_parse_hwcap_and_convert_at_platform (); #endif - return generic_start_main (stinfo->main, argc, argv, auxvec, - stinfo->init, stinfo->fini, rtld_fini, + void *main = stinfo->main; +#if ENABLE_STATIC_PIE && !defined SHARED + struct link_map *map = _dl_get_dl_main_map (); + if (!map->l_relocated) + main = (char *) main + elf_machine_load_address (); +#endif + + return generic_start_main (main, argc, argv, auxvec, + NULL, NULL, rtld_fini, stack_on_entry); } DEFINE_LIBC_START_MAIN_VERSION