[ThinLTO] Respect ClearDSOLocalOnDeclarations for unimported functions
authorFangrui Song <i@maskray.me>
Sat, 3 Jul 2021 00:08:25 +0000 (17:08 -0700)
committerFangrui Song <i@maskray.me>
Sat, 3 Jul 2021 00:08:25 +0000 (17:08 -0700)
commit252a1eecc04080d852ba58c6727970c688eb1619
tree8d098ebec0f70387376722a7e26a129ad0447475
parent6b0d266036f73f5ee9556d211a7d0946091ff3b2
[ThinLTO] Respect ClearDSOLocalOnDeclarations for unimported functions

D74751 added `ClearDSOLocalOnDeclarations` and dropped dso_local for
isDeclarationForLinker `GlobalValue`s. It missed a case for imported
declarations (`doImportAsDefinition` is false while `isPerformingImport` is
true). This can lead to a linker error for a default visibility symbol in
`ld.lld -shared`.

When `ClearDSOLocalOnDeclarations` is true, we check
`isPerformingImport() && !doImportAsDefinition(&GV)` along with
`GV.isDeclarationForLinker()`. The new condition checks an imported declaration.

This patch fixes a `LLVMPolly.so` link error using a trunk clang -DLLVM_ENABLE_LTO=Thin.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D104986
llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
llvm/test/ThinLTO/X86/import-dsolocal.ll [new file with mode: 0644]
llvm/test/ThinLTO/X86/index-const-prop-linkage.ll