<div dir="ltr"><div>In our case, we'd prefer the opposite that is for <font face="monospace">__start</font>/<font face="monospace">__stop</font> symbols to be always hidden (which is something Rafael also pointed out in <a href="https://reviews.llvm.org/D44566#1041984">https://reviews.llvm.org/D44566#1041984</a>), currently this also requires a linker script on our side which is unfortunate. I have created a change <a href="https://reviews.llvm.org/D55682">https://reviews.llvm.org/D55682</a> to provide the <font face="monospace">-z hidden-start-stop-symbol</font> but this was rejected. I'm wondering if it'd make sense to extend that change to instead provide <font face="monospace">-z start-stop-symbol-visibility=</font> which could be used to override visibility for <font face="monospace">__start</font>/<font face="monospace">__stop</font> symbol (i.e. <font face="monospace">default</font> or <font face="monospace">hidden</font>) which would match the frontend <font face="monospace">-fvisibility=</font> flag. Would that be acceptable?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 2, 2020 at 10:05 AM Moshtaghi, Alireza via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Okay<br>
Thank you<br>
<br>
On 6/2/20, 8:37 AM, "Fangrui Song" <<a href="mailto:maskray@google.com" target="_blank">maskray@google.com</a>> wrote:<br>
<br>
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.<br>
<br>
<br>
<br>
<br>
On 2020-06-02, Moshtaghi, Alireza wrote:<br>
>Sorry for the cryptic code but I had to modify stuff from original<br>
>In the following example see the difference when you comment or uncomment the line in the linker script:<br>
>============ test.c ============= :<br>
>struct orphan_dummy_anno_s {<br>
> void (*func)(void);<br>
>};<br>
><br>
>static void dummy_export_dbg_log_init_f (void) __attribute__ ((unused));<br>
>static struct orphan_dummy_anno_s const<br>
> dummy_export_dbg_log_init_linker_set =<br>
> { dummy_export_dbg_log_init_f, };<br>
>__asm__ (".globl " "__start_set_orphan_dummy_anno");<br>
>__asm__ (".globl " "__stop_set_orphan_dummy_anno");<br>
>static void const<br>
> *__set_orphan_dummy_anno_sym_dummy_export_dbg_log_init_linker_set<br>
> __attribute__ ((__section__ ("set_" "orphan_dummy_anno")))<br>
> __attribute__ ((__used__)) = &dummy_export_dbg_log_init_linker_set;<br>
>============ linker_script ============= :<br>
>SECTIONS {<br>
> data : { *(data) }<br>
># when commented, the __start and __stop symbols will be protected. How can I keep it from setting it as protected?<br>
># set_orphan_dummy_anno : { PROVIDE(__start_set_orphan_dummy_anno = . ); *(set_orphan_dummy_anno) PROVIDE (__stop_set_orphan_dummy_anno = . );}<br>
>}<br>
>============ howto ============= :<br>
>LDFLAGS="-Bshareable -T ./linker_script"<br>
>clang -fPIC -c test.c<br>
>ld.lld $LDFLAGS test.o -o test.so<br>
>objdump -tT test.so<br>
<br>
Making __start_* __stop_* STV_PROTECTED is a deliberate choice. See<br>
<a href="https://reviews.llvm.org/D44566" rel="noreferrer" target="_blank">https://reviews.llvm.org/D44566</a><br>
Such symbols can still be exported to .dynsym (can be looked up from<br>
another shared object with dlopen) but prevent accidental symbol preemption..<br>
><br>
>On 6/2/20, 12:00 AM, "llvm-dev on behalf of Moshtaghi, Alireza via llvm-dev" <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a> on behalf of <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> 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.<br>
><br>
><br>
><br>
><br>
> You are right it creates them but sets the protected flag (STV_PROTECTED) which seems to be the cause of my problem.<br>
> How can I tell it to set the flag as STV_DEFAULT?<br>
><br>
> Thanks<br>
> A<br>
><br>
> On 5/28/20, 11:30 PM, "Fangrui Song" <<a href="mailto:maskray@google.com" target="_blank">maskray@google.com</a>> wrote:<br>
><br>
> 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.<br>
><br>
><br>
><br>
><br>
> On 2020-05-28, Moshtaghi, Alireza via llvm-dev wrote:<br>
> >lld does not seem to create the __start and __end symbols for orphan sections.<br>
> >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?<br>
> ><br>
> >Thanks<br>
> >A<br>
><br>
> It works for me.<br>
><br>
> SECTIONS {<br>
> data : { *(data) }<br>
> }<br>
><br>
> .section data,"aw"<br>
> .quad __start_orphan<br>
> .quad __stop_orphan<br>
><br>
> .section orphan,"aw"<br>
> .quad __start_data<br>
> .quad __stop_data<br>
><br>
><br>
> Can you give an example __start_ or __end_ symbols are not defined for orphan sections?<br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>