[PATCH v2] Place ENTRY_POINT in .text.unlikely section [BZ #28153]

Florian Weimer fweimer@redhat.com
Sat Jul 31 17:11:01 GMT 2021


* H. J. Lu:

> On Sat, Jul 31, 2021 at 9:36 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu via Libc-alpha:
>>
>> > diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S
>> > index 417da8802b..e46e01ed0b 100644
>> > --- a/sysdeps/aarch64/start.S
>> > +++ b/sysdeps/aarch64/start.S
>> > @@ -42,7 +42,7 @@
>> >                                       NULL
>> >   */
>> >
>> > -     .text
>> > +     .section .text.unlikely,"ax",%progbits
>> >  ENTRY(_start)
>> >       /* Create an initial frame with 0 LR and FP */
>> >       cfi_undefined (x30)
>>
>> I don't think it's correct to place code that runs during every process
>> start into .text.unlikely.  Surely we can avoid that page fault.
>>
>> Can we fix the ENTRY_POINT assumption in profiling instead?
>
> We can do
>
> diff --git a/csu/gmon-start.c b/csu/gmon-start.c
> index b3432885b3..83322fd586 100644
> --- a/csu/gmon-start.c
> +++ b/csu/gmon-start.c
> @@ -48,7 +48,7 @@
>  #ifdef ENTRY_POINT_DECL
>  ENTRY_POINT_DECL(extern)
>  #else
> -extern char ENTRY_POINT[];
> +extern char entry_point[] asm (__SYMBOL_PREFIX "main");
>  #endif
>  extern char etext[];
>
> @@ -56,7 +56,7 @@ extern char etext[];
>  # ifdef ENTRY_POINT_DECL
>  #  define TEXT_START ENTRY_POINT
>  # else
> -#  define TEXT_START &ENTRY_POINT
> +#  define TEXT_START &entry_point
>  # endif
>  #endif
>
> But this may only work with BFD linker which places .text.startup
> section before .text section.

Can we get the linker to emit a symbol at the start of the text section?
Like it does for orphan sections?

Then we can use a weak symbol reference in gmon-start.c and use the new
symbol if it is available.

Thanks,
Florian



More information about the Libc-alpha mailing list