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
This commit is contained in:
David Majnemer
2015-03-06 08:11:32 +00:00
parent 02dc4fa6b2
commit ee711b5b16
2 changed files with 12 additions and 9 deletions

View File

@@ -96,14 +96,12 @@ const MCExpr *X86WindowsTargetObjectFile::getExecutableRelativeSymbol(
SubRHS->getPointerAddressSpace() != 0)
return nullptr;
// Both ptrtoint instructions must wrap global variables:
// Both ptrtoint instructions must wrap global objects:
// - Only global variables are eligible for image relative relocations.
// - The subtrahend refers to the special symbol __ImageBase, a global.
const GlobalVariable *GVLHS =
dyn_cast<GlobalVariable>(SubLHS->getPointerOperand());
const GlobalVariable *GVRHS =
dyn_cast<GlobalVariable>(SubRHS->getPointerOperand());
if (!GVLHS || !GVRHS)
// - The subtrahend refers to the special symbol __ImageBase, a GlobalVariable.
const auto *GOLHS = dyn_cast<GlobalObject>(SubLHS->getPointerOperand());
const auto *GVRHS = dyn_cast<GlobalVariable>(SubRHS->getPointerOperand());
if (!GOLHS || !GVRHS)
return nullptr;
// We expect __ImageBase to be a global variable without a section, externally
@@ -116,10 +114,10 @@ const MCExpr *X86WindowsTargetObjectFile::getExecutableRelativeSymbol(
return nullptr;
// An image-relative, thread-local, symbol makes no sense.
if (GVLHS->isThreadLocal())
if (GOLHS->isThreadLocal())
return nullptr;
return MCSymbolRefExpr::Create(TM.getSymbol(GVLHS, Mang),
return MCSymbolRefExpr::Create(TM.getSymbol(GOLHS, Mang),
MCSymbolRefExpr::VK_COFF_IMGREL32,
getContext());
}