[PATCH] D22613: [Profile] deprecate __llvm_profile_override_default_filename (part-1)

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 11:11:01 PDT 2016


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:

$ echo "@x = weak global i32 42" > weak.ll
$ clang weak.ll -o weak.o

$ echo "extern int x;" > use_weak.c
$ echo "int main() { return x; }" >> use_weak.c

$ clang weak.o weak.o use_weak.c -o use_weak
$ otool -s __DATA __data use_weak
Contents of (__DATA,__data) section
0000000100001008        2a 00 00 00

It looks like there is just one copy of the symbol in the final binary.

I wonder why the comdat is needed on ELF, or whether my test is just wrong.

vedant

> On Jul 21, 2016, at 10:55 AM, Xinliang David Li <davidxl at google.com> wrote:
> 
> 
> 
> On Thu, Jul 21, 2016 at 10:52 AM, Vedant Kumar <vsk at apple.com> wrote:
> vsk added a comment.
> 
> Nice, just one concern.
> 
> 
> ================
> Comment at: lib/Transforms/Instrumentation/InstrProfiling.cpp:615
> @@ +614,3 @@
> +      ProfileNameVar->setComdat(M->getOrInsertComdat(
> +          StringRef(INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR))));
> +  }
> ----------------
> 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?
> 
> 
> 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).
> 
> David
> 
>  
> 
> https://reviews.llvm.org/D22613
> 
> 
> 
> 



More information about the llvm-commits mailing list