2009-09-20 15:41:30 +08:00
|
|
|
//===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===//
|
2005-04-22 07:38:14 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 07:38:14 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
2009-09-20 15:41:30 +08:00
|
|
|
// This file contains a printer that converts from our internal representation
|
2010-01-28 09:02:27 +08:00
|
|
|
// of machine-dependent LLVM code to X86 machine code.
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
#include "X86AsmPrinter.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "InstPrinter/X86ATTInstPrinter.h"
|
2014-03-19 14:53:25 +08:00
|
|
|
#include "MCTargetDesc/X86BaseInfo.h"
|
|
|
|
#include "X86InstrInfo.h"
|
2009-09-20 15:41:30 +08:00
|
|
|
#include "X86MachineFunctionInfo.h"
|
2014-07-15 06:57:27 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
2014-03-19 14:53:25 +08:00
|
|
|
#include "llvm/CodeGen/MachineValueType.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
2014-03-06 08:46:21 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2010-03-09 08:40:17 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2016-04-19 13:24:47 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2009-09-20 15:41:30 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-02-03 14:42:38 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2014-07-15 06:57:27 +08:00
|
|
|
#include "llvm/MC/MCSectionCOFF.h"
|
2009-09-20 15:41:30 +08:00
|
|
|
#include "llvm/MC/MCSectionMachO.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-07-15 02:14:33 +08:00
|
|
|
#include "llvm/Support/COFF.h"
|
2010-08-05 02:06:05 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-09-20 15:41:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2009-09-20 15:41:30 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Primitive Helper Functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-28 09:02:27 +08:00
|
|
|
/// runOnMachineFunction - Emit the function body.
|
2009-09-20 15:41:30 +08:00
|
|
|
///
|
|
|
|
bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
2015-02-06 03:06:45 +08:00
|
|
|
Subtarget = &MF.getSubtarget<X86Subtarget>();
|
|
|
|
|
2014-07-25 04:40:55 +08:00
|
|
|
SMShadowTracker.startFunction(MF);
|
2016-04-19 13:24:47 +08:00
|
|
|
CodeEmitter.reset(TM.getTarget().createMCCodeEmitter(
|
|
|
|
*MF.getSubtarget().getInstrInfo(), *MF.getSubtarget().getRegisterInfo(),
|
|
|
|
MF.getContext()));
|
2014-07-25 04:40:55 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
SetupMachineFunction(MF);
|
|
|
|
|
2013-12-11 00:57:43 +08:00
|
|
|
if (Subtarget->isTargetCOFF()) {
|
2010-05-09 03:54:22 +08:00
|
|
|
bool Intrn = MF.getFunction()->hasInternalLinkage();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
|
|
|
|
OutStreamer->EmitCOFFSymbolStorageClass(Intrn ? COFF::IMAGE_SYM_CLASS_STATIC
|
|
|
|
: COFF::IMAGE_SYM_CLASS_EXTERNAL);
|
|
|
|
OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_FUNCTION
|
2010-07-15 02:14:33 +08:00
|
|
|
<< COFF::SCT_COMPLEX_TYPE_SHIFT);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EndCOFFSymbolDef();
|
2010-01-27 07:18:44 +08:00
|
|
|
}
|
2010-02-12 23:28:40 +08:00
|
|
|
|
2010-01-28 09:02:27 +08:00
|
|
|
// Emit the rest of the function body.
|
|
|
|
EmitFunctionBody();
|
2009-09-20 15:41:30 +08:00
|
|
|
|
|
|
|
// We didn't modify anything.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// printSymbolOperand - Print a raw symbol reference operand. This handles
|
|
|
|
/// jump tables, constant pools, global address and external symbols, all of
|
|
|
|
/// which print to a label with various suffixes for relocation types etc.
|
2013-11-27 15:14:26 +08:00
|
|
|
static void printSymbolOperand(X86AsmPrinter &P, const MachineOperand &MO,
|
|
|
|
raw_ostream &O) {
|
2009-09-20 15:41:30 +08:00
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("unknown symbol type!");
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2015-06-09 08:31:39 +08:00
|
|
|
P.GetCPISymbol(MO.getIndex())->print(O, P.MAI);
|
2013-11-27 15:14:26 +08:00
|
|
|
P.printOffset(MO.getOffset(), O);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
|
|
|
const GlobalValue *GV = MO.getGlobal();
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2010-01-18 08:59:24 +08:00
|
|
|
MCSymbol *GVSym;
|
2009-09-20 15:41:30 +08:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
|
2013-12-03 00:25:47 +08:00
|
|
|
GVSym = P.getSymbolWithGlobalValueBase(GV, "$stub");
|
2009-09-20 15:41:30 +08:00
|
|
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
|
2013-12-03 00:25:47 +08:00
|
|
|
GVSym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-01-16 08:51:39 +08:00
|
|
|
else
|
2013-11-27 15:14:26 +08:00
|
|
|
GVSym = P.getSymbol(GV);
|
2010-01-16 08:51:39 +08:00
|
|
|
|
2015-06-11 09:31:48 +08:00
|
|
|
// Handle dllimport linkage.
|
|
|
|
if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
|
|
|
|
GVSym =
|
|
|
|
P.OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
|
2013-12-03 00:25:47 +08:00
|
|
|
MCSymbol *Sym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-09-15 09:01:45 +08:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2013-11-27 15:14:26 +08:00
|
|
|
P.MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!StubSym.getPointer())
|
2010-03-11 06:34:10 +08:00
|
|
|
StubSym = MachineModuleInfoImpl::
|
2013-11-27 15:14:26 +08:00
|
|
|
StubValueTy(P.getSymbol(GV), !GV->hasInternalLinkage());
|
2009-09-20 15:41:30 +08:00
|
|
|
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){
|
2013-12-03 00:25:47 +08:00
|
|
|
MCSymbol *Sym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-03-11 06:34:10 +08:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2013-11-27 15:14:26 +08:00
|
|
|
P.MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(
|
|
|
|
Sym);
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!StubSym.getPointer())
|
2010-03-11 06:34:10 +08:00
|
|
|
StubSym = MachineModuleInfoImpl::
|
2013-11-27 15:14:26 +08:00
|
|
|
StubValueTy(P.getSymbol(GV), !GV->hasInternalLinkage());
|
2009-09-20 15:41:30 +08:00
|
|
|
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
|
2013-12-03 00:25:47 +08:00
|
|
|
MCSymbol *Sym = P.getSymbolWithGlobalValueBase(GV, "$stub");
|
2010-03-11 06:34:10 +08:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2013-11-27 15:14:26 +08:00
|
|
|
P.MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!StubSym.getPointer())
|
2010-03-11 06:34:10 +08:00
|
|
|
StubSym = MachineModuleInfoImpl::
|
2013-11-27 15:14:26 +08:00
|
|
|
StubValueTy(P.getSymbol(GV), !GV->hasInternalLinkage());
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
// If the name begins with a dollar-sign, enclose it in parens. We do this
|
|
|
|
// to avoid having it look like an integer immediate to the assembler.
|
2010-01-16 08:51:39 +08:00
|
|
|
if (GVSym->getName()[0] != '$')
|
2015-06-09 08:31:39 +08:00
|
|
|
GVSym->print(O, P.MAI);
|
|
|
|
else {
|
|
|
|
O << '(';
|
|
|
|
GVSym->print(O, P.MAI);
|
|
|
|
O << ')';
|
|
|
|
}
|
2013-11-27 15:14:26 +08:00
|
|
|
P.printOffset(MO.getOffset(), O);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
switch (MO.getTargetFlags()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown target flag on GV operand");
|
|
|
|
case X86II::MO_NO_FLAG: // No flag.
|
|
|
|
break;
|
|
|
|
case X86II::MO_DARWIN_NONLAZY:
|
|
|
|
case X86II::MO_DLLIMPORT:
|
|
|
|
case X86II::MO_DARWIN_STUB:
|
|
|
|
// These affect the name of the symbol, not any suffix.
|
|
|
|
break;
|
|
|
|
case X86II::MO_GOT_ABSOLUTE_ADDRESS:
|
2015-06-09 08:31:39 +08:00
|
|
|
O << " + [.-";
|
|
|
|
P.MF->getPICBaseSymbol()->print(O, P.MAI);
|
|
|
|
O << ']';
|
2010-09-15 09:01:45 +08:00
|
|
|
break;
|
2009-09-20 15:41:30 +08:00
|
|
|
case X86II::MO_PIC_BASE_OFFSET:
|
|
|
|
case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
|
|
|
|
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
|
2015-06-09 08:31:39 +08:00
|
|
|
O << '-';
|
|
|
|
P.MF->getPICBaseSymbol()->print(O, P.MAI);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
case X86II::MO_TLSGD: O << "@TLSGD"; break;
|
2012-06-02 00:27:21 +08:00
|
|
|
case X86II::MO_TLSLD: O << "@TLSLD"; break;
|
|
|
|
case X86II::MO_TLSLDM: O << "@TLSLDM"; break;
|
2009-09-20 15:41:30 +08:00
|
|
|
case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
|
|
|
|
case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
|
|
|
|
case X86II::MO_TPOFF: O << "@TPOFF"; break;
|
2012-06-02 00:27:21 +08:00
|
|
|
case X86II::MO_DTPOFF: O << "@DTPOFF"; break;
|
2009-09-20 15:41:30 +08:00
|
|
|
case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
|
2012-05-11 18:11:01 +08:00
|
|
|
case X86II::MO_GOTNTPOFF: O << "@GOTNTPOFF"; break;
|
2009-09-20 15:41:30 +08:00
|
|
|
case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
|
|
|
|
case X86II::MO_GOT: O << "@GOT"; break;
|
|
|
|
case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
|
|
|
|
case X86II::MO_PLT: O << "@PLT"; break;
|
2010-06-03 12:07:48 +08:00
|
|
|
case X86II::MO_TLVP: O << "@TLVP"; break;
|
|
|
|
case X86II::MO_TLVP_PIC_BASE:
|
2015-06-09 08:31:39 +08:00
|
|
|
O << "@TLVP" << '-';
|
|
|
|
P.MF->getPICBaseSymbol()->print(O, P.MAI);
|
2010-06-03 12:07:48 +08:00
|
|
|
break;
|
2013-03-31 00:21:50 +08:00
|
|
|
case X86II::MO_SECREL: O << "@SECREL32"; break;
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:14:26 +08:00
|
|
|
static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
|
|
|
|
unsigned OpNo, raw_ostream &O,
|
2014-04-25 13:30:21 +08:00
|
|
|
const char *Modifier = nullptr, unsigned AsmVariant = 0);
|
2013-11-27 15:14:26 +08:00
|
|
|
|
2012-09-11 06:50:57 +08:00
|
|
|
/// printPCRelImm - This is used to print an immediate value that ends up
|
2009-09-20 15:41:30 +08:00
|
|
|
/// being encoded as a pc-relative value. These print slightly differently, for
|
|
|
|
/// example, a $ is not emitted.
|
2013-11-27 15:14:26 +08:00
|
|
|
static void printPCRelImm(X86AsmPrinter &P, const MachineInstr *MI,
|
|
|
|
unsigned OpNo, raw_ostream &O) {
|
2009-09-20 15:41:30 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("Unknown pcrel immediate operand");
|
2010-07-17 02:35:46 +08:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
// pc-relativeness was handled when computing the value in the reg.
|
2013-11-27 15:14:26 +08:00
|
|
|
printOperand(P, MI, OpNo, O);
|
2010-07-17 02:35:46 +08:00
|
|
|
return;
|
2009-09-20 15:41:30 +08:00
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
O << MO.getImm();
|
|
|
|
return;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2013-11-27 15:14:26 +08:00
|
|
|
printSymbolOperand(P, MO, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:14:26 +08:00
|
|
|
static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
|
|
|
|
unsigned OpNo, raw_ostream &O, const char *Modifier,
|
|
|
|
unsigned AsmVariant) {
|
2009-09-20 15:41:30 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("unknown operand type!");
|
|
|
|
case MachineOperand::MO_Register: {
|
2012-09-11 05:10:49 +08:00
|
|
|
// FIXME: Enumerating AsmVariant, so we can remove magic number.
|
|
|
|
if (AsmVariant == 0) O << '%';
|
2009-09-20 15:41:30 +08:00
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
|
2015-12-26 06:09:45 +08:00
|
|
|
unsigned Size = (strcmp(Modifier+6,"64") == 0) ? 64 :
|
|
|
|
(strcmp(Modifier+6,"32") == 0) ? 32 :
|
|
|
|
(strcmp(Modifier+6,"16") == 0) ? 16 : 8;
|
|
|
|
Reg = getX86SubSuperRegister(Reg, Size);
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
O << X86ATTInstPrinter::getRegisterName(Reg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MachineOperand::MO_Immediate:
|
2013-02-14 05:33:44 +08:00
|
|
|
if (AsmVariant == 0) O << '$';
|
|
|
|
O << MO.getImm();
|
2009-09-20 15:41:30 +08:00
|
|
|
return;
|
|
|
|
|
2013-11-27 23:13:06 +08:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
2013-02-14 05:33:44 +08:00
|
|
|
if (AsmVariant == 0) O << '$';
|
2013-11-27 15:14:26 +08:00
|
|
|
printSymbolOperand(P, MO, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:34:09 +08:00
|
|
|
static void printLeaMemReference(X86AsmPrinter &P, const MachineInstr *MI,
|
|
|
|
unsigned Op, raw_ostream &O,
|
2014-04-25 13:30:21 +08:00
|
|
|
const char *Modifier = nullptr) {
|
2014-03-19 00:14:11 +08:00
|
|
|
const MachineOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
|
|
|
|
const MachineOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
|
|
|
|
const MachineOperand &DispSpec = MI->getOperand(Op+X86::AddrDisp);
|
2009-09-20 15:41:30 +08:00
|
|
|
|
|
|
|
// If we really don't want to print out (rip), don't.
|
|
|
|
bool HasBaseReg = BaseReg.getReg() != 0;
|
|
|
|
if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
|
|
|
|
BaseReg.getReg() == X86::RIP)
|
|
|
|
HasBaseReg = false;
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
// HasParenPart - True if we will print out the () part of the mem ref.
|
|
|
|
bool HasParenPart = IndexReg.getReg() || HasBaseReg;
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2013-11-28 02:18:24 +08:00
|
|
|
switch (DispSpec.getType()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unknown operand type!");
|
|
|
|
case MachineOperand::MO_Immediate: {
|
2009-09-20 15:41:30 +08:00
|
|
|
int DispVal = DispSpec.getImm();
|
|
|
|
if (DispVal || !HasParenPart)
|
|
|
|
O << DispVal;
|
2013-11-28 02:18:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2014-03-19 00:14:11 +08:00
|
|
|
printSymbolOperand(P, DispSpec, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
2011-01-02 04:58:46 +08:00
|
|
|
if (Modifier && strcmp(Modifier, "H") == 0)
|
|
|
|
O << "+8";
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
if (HasParenPart) {
|
|
|
|
assert(IndexReg.getReg() != X86::ESP &&
|
|
|
|
"X86 doesn't allow scaling by ESP");
|
|
|
|
|
|
|
|
O << '(';
|
|
|
|
if (HasBaseReg)
|
2014-03-19 00:14:11 +08:00
|
|
|
printOperand(P, MI, Op+X86::AddrBaseReg, O, Modifier);
|
2009-09-20 15:41:30 +08:00
|
|
|
|
|
|
|
if (IndexReg.getReg()) {
|
|
|
|
O << ',';
|
2014-03-19 00:14:11 +08:00
|
|
|
printOperand(P, MI, Op+X86::AddrIndexReg, O, Modifier);
|
|
|
|
unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
|
2009-09-20 15:41:30 +08:00
|
|
|
if (ScaleVal != 1)
|
|
|
|
O << ',' << ScaleVal;
|
|
|
|
}
|
|
|
|
O << ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:34:09 +08:00
|
|
|
static void printMemReference(X86AsmPrinter &P, const MachineInstr *MI,
|
|
|
|
unsigned Op, raw_ostream &O,
|
2014-04-25 13:30:21 +08:00
|
|
|
const char *Modifier = nullptr) {
|
2009-09-20 15:41:30 +08:00
|
|
|
assert(isMem(MI, Op) && "Invalid memory reference!");
|
2014-03-19 00:14:11 +08:00
|
|
|
const MachineOperand &Segment = MI->getOperand(Op+X86::AddrSegmentReg);
|
2009-09-20 15:41:30 +08:00
|
|
|
if (Segment.getReg()) {
|
2014-03-19 00:14:11 +08:00
|
|
|
printOperand(P, MI, Op+X86::AddrSegmentReg, O, Modifier);
|
2009-09-20 15:41:30 +08:00
|
|
|
O << ':';
|
|
|
|
}
|
2013-11-27 15:34:09 +08:00
|
|
|
printLeaMemReference(P, MI, Op, O, Modifier);
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:34:09 +08:00
|
|
|
static void printIntelMemReference(X86AsmPrinter &P, const MachineInstr *MI,
|
|
|
|
unsigned Op, raw_ostream &O,
|
2014-04-25 13:30:21 +08:00
|
|
|
const char *Modifier = nullptr,
|
2013-11-27 15:34:09 +08:00
|
|
|
unsigned AsmVariant = 1) {
|
2014-03-19 00:14:11 +08:00
|
|
|
const MachineOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
|
|
|
|
unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
|
|
|
|
const MachineOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
|
|
|
|
const MachineOperand &DispSpec = MI->getOperand(Op+X86::AddrDisp);
|
|
|
|
const MachineOperand &SegReg = MI->getOperand(Op+X86::AddrSegmentReg);
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-10-04 06:06:44 +08:00
|
|
|
// If this has a segment register, print it.
|
|
|
|
if (SegReg.getReg()) {
|
2014-03-19 00:14:11 +08:00
|
|
|
printOperand(P, MI, Op+X86::AddrSegmentReg, O, Modifier, AsmVariant);
|
2012-10-04 06:06:44 +08:00
|
|
|
O << ':';
|
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-10-04 06:06:44 +08:00
|
|
|
O << '[';
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-10-04 06:06:44 +08:00
|
|
|
bool NeedPlus = false;
|
|
|
|
if (BaseReg.getReg()) {
|
2014-03-19 00:14:11 +08:00
|
|
|
printOperand(P, MI, Op+X86::AddrBaseReg, O, Modifier, AsmVariant);
|
2012-10-04 06:06:44 +08:00
|
|
|
NeedPlus = true;
|
|
|
|
}
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2012-10-04 06:06:44 +08:00
|
|
|
if (IndexReg.getReg()) {
|
|
|
|
if (NeedPlus) O << " + ";
|
|
|
|
if (ScaleVal != 1)
|
|
|
|
O << ScaleVal << '*';
|
2014-03-19 00:14:11 +08:00
|
|
|
printOperand(P, MI, Op+X86::AddrIndexReg, O, Modifier, AsmVariant);
|
2012-10-04 06:06:44 +08:00
|
|
|
NeedPlus = true;
|
|
|
|
}
|
|
|
|
|
2013-02-14 05:33:44 +08:00
|
|
|
if (!DispSpec.isImm()) {
|
|
|
|
if (NeedPlus) O << " + ";
|
2014-03-19 00:14:11 +08:00
|
|
|
printOperand(P, MI, Op+X86::AddrDisp, O, Modifier, AsmVariant);
|
2013-02-14 05:33:44 +08:00
|
|
|
} else {
|
|
|
|
int64_t DispVal = DispSpec.getImm();
|
|
|
|
if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
|
|
|
|
if (NeedPlus) {
|
|
|
|
if (DispVal > 0)
|
|
|
|
O << " + ";
|
|
|
|
else {
|
|
|
|
O << " - ";
|
|
|
|
DispVal = -DispVal;
|
|
|
|
}
|
2012-10-04 06:06:44 +08:00
|
|
|
}
|
2013-02-14 05:33:44 +08:00
|
|
|
O << DispVal;
|
2012-10-04 06:06:44 +08:00
|
|
|
}
|
2013-02-14 05:33:44 +08:00
|
|
|
}
|
2012-10-04 06:06:44 +08:00
|
|
|
O << ']';
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:34:09 +08:00
|
|
|
static bool printAsmMRegister(X86AsmPrinter &P, const MachineOperand &MO,
|
|
|
|
char Mode, raw_ostream &O) {
|
2009-09-20 15:41:30 +08:00
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
switch (Mode) {
|
|
|
|
default: return true; // Unknown mode.
|
|
|
|
case 'b': // Print QImode register
|
2015-12-26 06:09:45 +08:00
|
|
|
Reg = getX86SubSuperRegister(Reg, 8);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
case 'h': // Print QImode high register
|
2015-12-26 06:09:45 +08:00
|
|
|
Reg = getX86SubSuperRegister(Reg, 8, true);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
case 'w': // Print HImode register
|
2015-12-26 06:09:45 +08:00
|
|
|
Reg = getX86SubSuperRegister(Reg, 16);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
case 'k': // Print SImode register
|
2015-12-26 06:09:45 +08:00
|
|
|
Reg = getX86SubSuperRegister(Reg, 32);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
2014-03-29 07:28:07 +08:00
|
|
|
case 'q':
|
|
|
|
// Print 64-bit register names if 64-bit integer registers are available.
|
|
|
|
// Otherwise, print 32-bit register names.
|
2015-12-26 06:09:45 +08:00
|
|
|
Reg = getX86SubSuperRegister(Reg, P.getSubtarget().is64Bit() ? 64 : 32);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
O << '%' << X86ATTInstPrinter::getRegisterName(Reg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
|
|
|
bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
2010-04-04 13:29:35 +08:00
|
|
|
const char *ExtraCode, raw_ostream &O) {
|
2009-09-20 15:41:30 +08:00
|
|
|
// Does this asm operand have a single letter operand modifier?
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
|
|
|
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
switch (ExtraCode[0]) {
|
2012-06-26 21:49:27 +08:00
|
|
|
default:
|
|
|
|
// See if this is a generic print operand
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
case 'a': // This is an address. Currently only 'i' and 'r' are expected.
|
2013-11-28 02:26:51 +08:00
|
|
|
switch (MO.getType()) {
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
case MachineOperand::MO_Immediate:
|
2009-09-20 15:41:30 +08:00
|
|
|
O << MO.getImm();
|
|
|
|
return false;
|
2013-11-28 02:26:51 +08:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
2013-11-28 02:38:14 +08:00
|
|
|
llvm_unreachable("unexpected operand type!");
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2013-11-27 15:14:26 +08:00
|
|
|
printSymbolOperand(*this, MO, O);
|
2010-07-07 07:27:00 +08:00
|
|
|
if (Subtarget->isPICStyleRIPRel())
|
|
|
|
O << "(%rip)";
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
2013-11-28 02:26:51 +08:00
|
|
|
case MachineOperand::MO_Register:
|
2009-09-20 15:41:30 +08:00
|
|
|
O << '(';
|
2013-11-27 15:14:26 +08:00
|
|
|
printOperand(*this, MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
O << ')';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'c': // Don't print "$" before a global var name or constant.
|
2013-11-28 02:26:51 +08:00
|
|
|
switch (MO.getType()) {
|
|
|
|
default:
|
|
|
|
printOperand(*this, MI, OpNo, O);
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_Immediate:
|
2009-09-20 15:41:30 +08:00
|
|
|
O << MO.getImm();
|
2013-11-28 02:26:51 +08:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
2013-11-28 02:38:14 +08:00
|
|
|
llvm_unreachable("unexpected operand type!");
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2013-11-27 15:14:26 +08:00
|
|
|
printSymbolOperand(*this, MO, O);
|
2013-11-28 02:26:51 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case 'A': // Print '*' before a register (it must be a register)
|
|
|
|
if (MO.isReg()) {
|
|
|
|
O << '*';
|
2013-11-27 15:14:26 +08:00
|
|
|
printOperand(*this, MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 'b': // Print QImode register
|
|
|
|
case 'h': // Print QImode high register
|
|
|
|
case 'w': // Print HImode register
|
|
|
|
case 'k': // Print SImode register
|
|
|
|
case 'q': // Print DImode register
|
|
|
|
if (MO.isReg())
|
2013-11-27 15:34:09 +08:00
|
|
|
return printAsmMRegister(*this, MO, ExtraCode[0], O);
|
2013-11-27 15:14:26 +08:00
|
|
|
printOperand(*this, MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case 'P': // This is the operand of a call, treat specially.
|
2013-11-27 15:14:26 +08:00
|
|
|
printPCRelImm(*this, MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case 'n': // Negate the immediate or print a '-' before the operand.
|
|
|
|
// Note: this is a temporary solution. It should be handled target
|
|
|
|
// independently as part of the 'MC' work.
|
|
|
|
if (MO.isImm()) {
|
|
|
|
O << -MO.getImm();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
O << '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-25 13:30:21 +08:00
|
|
|
printOperand(*this, MI, OpNo, O, /*Modifier*/ nullptr, AsmVariant);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
|
|
|
unsigned OpNo, unsigned AsmVariant,
|
2010-04-04 13:29:35 +08:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
2012-10-04 06:06:44 +08:00
|
|
|
if (AsmVariant) {
|
2013-11-27 15:34:09 +08:00
|
|
|
printIntelMemReference(*this, MI, OpNo, O);
|
2012-10-04 06:06:44 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
|
|
|
|
|
|
|
switch (ExtraCode[0]) {
|
|
|
|
default: return true; // Unknown modifier.
|
|
|
|
case 'b': // Print QImode register
|
|
|
|
case 'h': // Print QImode high register
|
|
|
|
case 'w': // Print HImode register
|
|
|
|
case 'k': // Print SImode register
|
|
|
|
case 'q': // Print SImode register
|
|
|
|
// These only apply to registers, ignore on mem.
|
|
|
|
break;
|
2011-01-02 04:58:46 +08:00
|
|
|
case 'H':
|
2013-11-27 15:34:09 +08:00
|
|
|
printMemReference(*this, MI, OpNo, O, "H");
|
2011-01-02 04:58:46 +08:00
|
|
|
return false;
|
2009-09-20 15:41:30 +08:00
|
|
|
case 'P': // Don't print @PLT, but do print as memory.
|
2013-11-27 15:34:09 +08:00
|
|
|
printMemReference(*this, MI, OpNo, O, "no-rip");
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-11-27 15:34:09 +08:00
|
|
|
printMemReference(*this, MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-13 10:10:00 +08:00
|
|
|
void X86AsmPrinter::EmitStartOfAsmFile(Module &M) {
|
2015-06-16 23:44:21 +08:00
|
|
|
const Triple &TT = TM.getTargetTriple();
|
2015-02-06 03:06:45 +08:00
|
|
|
|
|
|
|
if (TT.isOSBinFormatMachO())
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
|
2013-09-18 07:18:05 +08:00
|
|
|
|
2015-02-06 03:06:45 +08:00
|
|
|
if (TT.isOSBinFormatCOFF()) {
|
2013-09-18 07:18:05 +08:00
|
|
|
// Emit an absolute @feat.00 symbol. This appears to be some kind of
|
|
|
|
// compiler features bitfield read by link.exe.
|
2015-02-06 03:06:45 +08:00
|
|
|
if (TT.getArch() == Triple::x86) {
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->BeginCOFFSymbolDef(S);
|
|
|
|
OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
|
|
|
|
OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
|
|
|
|
OutStreamer->EndCOFFSymbolDef();
|
2013-09-18 07:18:05 +08:00
|
|
|
// According to the PE-COFF spec, the LSB of this value marks the object
|
|
|
|
// for "registered SEH". This means that all SEH handler entry points
|
|
|
|
// must be registered in .sxdata. Use of any unregistered handlers will
|
|
|
|
// cause the process to terminate immediately. LLVM does not know how to
|
|
|
|
// register any SEH handlers, so its object files should be safe.
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
|
|
|
|
OutStreamer->EmitAssignment(
|
2015-05-30 09:25:56 +08:00
|
|
|
S, MCConstantExpr::create(int64_t(1), MMI->getContext()));
|
2013-09-18 07:18:05 +08:00
|
|
|
}
|
|
|
|
}
|
2015-07-22 18:49:44 +08:00
|
|
|
OutStreamer->EmitSyntaxDirective();
|
2016-04-22 21:36:11 +08:00
|
|
|
|
|
|
|
// If this is not inline asm and we're in 16-bit
|
|
|
|
// mode prefix assembly with .code16.
|
|
|
|
bool is16 = TT.getEnvironment() == Triple::CODE16;
|
|
|
|
if (M.getModuleInlineAsm().empty() && is16)
|
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_Code16);
|
2010-03-13 10:10:00 +08:00
|
|
|
}
|
|
|
|
|
2014-04-29 18:06:10 +08:00
|
|
|
static void
|
|
|
|
emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
|
|
|
|
MachineModuleInfoImpl::StubValueTy &MCSym) {
|
|
|
|
// L_foo$stub:
|
|
|
|
OutStreamer.EmitLabel(StubLabel);
|
|
|
|
// .indirect_symbol _foo
|
|
|
|
OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
|
|
|
|
|
|
|
|
if (MCSym.getInt())
|
|
|
|
// External to current translation unit.
|
|
|
|
OutStreamer.EmitIntValue(0, 4/*size*/);
|
|
|
|
else
|
|
|
|
// Internal to current translation unit.
|
|
|
|
//
|
|
|
|
// When we place the LSDA into the TEXT section, the type info
|
|
|
|
// pointers need to be indirect and pc-rel. We accomplish this by
|
|
|
|
// using NLPs; however, sometimes the types are local to the file.
|
|
|
|
// We need to fill in the value for the NLP in those cases.
|
|
|
|
OutStreamer.EmitValue(
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
|
2014-04-29 18:06:10 +08:00
|
|
|
4 /*size*/);
|
|
|
|
}
|
|
|
|
|
2014-07-15 06:57:27 +08:00
|
|
|
MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const {
|
|
|
|
if (Subtarget->isTargetKnownWindowsMSVC()) {
|
|
|
|
const MachineConstantPoolEntry &CPE =
|
|
|
|
MF->getConstantPool()->getConstants()[CPID];
|
|
|
|
if (!CPE.isMachineConstantPoolEntry()) {
|
2015-07-16 14:04:17 +08:00
|
|
|
const DataLayout &DL = MF->getDataLayout();
|
|
|
|
SectionKind Kind = CPE.getSectionKind(&DL);
|
2014-07-15 06:57:27 +08:00
|
|
|
const Constant *C = CPE.Val.ConstVal;
|
2016-02-21 09:30:30 +08:00
|
|
|
unsigned Align = CPE.Alignment;
|
2014-08-21 20:55:27 +08:00
|
|
|
if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
|
2016-02-21 09:30:30 +08:00
|
|
|
getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) {
|
2014-08-21 20:55:27 +08:00
|
|
|
if (MCSymbol *Sym = S->getCOMDATSymbol()) {
|
|
|
|
if (Sym->isUndefined())
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
|
2014-08-21 20:55:27 +08:00
|
|
|
return Sym;
|
|
|
|
}
|
2014-07-15 06:57:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return AsmPrinter::GetCPISymbol(CPID);
|
|
|
|
}
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
|
2015-06-16 23:44:21 +08:00
|
|
|
const Triple &TT = TM.getTargetTriple();
|
2015-02-06 03:06:45 +08:00
|
|
|
|
|
|
|
if (TT.isOSBinFormatMachO()) {
|
2009-09-20 15:41:30 +08:00
|
|
|
// All darwin targets use mach-o.
|
|
|
|
MachineModuleInfoMachO &MMIMacho =
|
2014-12-05 08:22:38 +08:00
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
// Output stubs for dynamically-linked functions.
|
|
|
|
MachineModuleInfoMachO::SymbolListTy Stubs;
|
|
|
|
|
|
|
|
Stubs = MMIMacho.GetFnStubList();
|
|
|
|
if (!Stubs.empty()) {
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *TheSection = OutContext.getMachOSection(
|
|
|
|
"__IMPORT", "__jump_table",
|
|
|
|
MachO::S_SYMBOL_STUBS | MachO::S_ATTR_SELF_MODIFYING_CODE |
|
|
|
|
MachO::S_ATTR_PURE_INSTRUCTIONS,
|
|
|
|
5, SectionKind::getMetadata());
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(TheSection);
|
2009-09-20 15:41:30 +08:00
|
|
|
|
2014-05-04 09:54:17 +08:00
|
|
|
for (const auto &Stub : Stubs) {
|
2010-02-03 14:42:38 +08:00
|
|
|
// L_foo$stub:
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(Stub.first);
|
2010-02-03 14:42:38 +08:00
|
|
|
// .indirect_symbol _foo
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitSymbolAttribute(Stub.second.getPointer(),
|
|
|
|
MCSA_IndirectSymbol);
|
2011-08-31 04:53:29 +08:00
|
|
|
// hlt; hlt; hlt; hlt; hlt hlt = 0xf4.
|
|
|
|
const char HltInsts[] = "\xf4\xf4\xf4\xf4\xf4";
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitBytes(StringRef(HltInsts, 5));
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
2010-09-15 09:01:45 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
Stubs.clear();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddBlankLine();
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Output stubs for external and common global variables.
|
|
|
|
Stubs = MMIMacho.GetGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *TheSection = OutContext.getMachOSection(
|
|
|
|
"__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
|
|
|
|
SectionKind::getMetadata());
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(TheSection);
|
2009-09-20 15:41:30 +08:00
|
|
|
|
2014-04-29 18:06:10 +08:00
|
|
|
for (auto &Stub : Stubs)
|
2015-04-25 03:11:51 +08:00
|
|
|
emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
|
2014-04-29 18:06:10 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
Stubs.clear();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddBlankLine();
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Stubs = MMIMacho.GetHiddenGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *TheSection = OutContext.getMachOSection(
|
|
|
|
"__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
|
|
|
|
SectionKind::getMetadata());
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(TheSection);
|
2014-04-29 18:06:10 +08:00
|
|
|
|
|
|
|
for (auto &Stub : Stubs)
|
2015-04-25 03:11:51 +08:00
|
|
|
emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
|
2009-09-20 15:41:30 +08:00
|
|
|
|
|
|
|
Stubs.clear();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->AddBlankLine();
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
2013-11-01 06:11:56 +08:00
|
|
|
SM.serializeToStackMapSection();
|
2015-06-16 02:44:08 +08:00
|
|
|
FM.serializeToFaultMapSection();
|
2013-11-01 06:11:56 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
// Funny Darwin hack: This flag tells the linker that no global symbols
|
|
|
|
// contain code that falls through to other global symbols (e.g. the obvious
|
|
|
|
// implementation of multiple entry points). If this doesn't occur, the
|
|
|
|
// linker can safely perform dead code stripping. Since LLVM never
|
|
|
|
// generates code that does this, it is always safe to set.
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
|
2009-10-16 06:36:18 +08:00
|
|
|
}
|
2009-09-20 15:41:30 +08:00
|
|
|
|
2015-02-06 03:06:45 +08:00
|
|
|
if (TT.isKnownWindowsMSVCEnvironment() && MMI->usesVAFloatArgument()) {
|
|
|
|
StringRef SymbolName =
|
|
|
|
(TT.getArch() == Triple::x86_64) ? "_fltused" : "__fltused";
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
|
2010-10-16 16:25:41 +08:00
|
|
|
}
|
|
|
|
|
2015-02-06 03:06:45 +08:00
|
|
|
if (TT.isOSBinFormatCOFF()) {
|
2015-06-30 06:04:09 +08:00
|
|
|
const TargetLoweringObjectFileCOFF &TLOFCOFF =
|
|
|
|
static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());
|
2010-05-09 13:52:28 +08:00
|
|
|
|
2015-06-30 06:04:09 +08:00
|
|
|
std::string Flags;
|
|
|
|
raw_string_ostream FlagsOS(Flags);
|
2010-05-09 13:52:28 +08:00
|
|
|
|
2015-06-30 06:04:09 +08:00
|
|
|
for (const auto &Function : M)
|
|
|
|
TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Function, *Mang);
|
2014-05-04 09:54:17 +08:00
|
|
|
for (const auto &Global : M.globals())
|
2015-06-30 06:04:09 +08:00
|
|
|
TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Global, *Mang);
|
|
|
|
for (const auto &Alias : M.aliases())
|
|
|
|
TLOFCOFF.emitLinkerFlagsForGlobal(FlagsOS, &Alias, *Mang);
|
2010-05-09 13:52:28 +08:00
|
|
|
|
2015-06-30 06:04:09 +08:00
|
|
|
FlagsOS.flush();
|
2014-01-14 23:22:47 +08:00
|
|
|
|
2015-06-30 06:04:09 +08:00
|
|
|
// Output collected flags.
|
|
|
|
if (!Flags.empty()) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(TLOFCOFF.getDrectveSection());
|
2015-06-30 06:04:09 +08:00
|
|
|
OutStreamer->EmitBytes(Flags);
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
2015-06-25 08:28:42 +08:00
|
|
|
|
|
|
|
SM.serializeToStackMapSection();
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
2010-02-16 06:35:59 +08:00
|
|
|
|
2015-06-16 02:44:08 +08:00
|
|
|
if (TT.isOSBinFormatELF()) {
|
2014-08-02 02:47:09 +08:00
|
|
|
SM.serializeToStackMapSection();
|
2015-06-16 02:44:08 +08:00
|
|
|
FM.serializeToFaultMapSection();
|
|
|
|
}
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Target Registry Stuff
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Force static initialization.
|
2010-09-15 09:01:45 +08:00
|
|
|
extern "C" void LLVMInitializeX86AsmPrinter() {
|
2009-09-20 15:41:30 +08:00
|
|
|
RegisterAsmPrinter<X86AsmPrinter> X(TheX86_32Target);
|
|
|
|
RegisterAsmPrinter<X86AsmPrinter> Y(TheX86_64Target);
|
|
|
|
}
|