[PATCH] D73139: [LLD][COFF] Enable linking of __declspec(selectany) symbols from Clang and GCC
Markus Böck via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 13:47:04 PST 2020
zero9178 created this revision.
zero9178 added reviewers: ruiu, pcc.
Herald added subscribers: llvm-commits, mstorsjo.
Herald added a project: LLVM.
zero9178 edited the summary of this revision.
zero9178 edited the summary of this revision.
zero9178 edited the summary of this revision.
When annotating a symbol with declspec(selectany), Clang assigns it comdat 2 while GCC assigns it comdat 3. This patch enables two object files that contain a declspec(selectany) symbol, one created by gcc and the other by clang, to be linked together instead of issuing a duplicate symbol error.
Would need someone to commit this for me if accepted.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D73139
Files:
lld/COFF/InputFiles.cpp
Index: lld/COFF/InputFiles.cpp
===================================================================
--- lld/COFF/InputFiles.cpp
+++ lld/COFF/InputFiles.cpp
@@ -500,6 +500,17 @@
leaderSelection = selection = IMAGE_COMDAT_SELECT_LARGEST;
}
+ // GCCs __declspec(selectany) doesn't actually pick "any" but "same size as".
+ // Clang on the other hand picks "any". To be able to link two object files
+ // with a __declspec(selectany) declaration, one compiled with gcc and the other
+ // with clang, we merge them as proper "any"
+ if (config->mingw && ((selection == IMAGE_COMDAT_SELECT_ANY &&
+ leaderSelection == IMAGE_COMDAT_SELECT_SAME_SIZE) ||
+ (selection == IMAGE_COMDAT_SELECT_SAME_SIZE &&
+ leaderSelection == IMAGE_COMDAT_SELECT_ANY))) {
+ leaderSelection = selection = IMAGE_COMDAT_SELECT_ANY;
+ }
+
// Other than that, comdat selections must match. This is a bit more
// strict than link.exe which allows merging "any" and "largest" if "any"
// is the first symbol the linker sees, and it allows merging "largest"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73139.239424.patch
Type: text/x-patch
Size: 1122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200121/1a0a23da/attachment.bin>
More information about the llvm-commits
mailing list