[llvm-dev] LLD : __start_ and __end_ symbols for orphan sections
Petr Hosek via llvm-dev
llvm-dev at lists.llvm.org
Tue Jun 2 12:59:44 PDT 2020
In our case, we'd prefer the opposite that is for __start/__stop symbols to
be always hidden (which is something Rafael also pointed out in
https://reviews.llvm.org/D44566#1041984), currently this also requires a
linker script on our side which is unfortunate. I have created a change
https://reviews.llvm.org/D55682 to provide the -z hidden-start-stop-symbol
but this was rejected. I'm wondering if it'd make sense to extend that
change to instead provide -z start-stop-symbol-visibility= which could be
used to override visibility for __start/__stop symbol (i.e. default or
hidden) which would match the frontend -fvisibility= flag. Would that be
acceptable?
On Tue, Jun 2, 2020 at 10:05 AM Moshtaghi, Alireza via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Okay
> Thank you
>
> On 6/2/20, 8:37 AM, "Fangrui Song" <maskray at google.com> wrote:
>
> NetApp Security WARNING: This is an external email. Do not click links
> or open attachments unless you recognize the sender and know the content is
> safe.
>
>
>
>
> On 2020-06-02, Moshtaghi, Alireza wrote:
> >Sorry for the cryptic code but I had to modify stuff from original
> >In the following example see the difference when you comment or
> uncomment the line in the linker script:
> >============ test.c ============= :
> >struct orphan_dummy_anno_s {
> > void (*func)(void);
> >};
> >
> >static void dummy_export_dbg_log_init_f (void) __attribute__
> ((unused));
> >static struct orphan_dummy_anno_s const
> > dummy_export_dbg_log_init_linker_set =
> > { dummy_export_dbg_log_init_f, };
> >__asm__ (".globl " "__start_set_orphan_dummy_anno");
> >__asm__ (".globl " "__stop_set_orphan_dummy_anno");
> >static void const
> > *__set_orphan_dummy_anno_sym_dummy_export_dbg_log_init_linker_set
> > __attribute__ ((__section__ ("set_" "orphan_dummy_anno")))
> > __attribute__ ((__used__)) = &dummy_export_dbg_log_init_linker_set;
> >============ linker_script ============= :
> >SECTIONS {
> > data : { *(data) }
> ># when commented, the __start and __stop symbols will be protected.
> How can I keep it from setting it as protected?
> ># set_orphan_dummy_anno : { PROVIDE(__start_set_orphan_dummy_anno =
> . ); *(set_orphan_dummy_anno) PROVIDE (__stop_set_orphan_dummy_anno = . );}
> >}
> >============ howto ============= :
> >LDFLAGS="-Bshareable -T ./linker_script"
> >clang -fPIC -c test.c
> >ld.lld $LDFLAGS test.o -o test.so
> >objdump -tT test.so
>
> Making __start_* __stop_* STV_PROTECTED is a deliberate choice. See
> https://reviews.llvm.org/D44566
> Such symbols can still be exported to .dynsym (can be looked up from
> another shared object with dlopen) but prevent accidental symbol
> preemption..
> >
> >On 6/2/20, 12:00 AM, "llvm-dev on behalf of Moshtaghi, Alireza via
> llvm-dev" <llvm-dev-bounces at lists.llvm.org on behalf of
> llvm-dev at lists.llvm.org> wrote:
> >
> > NetApp Security WARNING: This is an external email. Do not click
> links or open attachments unless you recognize the sender and know the
> content is safe.
> >
> >
> >
> >
> > You are right it creates them but sets the protected flag
> (STV_PROTECTED) which seems to be the cause of my problem.
> > How can I tell it to set the flag as STV_DEFAULT?
> >
> > Thanks
> > A
> >
> > On 5/28/20, 11:30 PM, "Fangrui Song" <maskray at google.com> wrote:
> >
> > NetApp Security WARNING: This is an external email. Do not
> click links or open attachments unless you recognize the sender and know
> the content is safe.
> >
> >
> >
> >
> > On 2020-05-28, Moshtaghi, Alireza via llvm-dev wrote:
> > >lld does not seem to create the __start and __end symbols
> for orphan sections.
> > >I would like to keep my linker script as generic as possible
> so how can I tell lld to create these symbols without having to add them in
> the linker script?
> > >
> > >Thanks
> > >A
> >
> > It works for me.
> >
> > SECTIONS {
> > data : { *(data) }
> > }
> >
> > .section data,"aw"
> > .quad __start_orphan
> > .quad __stop_orphan
> >
> > .section orphan,"aw"
> > .quad __start_data
> > .quad __stop_data
> >
> >
> > Can you give an example __start_ or __end_ symbols are not
> defined for orphan sections?
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > llvm-dev at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> >
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200602/f0d64073/attachment.html>
More information about the llvm-dev
mailing list