<div dir="ltr">This may be a gold bug. I know that there was a bug in some versions of gold that caused the wrong symbol binding and/or visibility to appear in the output file. This bug also ended up manifesting as gold plugin test failures. Does the problem go away if you use a very recent (git master) version of gold?<div><br></div><div>Peter</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Sep 27, 2018 at 3:28 PM Bill Wendling <<a href="mailto:isanbard@gmail.com">isanbard@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">It appears as if the gold linker doesn't resolve weak functions to the strong definition with regular LTO (ThinLTO seems to work).<div><br></div><div>weak.c:</div><div><div><font face="monospace, monospace">#define __init __attribute__ ((__section__(".init.text")))</font></div><div><font face="monospace, monospace">#define __weak __attribute__ ((weak))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">int __init __weak early_irq_init(void)<br></font></div><div><font face="monospace, monospace">{</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">       </span>return 0;</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>strong.c:</div><div><div><font face="monospace, monospace">#define __init __attribute__ ((__section__(".init.text")))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">extern int arch_early_irq_init(void);</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">int __init early_irq_init(void)</font></div><div><font face="monospace, monospace">{</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">     </span>return arch_early_irq_init();</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>Compiled like so:</div><div><br></div><div><font face="monospace, monospace">  clang -flto -c weak.c<br></font></div><div><font face="monospace, monospace">  clang -flto -c strong.c</font><br></div><div><br></div><div>Linked:</div><div><br></div><div><font face="monospace, monospace">  ld.gold -plugin llvm-r337625.install/lib/LLVMgold.so -r -o bad.o weak.o strong.o</font></div><div><br></div><div>The resulting object file has a weak reference to "early_irq_init":</div><div><br></div><div><div><font face="monospace, monospace">  $ nm bad.o</font></div><div><font face="monospace, monospace">  0000000000000000 W early_irq_init</font></div></div><div><font face="monospace, monospace">  $ objdump -d bad.o<br></font></div><div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">  bad.o:     file format elf64-x86-64</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">  Disassembly of section .init.text:</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">  0000000000000000 <early_irq_init>:</font></div><div><font face="monospace, monospace">     0:<span style="white-space:pre-wrap">     </span>55                   <span style="white-space:pre-wrap"> </span>push   %rbp</font></div><div><font face="monospace, monospace">     1:<span style="white-space:pre-wrap">   </span>48 89 e5             <span style="white-space:pre-wrap">    </span>mov    %rsp,%rbp</font></div><div><font face="monospace, monospace">     4:<span style="white-space:pre-wrap">      </span>31 c0                <span style="white-space:pre-wrap">   </span>xor    %eax,%eax</font></div><div><font face="monospace, monospace">     6:<span style="white-space:pre-wrap">      </span>5d                   <span style="white-space:pre-wrap"> </span>pop    %rbp</font></div><div><font face="monospace, monospace">     7:<span style="white-space:pre-wrap">   </span>c3                   <span style="white-space:pre-wrap"> </span>retq</font></div></div><div><br></div><div>I've been combing through the gold linker code, but I haven't found the correct set of attributes to get it to work. Note that if I change the weak symbol to a symbol *reference* then everything links correctly.</div><div><br></div><div>-bw</div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>