llvm.org GIT mirror llvm / 3343ddf
Merging r195477: ------------------------------------------------------------------------ r195477 | rafael | 2013-11-22 09:58:12 -0800 (Fri, 22 Nov 2013) | 13 lines Add a fixed version of r195470 back. The fix is simply to use CurI instead of I when handling aliases to avoid accessing a invalid iterator. original message: Convert linkonce* to weak* instead of strong. Also refactor the logic into a helper function. This is an important improve on mingw where the linker complains about mixed weak and strong symbols. Converting to weak ensures that the symbol is not dropped, but keeps in a comdat, making the linker happy. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@195603 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 5 years ago
2 changed file(s) with 43 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
1919 #include "llvm/Pass.h"
2020 #include
2121 using namespace llvm;
22
23 /// Make sure GV is visible from both modules. Delete is true if it is
24 /// being deleted from this module.
25 /// This also makes sure GV cannot be dropped so that references from
26 /// the split module remain valid.
27 static void makeVisible(GlobalValue &GV, bool Delete) {
28 bool Local = GV.hasLocalLinkage();
29 if (Local)
30 GV.setVisibility(GlobalValue::HiddenVisibility);
31
32 if (Local || Delete) {
33 GV.setLinkage(GlobalValue::ExternalLinkage);
34 return;
35 }
36
37 if (!GV.hasLinkOnceLinkage()) {
38 assert(!GV.isDiscardableIfUnused());
39 return;
40 }
41
42 // Map linkonce* to weak* so that llvm doesn't drop this GV.
43 switch(GV.getLinkage()) {
44 default:
45 llvm_unreachable("Unexpected linkage");
46 case GlobalValue::LinkOnceAnyLinkage:
47 GV.setLinkage(GlobalValue::WeakAnyLinkage);
48 return;
49 case GlobalValue::LinkOnceODRLinkage:
50 GV.setLinkage(GlobalValue::WeakODRLinkage);
51 return;
52 }
53 }
2254
2355 namespace {
2456 /// @brief A pass to extract specific functions and their dependencies.
5991 continue;
6092 }
6193
62 bool Local = I->isDiscardableIfUnused();
63 if (Local)
64 I->setVisibility(GlobalValue::HiddenVisibility);
65
66 if (Local || Delete)
67 I->setLinkage(GlobalValue::ExternalLinkage);
94 makeVisible(*I, Delete);
6895
6996 if (Delete)
7097 I->setInitializer(0);
79106 continue;
80107 }
81108
82 bool Local = I->isDiscardableIfUnused();
83 if (Local)
84 I->setVisibility(GlobalValue::HiddenVisibility);
85
86 if (Local || Delete)
87 I->setLinkage(GlobalValue::ExternalLinkage);
109 makeVisible(*I, Delete);
88110
89111 if (Delete)
90112 I->deleteBody();
96118 Module::alias_iterator CurI = I;
97119 ++I;
98120
99 if (CurI->isDiscardableIfUnused()) {
100 CurI->setVisibility(GlobalValue::HiddenVisibility);
101 CurI->setLinkage(GlobalValue::ExternalLinkage);
102 }
121 bool Delete = deleteStuff == (bool)Named.count(CurI);
122 makeVisible(*CurI, Delete);
103123
104 if (deleteStuff == (bool)Named.count(CurI)) {
124 if (Delete) {
105125 Type *Ty = CurI->getType()->getElementType();
106126
107127 CurI->removeFromParent();
0 ; RUN: llvm-extract -func foo -S < %s | FileCheck %s
11 ; RUN: llvm-extract -delete -func foo -S < %s | FileCheck --check-prefix=DELETE %s
22
3 ; Test that we don't convert weak_odr to external definitions.
3 ; Test that linkonce definitions are mapped to weak so that they are not
4 ; dropped.
45
5 ; CHECK: @bar = external hidden global i32
6 ; CHECK: define hidden i32* @foo() {
6 ; CHECK: @bar = external global i32
7 ; CHECK: define weak i32* @foo() {
78 ; CHECK-NEXT: ret i32* @bar
89 ; CHECK-NEXT: }
910
10 ; DELETE: @bar = hidden global i32 42
11 ; DELETE: declare hidden i32* @foo()
11 ; DELETE: @bar = weak global i32 42
12 ; DELETE: declare i32* @foo()
1213
1314 @bar = linkonce global i32 42
1415