<div dir="ltr">There are some other factors that make the linker to keep the extra copies. If I remove the comdat setting, the size of clang instrumented binary's rodata size increases from 8,684,939 to 8,709,291 (with profile path 14 chars long) -- they are all from duplicated strings.<div><br></div><div>David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 21, 2016 at 11:11 AM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">That's interesting. It seems like it's enough to specify WeakAnyLinkage on Darwin to get the same behavior. Do you expect that to be the case? Here is the test I tried:<br>
<br>
$ echo "@x = weak global i32 42" > weak.ll<br>
$ clang weak.ll -o weak.o<br>
<br>
$ echo "extern int x;" > use_weak.c<br>
$ echo "int main() { return x; }" >> use_weak.c<br>
<br>
$ clang weak.o weak.o use_weak.c -o use_weak<br>
$ otool -s __DATA __data use_weak<br>
Contents of (__DATA,__data) section<br>
0000000100001008        2a 00 00 00<br>
<br>
It looks like there is just one copy of the symbol in the final binary.<br>
<br>
I wonder why the comdat is needed on ELF, or whether my test is just wrong.<br>
<span class="HOEnZb"><font color="#888888"><br>
vedant<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Jul 21, 2016, at 10:55 AM, Xinliang David Li <<a href="mailto:davidxl@google.com">davidxl@google.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Jul 21, 2016 at 10:52 AM, Vedant Kumar <<a href="mailto:vsk@apple.com">vsk@apple.com</a>> wrote:<br>
> vsk added a comment.<br>
><br>
> Nice, just one concern.<br>
><br>
><br>
> ================<br>
> Comment at: lib/Transforms/Instrumentation/InstrProfiling.cpp:615<br>
> @@ +614,3 @@<br>
> +      ProfileNameVar->setComdat(M->getOrInsertComdat(<br>
> +          StringRef(INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR))));<br>
> +  }<br>
> ----------------<br>
> What's the advantage of placing the file name var in a comdat if it already has weak linkage? Would some ELF tests break without this?<br>
><br>
><br>
> It won't break, but the final binary will contain more than one copies of the symbols which wastes space. With Comdat, there is only one copy in the final link. Note current behavior (with private linkage will also result in multiple copies which is fixed here).<br>
><br>
> David<br>
><br>
><br>
><br>
> <a href="https://reviews.llvm.org/D22613" rel="noreferrer" target="_blank">https://reviews.llvm.org/D22613</a><br>
><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div>