<div dir="ltr">I don't know whether or not it's intended, but it seems like a subtle but unnecessary incompatibility. I'd vote for making it compatible with GNU unless there's a real reason to not do so.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 8, 2014 at 3:22 PM, Simon Atanasyan <span dir="ltr"><<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
The LLD linker in gnu flavor mode accepts multiple -init/-fini command<br>
line options. For _all_ symbols specified by these options the linker<br>
creates appropriate entries in the .init_array/.fini_array sections.<br>
But it looks like LD and Gold linkers do not support this feature and<br>
take in account only the last -init/-fini options.<br>
<br>
% cat foo.c<br>
int a = 0;<br>
void foo() { a += 1; }<br>
void bar() { a += 2; }<br>
<br>
% cat main.c<br>
extern int a;<br>
int printf(const char *, ...);<br>
int main() { printf("a: %d\n", a); }<br>
<br>
% gcc -fPIC -shared -o libfoo.so -Wl,-init,foo -Wl,-init,bar foo.c<br>
% gcc main.c -L. -lfoo -Wl,-rpath,.<br>
% ./a.out<br>
2<br>
<br>
% gcc -fPIC -shared -o libfoo.so -Wl,-init,bar -Wl,-init,foo foo.c<br>
% ./a.out<br>
1<br>
<br>
What is the reason of this incompatibility? The question is caused by<br>
attempt to support DT_INIT/DT_FINI dynamic table tags. The table can<br>
contain no more than one DT_INIT/DT_FINI tags. The LD and Gold linker<br>
look up either default symbols (_init/_fini) or symbols specified by<br>
the -init/-fini options and put their values to the tags.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Simon Atanasyan<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</font></span></blockquote></div><br></div>