llvm.org GIT mirror llvm / ce0afe6
[ThinLTO] Remove imported available externally defs from comdats. Summary: Available externally definitions are considered declarations for the linker and eventually dropped. As such they are not allowed to be in comdats. Remove any such imported functions from comdats. Reviewers: rafael Subscribers: davidxl, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D16120 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260122 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 4 years ago
3 changed file(s) with 47 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
721721 GV.setVisibility(GlobalValue::HiddenVisibility);
722722 if (isModuleExporting())
723723 NewExportedValues.insert(&GV);
724 return;
725 }
726 GV.setLinkage(getLinkage(&GV));
724 } else
725 GV.setLinkage(getLinkage(&GV));
726
727 // Remove functions imported as available externally defs from comdats,
728 // as this is a declaration for the linker, and will be dropped eventually.
729 // It is illegal for comdats to contain declarations.
730 auto *GO = dyn_cast_or_null(&GV);
731 if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
732 // The IRMover should not have placed any imported declarations in
733 // a comdat, so the only declaration that should be in a comdat
734 // at this point would be a definition imported as available_externally.
735 assert(GO->hasAvailableExternallyLinkage() &&
736 "Expected comdat on definition (possibly available external)");
737 GO->setComdat(nullptr);
738 }
727739 }
728740
729741 void ThinLTOGlobalProcessing::processGlobalsForThinLTO() {
0 define i32 @main() #0 {
1 entry:
2 ret i32 0
3 }
0 ; Do setup work for all below tests: generate bitcode and combined index
1 ; RUN: llvm-as -function-summary %s -o %t.bc
2 ; RUN: llvm-as -function-summary %p/Inputs/funcimport_comdat.ll -o %t2.bc
3 ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
4
5 ; Ensure linking of comdat containing external linkage global and function
6 ; removes the imported available_externally defs from comdat.
7 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=comdat1_func1:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMDAT
8 ; IMPORTCOMDAT-NOT: $comdat1 = comdat any
9 ; IMPORTCOMDAT-NOT: comdat($comdat1)
10
11 ; Ensure linking of comdat containing internal linkage function with alias
12 ; removes the imported and promoted available_externally defs from comdat.
13 ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=comdat2_func1:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMDAT2
14 ; IMPORTCOMDAT2-NOT: $comdat2 = comdat any
15 ; IMPORTCOMDAT2-NOT: comdat($comdat2)
16
17 $comdat1 = comdat any
18 @comdat1_glob = global i32 0, comdat($comdat1)
19 define void @comdat1_func1() comdat($comdat1) {
20 ret void
21 }
22
23 $comdat2 = comdat any
24 @comdat2_alias = alias void (), void ()* @comdat2_func1
25 define internal void @comdat2_func1() comdat($comdat2) {
26 ret void
27 }