diff options
author | Fangrui Song <i@maskray.me> | 2022-11-16 21:43:50 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2022-11-16 21:43:50 -0800 |
commit | 2c239da6913dc7cb0710577c8e6b8e71cc1833c6 (patch) | |
tree | 8084edcac9d38fdd24f2b2761754147d89066622 /llvm/lib/LTO/LTO.cpp | |
parent | bbe6bd724a6335e497c7edaed191d37a828d0390 (diff) | |
download | llvm-2c239da6913dc7cb0710577c8e6b8e71cc1833c6.zip llvm-2c239da6913dc7cb0710577c8e6b8e71cc1833c6.tar.gz llvm-2c239da6913dc7cb0710577c8e6b8e71cc1833c6.tar.bz2 |
Revert D135427 "[LTO] Make local linkage GlobalValue in non-prevailing COMDAT available_externally"
This reverts commit 8901635423cbea4324059a5127657126d2e00ce1.
This change broke the following example and we need to check `if (GO->getComdat()->getName() == GO->getName())`
before `NonPrevailingComdats.insert(GO->getComdat());`
Revert for clarify.
```
// a.cc
template <typename T>
struct A final { virtual ~A() {} };
extern "C" void aa() { A<int> a; }
// b.cc
template <typename T>
struct A final { virtual ~A() {} };
template struct A<int>;
extern "C" void bb(A<int> *a) { delete a; }
clang -c -fpic -O0 -flto=thin a.cc && ld.lld -shared a.o b.o
```
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 9bfbabc..d3f29a6 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -712,11 +712,11 @@ handleNonPrevailingComdat(GlobalValue &GV, if (!NonPrevailingComdats.count(C)) return; - // Additionally need to drop all global values from the comdat to - // available_externally, to satisfy the COMDAT requirement that all members - // are discarded as a unit. The non-local linkage global values avoid - // duplicate definition linker errors. - GV.setLinkage(GlobalValue::AvailableExternallyLinkage); + // Additionally need to drop externally visible global values from the comdat + // to available_externally, so that there aren't multiply defined linker + // errors. + if (!GV.hasLocalLinkage()) + GV.setLinkage(GlobalValue::AvailableExternallyLinkage); if (auto GO = dyn_cast<GlobalObject>(&GV)) GO->setComdat(nullptr); |