[AArch64] Add support for dllimport of values and functions
Previously, the dllimport attribute did the right thing in terms
of treating it as a pointer to a value, but this makes sure the
names get mangled properly, and calls to such functions load the
function from the __imp_ pointer.
This is based on SVN r212431 and r212430 where the same was
implemented for ARM.
Differential Revision: https://reviews.llvm.org/D38530
llvm-svn: 316555
diff --git a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp b/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
index f82b9db..f1281a1 100644
--- a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
+++ b/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
@@ -19,10 +19,12 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/IR/Mangler.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
using namespace llvm;
@@ -33,7 +35,25 @@
MCSymbol *
AArch64MCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
- return Printer.getSymbol(MO.getGlobal());
+ const GlobalValue *GV = MO.getGlobal();
+ unsigned TargetFlags = MO.getTargetFlags();
+ const Triple &TheTriple = Printer.TM.getTargetTriple();
+ if (!TheTriple.isOSBinFormatCOFF())
+ return Printer.getSymbol(GV);
+
+ assert(TheTriple.isOSWindows() &&
+ "Windows is the only supported COFF target");
+
+ bool IsIndirect = (TargetFlags & AArch64II::MO_DLLIMPORT);
+ if (!IsIndirect)
+ return Printer.getSymbol(GV);
+
+ SmallString<128> Name;
+ Name = "__imp_";
+ Printer.TM.getNameWithPrefix(Name, GV,
+ Printer.getObjFileLowering().getMangler());
+
+ return Ctx.getOrCreateSymbol(Name);
}
MCSymbol *