<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">   </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">  </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">  </span>55                   <span style="white-space:pre">      </span>push   %rbp</font></div><div><font face="monospace, monospace">     1:<span style="white-space:pre">        </span>48 89 e5             <span style="white-space:pre"> </span>mov    %rsp,%rbp</font></div><div><font face="monospace, monospace">     4:<span style="white-space:pre">   </span>31 c0                <span style="white-space:pre">        </span>xor    %eax,%eax</font></div><div><font face="monospace, monospace">     6:<span style="white-space:pre">   </span>5d                   <span style="white-space:pre">      </span>pop    %rbp</font></div><div><font face="monospace, monospace">     7:<span style="white-space:pre">        </span>c3                   <span style="white-space:pre">      </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>