summaryrefslogtreecommitdiffstats
path: root/lld/COFF/InputFiles.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/COFF/InputFiles.cpp')
-rw-r--r--lld/COFF/InputFiles.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index d884201ba31..272f9c0717c 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -500,6 +500,17 @@ void ObjFile::handleComdatSelection(COFFSymbolRef sym, COMDATType &selection,
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 "same size as"
+ 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_SAME_SIZE;
+ }
+
// 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"
OpenPOWER on IntegriCloud