This is an archive of the discontinued LLVM Phabricator instance.

tsan_interface.h: make constants static
ClosedPublic

Authored by cota on Mar 7 2020, 10:26 PM.

Details

Reviewers
dvyukov
Summary

Note that in C++ the static keyword is implicit for const objects.
In C however it is not, and we get clashes at link time after
including the header from more than one C file:

lib.a(bar.o):(.rodata+0x0): multiple definition of `__tsan_mutex_linker_init'
lib.a(foo.o):(.rodata+0x0): first defined here
lib.a(bar.o):(.rodata+0xc): multiple definition of `__tsan_mutex_not_static'
lib.a(foo.o):(.rodata+0xc): first defined here
<snip>

Indeed both foo.o and bar.o define the clashing symbols:

$ nm foo.o
<snip>
0000000000000000 R __tsan_mutex_linker_init
000000000000000c R __tsan_mutex_not_static
<snip>

Fix it by explicitly making the constants static.

Diff Detail

Event Timeline

cota created this revision.Mar 7 2020, 10:26 PM
Herald added subscribers: Restricted Project, llvm-commits. · View Herald TranscriptMar 7 2020, 10:26 PM
dvyukov accepted this revision.Mar 8 2020, 10:51 PM

Interesting difference between C and C++...
Do you want me to merge this as well? or you have commit access?
Thanks

This revision is now accepted and ready to land.Mar 8 2020, 10:51 PM
cota added a comment.Mar 9 2020, 9:57 AM

I have no commit access -- please merge it, thanks!