diff mbox series

[v5,4/7] csu: Avoid weak ref for __ehdr_start in static PIE

Message ID 4da71cb981057048e8cf9dec8731ad936b433e38.1611155254.git.szabolcs.nagy@arm.com
State Committed
Commit 04af1eb3132904519f9bc8fdcca49525bec83fc7
Headers show
Series fix ifunc with static pie [BZ #27072] | expand

Commit Message

Szabolcs Nagy Jan. 20, 2021, 3:31 p.m. UTC
All linkers support __ehdr_start that support static PIE linking,
so there is no need to check for its presence via a weak reference.

This avoids a RELATIVE relocation in static PIE startup code on some
targets.

With non-PIE static linking the weak ref check is kept in case the
linker does not support __ehdr_start.
---
 csu/libc-start.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

H.J. Lu Jan. 20, 2021, 3:36 p.m. UTC | #1
On Wed, Jan 20, 2021 at 7:34 AM Szabolcs Nagy via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> All linkers support __ehdr_start that support static PIE linking,
> so there is no need to check for its presence via a weak reference.
>
> This avoids a RELATIVE relocation in static PIE startup code on some
> targets.
>
> With non-PIE static linking the weak ref check is kept in case the
> linker does not support __ehdr_start.
> ---
>  csu/libc-start.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/csu/libc-start.c b/csu/libc-start.c
> index db859c3bed..5b9ce1d158 100644
> --- a/csu/libc-start.c
> +++ b/csu/libc-start.c
> @@ -175,8 +175,12 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
>           information from auxv.  */
>
>        extern const ElfW(Ehdr) __ehdr_start
> +# if BUILD_PIE_DEFAULT
> +       __attribute__ ((visibility ("hidden")));
> +# else
>         __attribute__ ((weak, visibility ("hidden")));
>        if (&__ehdr_start != NULL)
> +# endif
>          {
>            assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
>            GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
> --
> 2.17.1
>

LGTM.  Please wait for Adhemerval approval.
Adhemerval Zanella Jan. 21, 2021, 2:01 p.m. UTC | #2
On 20/01/2021 12:31, Szabolcs Nagy via Libc-alpha wrote:
> All linkers support __ehdr_start that support static PIE linking,
> so there is no need to check for its presence via a weak reference.
> 
> This avoids a RELATIVE relocation in static PIE startup code on some
> targets.
> 
> With non-PIE static linking the weak ref check is kept in case the
> linker does not support __ehdr_start.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  csu/libc-start.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/csu/libc-start.c b/csu/libc-start.c
> index db859c3bed..5b9ce1d158 100644
> --- a/csu/libc-start.c
> +++ b/csu/libc-start.c
> @@ -175,8 +175,12 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
>           information from auxv.  */
>  
>        extern const ElfW(Ehdr) __ehdr_start
> +# if BUILD_PIE_DEFAULT
> +	__attribute__ ((visibility ("hidden")));
> +# else
>  	__attribute__ ((weak, visibility ("hidden")));
>        if (&__ehdr_start != NULL)
> +# endif
>          {
>            assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
>            GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
>
diff mbox series

Patch

diff --git a/csu/libc-start.c b/csu/libc-start.c
index db859c3bed..5b9ce1d158 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -175,8 +175,12 @@  LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
          information from auxv.  */
 
       extern const ElfW(Ehdr) __ehdr_start
+# if BUILD_PIE_DEFAULT
+	__attribute__ ((visibility ("hidden")));
+# else
 	__attribute__ ((weak, visibility ("hidden")));
       if (&__ehdr_start != NULL)
+# endif
         {
           assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
           GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;