llvm.org GIT mirror llvm / ee711b5
X86: Form IMGREL relocations for LLVM Functions We supported forming IMGREL relocations from ConstantExprs involving __ImageBase if the minuend was a GlobalVariable. Extend this functionality to all GlobalObjects. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231456 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 5 years ago
2 changed file(s) with 12 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
9595 SubRHS->getPointerAddressSpace() != 0)
9696 return nullptr;
9797
98 // Both ptrtoint instructions must wrap global variables:
98 // Both ptrtoint instructions must wrap global objects:
9999 // - Only global variables are eligible for image relative relocations.
100 // - The subtrahend refers to the special symbol __ImageBase, a global.
101 const GlobalVariable *GVLHS =
102 dyn_cast(SubLHS->getPointerOperand());
103 const GlobalVariable *GVRHS =
104 dyn_cast(SubRHS->getPointerOperand());
105 if (!GVLHS || !GVRHS)
100 // - The subtrahend refers to the special symbol __ImageBase, a GlobalVariable.
101 const auto *GOLHS = dyn_cast(SubLHS->getPointerOperand());
102 const auto *GVRHS = dyn_cast(SubRHS->getPointerOperand());
103 if (!GOLHS || !GVRHS)
106104 return nullptr;
107105
108106 // We expect __ImageBase to be a global variable without a section, externally
115113 return nullptr;
116114
117115 // An image-relative, thread-local, symbol makes no sense.
118 if (GVLHS->isThreadLocal())
116 if (GOLHS->isThreadLocal())
119117 return nullptr;
120118
121 return MCSymbolRefExpr::Create(TM.getSymbol(GVLHS, Mang),
119 return MCSymbolRefExpr::Create(TM.getSymbol(GOLHS, Mang),
122120 MCSymbolRefExpr::VK_COFF_IMGREL32,
123121 getContext());
124122 }
33
44 ; X64: .quad "?x@@3HA"@IMGREL
55 @"\01?x@@3HA" = global i64 sub nsw (i64 ptrtoint (i64* @"\01?x@@3HA" to i64), i64 ptrtoint (i8* @__ImageBase to i64)), align 8
6
7 declare void @f()
8
9 ; X64: .quad f@IMGREL
10 @fp = global i64 sub nsw (i64 ptrtoint (void ()* @f to i64), i64 ptrtoint (i8* @__ImageBase to i64)), align 8