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
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
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"
|
2019-05-11 07:24:38 +08:00
|
|
|
#include "MCTargetDesc/X86ATTInstPrinter.h"
|
2014-03-19 14:53:25 +08:00
|
|
|
#include "MCTargetDesc/X86BaseInfo.h"
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
#include "MCTargetDesc/X86TargetStreamer.h"
|
2019-05-15 09:17:58 +08:00
|
|
|
#include "TargetInfo/X86TargetInfo.h"
|
2014-03-19 14:53:25 +08:00
|
|
|
#include "X86InstrInfo.h"
|
2009-09-20 15:41:30 +08:00
|
|
|
#include "X86MachineFunctionInfo.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
2018-06-05 05:07:35 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.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"
|
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
#include "llvm/IR/InlineAsm.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"
|
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"
|
2018-06-05 05:07:35 +08:00
|
|
|
#include "llvm/MC/MCSectionELF.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-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"
|
2018-03-24 07:58:25 +08:00
|
|
|
#include "llvm/Support/MachineValueType.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;
|
|
|
|
|
2017-10-12 07:53:12 +08:00
|
|
|
X86AsmPrinter::X86AsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
|
|
|
: AsmPrinter(TM, std::move(Streamer)), SM(*this), FM(*this) {}
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// 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(
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
*Subtarget->getInstrInfo(), *Subtarget->getRegisterInfo(),
|
2016-04-19 13:24:47 +08:00
|
|
|
MF.getContext()));
|
2014-07-25 04:40:55 +08:00
|
|
|
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
EmitFPOData =
|
|
|
|
Subtarget->isTargetWin32() && MF.getMMI().getModule()->getCodeViewFlag();
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
SetupMachineFunction(MF);
|
|
|
|
|
2013-12-11 00:57:43 +08:00
|
|
|
if (Subtarget->isTargetCOFF()) {
|
2017-12-16 06:22:58 +08:00
|
|
|
bool Local = MF.getFunction().hasLocalLinkage();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
|
2016-10-13 08:55:24 +08:00
|
|
|
OutStreamer->EmitCOFFSymbolStorageClass(
|
|
|
|
Local ? COFF::IMAGE_SYM_CLASS_STATIC : COFF::IMAGE_SYM_CLASS_EXTERNAL);
|
2015-04-25 03:11:51 +08:00
|
|
|
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
|
|
|
|
XRay: Add entry and exit sleds
Summary:
In this patch we implement the following parts of XRay:
- Supporting a function attribute named 'function-instrument' which currently only supports 'xray-always'. We should be able to use this attribute for other instrumentation approaches.
- Supporting a function attribute named 'xray-instruction-threshold' used to determine whether a function is instrumented with a minimum number of instructions (IR instruction counts).
- X86-specific nop sleds as described in the white paper.
- A machine function pass that adds the different instrumentation marker instructions at a very late stage.
- A way of identifying which return opcode is considered "normal" for each architecture.
There are some caveats here:
1) We don't handle PATCHABLE_RET in platforms other than x86_64 yet -- this means if IR used PATCHABLE_RET directly instead of a normal ret, instruction lowering for that platform might do the wrong thing. We think this should be handled at instruction selection time to by default be unpacked for platforms where XRay is not availble yet.
2) The generated section for X86 is different from what is described from the white paper for the sole reason that LLVM allows us to do this neatly. We're taking the opportunity to deviate from the white paper from this perspective to allow us to get richer information from the runtime library.
Reviewers: sanjoy, eugenis, kcc, pcc, echristo, rnk
Subscribers: niravd, majnemer, atrick, rnk, emaste, bmakam, mcrosier, mehdi_amini, llvm-commits
Differential Revision: http://reviews.llvm.org/D19904
llvm-svn: 275367
2016-07-14 12:06:33 +08:00
|
|
|
// Emit the XRay table for this function.
|
2017-01-03 12:30:21 +08:00
|
|
|
emitXRayTable();
|
XRay: Add entry and exit sleds
Summary:
In this patch we implement the following parts of XRay:
- Supporting a function attribute named 'function-instrument' which currently only supports 'xray-always'. We should be able to use this attribute for other instrumentation approaches.
- Supporting a function attribute named 'xray-instruction-threshold' used to determine whether a function is instrumented with a minimum number of instructions (IR instruction counts).
- X86-specific nop sleds as described in the white paper.
- A machine function pass that adds the different instrumentation marker instructions at a very late stage.
- A way of identifying which return opcode is considered "normal" for each architecture.
There are some caveats here:
1) We don't handle PATCHABLE_RET in platforms other than x86_64 yet -- this means if IR used PATCHABLE_RET directly instead of a normal ret, instruction lowering for that platform might do the wrong thing. We think this should be handled at instruction selection time to by default be unpacked for platforms where XRay is not availble yet.
2) The generated section for X86 is different from what is described from the white paper for the sole reason that LLVM allows us to do this neatly. We're taking the opportunity to deviate from the white paper from this perspective to allow us to get richer information from the runtime library.
Reviewers: sanjoy, eugenis, kcc, pcc, echristo, rnk
Subscribers: niravd, majnemer, atrick, rnk, emaste, bmakam, mcrosier, mehdi_amini, llvm-commits
Differential Revision: http://reviews.llvm.org/D19904
llvm-svn: 275367
2016-07-14 12:06:33 +08:00
|
|
|
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
EmitFPOData = false;
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
// We didn't modify anything.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
void X86AsmPrinter::EmitFunctionBodyStart() {
|
|
|
|
if (EmitFPOData) {
|
2018-11-15 23:17:15 +08:00
|
|
|
if (auto *XTS =
|
|
|
|
static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer()))
|
|
|
|
XTS->emitFPOProc(
|
|
|
|
CurrentFnSym,
|
|
|
|
MF->getInfo<X86MachineFunctionInfo>()->getArgumentStackSize());
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86AsmPrinter::EmitFunctionBodyEnd() {
|
|
|
|
if (EmitFPOData) {
|
2018-11-15 23:17:15 +08:00
|
|
|
if (auto *XTS =
|
|
|
|
static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer()))
|
|
|
|
XTS->emitFPOEndProc();
|
[codeview] Implement FPO data assembler directives
Summary:
This adds a set of new directives that describe 32-bit x86 prologues.
The directives are limited and do not expose the full complexity of
codeview FPO data. They are merely a convenience for the compiler to
generate more readable assembly so we don't need to generate tons of
labels in CodeGen. If our prologue emission changes in the future, we
can change the set of available directives to suit our needs. These are
modelled after the .seh_ directives, which use a different format that
interacts with exception handling.
The directives are:
.cv_fpo_proc _foo
.cv_fpo_pushreg ebp/ebx/etc
.cv_fpo_setframe ebp/esi/etc
.cv_fpo_stackalloc 200
.cv_fpo_endprologue
.cv_fpo_endproc
.cv_fpo_data _foo
I tried to follow the implementation of ARM EHABI CFI directives by
sinking most directives out of MCStreamer and into X86TargetStreamer.
This helps avoid polluting non-X86 code with WinCOFF specific logic.
I used cdb to confirm that this can show locals in parent CSRs in a few
cases, most importantly the one where we use ESI as a frame pointer,
i.e. the one in http://crbug.com/756153#c28
Once we have cdb integration in debuginfo-tests, we can add integration
tests there.
Reviewers: majnemer, hans
Subscribers: aemerson, mgorny, kristof.beyls, llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D38776
llvm-svn: 315513
2017-10-12 05:24:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
/// PrintSymbolOperand - Print a raw symbol reference operand. This handles
|
2009-09-20 15:41:30 +08:00
|
|
|
/// jump tables, constant pools, global address and external symbols, all of
|
|
|
|
/// which print to a label with various suffixes for relocation types etc.
|
2019-04-12 06:47:13 +08:00
|
|
|
void X86AsmPrinter::PrintSymbolOperand(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:
|
2019-04-12 06:47:13 +08:00
|
|
|
GetCPISymbol(MO.getIndex())->print(O, MAI);
|
|
|
|
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;
|
2016-06-29 22:59:50 +08:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
|
2019-04-12 06:47:13 +08:00
|
|
|
GVSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-01-16 08:51:39 +08:00
|
|
|
else
|
2019-04-12 06:47:13 +08:00
|
|
|
GVSym = 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)
|
2019-04-12 06:47:13 +08:00
|
|
|
GVSym = OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
|
[MinGW] [X86] Add stubs for references to data variables that might end up imported from a dll
Variables declared with the dllimport attribute are accessed via a
stub variable named __imp_<var>. In MinGW configurations, variables that
aren't declared with a dllimport attribute might still end up imported
from another DLL with runtime pseudo relocs.
For x86_64, this avoids the risk that the target is out of range
for a 32 bit PC relative reference, in case the target DLL is loaded
further than 4 GB from the reference. It also avoids having to make the
text section writable at runtime when doing the runtime fixups, which
makes it worthwhile to do for i386 as well.
Add stub variables for all dso local data references where a definition
of the variable isn't visible within the module, since the DLL data
autoimporting might make them imported even though they are marked as
dso local within LLVM.
Don't do this for variables that actually are defined within the same
module, since we then know for sure that it actually is dso local.
Don't do this for references to functions, since there's no need for
runtime pseudo relocations for autoimporting them; if a function from
a different DLL is called without the appropriate dllimport attribute,
the call just gets routed via a thunk instead.
GCC does something similar since 4.9 (when compiling with -mcmodel=medium
or large; from that version, medium is the default code model for x86_64
mingw), but only for x86_64.
Differential Revision: https://reviews.llvm.org/D51288
llvm-svn: 340942
2018-08-30 01:28:34 +08:00
|
|
|
else if (MO.getTargetFlags() == X86II::MO_COFFSTUB)
|
|
|
|
GVSym =
|
2019-04-12 06:47:13 +08:00
|
|
|
OutContext.getOrCreateSymbol(Twine(".refptr.") + GVSym->getName());
|
2015-06-11 09:31:48 +08:00
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
|
2019-04-12 06:47:13 +08:00
|
|
|
MCSymbol *Sym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
|
2010-09-15 09:01:45 +08:00
|
|
|
MachineModuleInfoImpl::StubValueTy &StubSym =
|
2019-04-12 06:47:13 +08:00
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
|
2014-04-25 13:30:21 +08:00
|
|
|
if (!StubSym.getPointer())
|
2019-04-12 06:47:13 +08:00
|
|
|
StubSym = MachineModuleInfoImpl::StubValueTy(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] != '$')
|
2019-04-12 06:47:13 +08:00
|
|
|
GVSym->print(O, MAI);
|
2015-06-09 08:31:39 +08:00
|
|
|
else {
|
|
|
|
O << '(';
|
2019-04-12 06:47:13 +08:00
|
|
|
GVSym->print(O, MAI);
|
2015-06-09 08:31:39 +08:00
|
|
|
O << ')';
|
|
|
|
}
|
2019-04-12 06:47:13 +08:00
|
|
|
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:
|
[MinGW] [X86] Add stubs for references to data variables that might end up imported from a dll
Variables declared with the dllimport attribute are accessed via a
stub variable named __imp_<var>. In MinGW configurations, variables that
aren't declared with a dllimport attribute might still end up imported
from another DLL with runtime pseudo relocs.
For x86_64, this avoids the risk that the target is out of range
for a 32 bit PC relative reference, in case the target DLL is loaded
further than 4 GB from the reference. It also avoids having to make the
text section writable at runtime when doing the runtime fixups, which
makes it worthwhile to do for i386 as well.
Add stub variables for all dso local data references where a definition
of the variable isn't visible within the module, since the DLL data
autoimporting might make them imported even though they are marked as
dso local within LLVM.
Don't do this for variables that actually are defined within the same
module, since we then know for sure that it actually is dso local.
Don't do this for references to functions, since there's no need for
runtime pseudo relocations for autoimporting them; if a function from
a different DLL is called without the appropriate dllimport attribute,
the call just gets routed via a thunk instead.
GCC does something similar since 4.9 (when compiling with -mcmodel=medium
or large; from that version, medium is the default code model for x86_64
mingw), but only for x86_64.
Differential Revision: https://reviews.llvm.org/D51288
llvm-svn: 340942
2018-08-30 01:28:34 +08:00
|
|
|
case X86II::MO_COFFSTUB:
|
2009-09-20 15:41:30 +08:00
|
|
|
// 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 << " + [.-";
|
2019-04-12 06:47:13 +08:00
|
|
|
MF->getPICBaseSymbol()->print(O, MAI);
|
2015-06-09 08:31:39 +08:00
|
|
|
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:
|
2015-06-09 08:31:39 +08:00
|
|
|
O << '-';
|
2019-04-12 06:47:13 +08:00
|
|
|
MF->getPICBaseSymbol()->print(O, 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" << '-';
|
2019-04-12 06:47:13 +08:00
|
|
|
MF->getPICBaseSymbol()->print(O, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
void X86AsmPrinter::PrintOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
2009-09-20 15:41:30 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
const bool IsATT = MI->getInlineAsmDialect() == InlineAsm::AD_ATT;
|
2009-09-20 15:41:30 +08:00
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("unknown operand type!");
|
|
|
|
case MachineOperand::MO_Register: {
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
if (IsATT)
|
|
|
|
O << '%';
|
2019-04-11 03:01:44 +08:00
|
|
|
O << X86ATTInstPrinter::getRegisterName(MO.getReg());
|
2009-09-20 15:41:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MachineOperand::MO_Immediate:
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
if (IsATT)
|
|
|
|
O << '$';
|
2013-02-14 05:33:44 +08:00
|
|
|
O << MO.getImm();
|
2009-09-20 15:41:30 +08:00
|
|
|
return;
|
|
|
|
|
2019-11-10 09:58:56 +08:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2013-11-27 23:13:06 +08:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
2019-12-31 03:33:56 +08:00
|
|
|
switch (MI->getInlineAsmDialect()) {
|
|
|
|
case InlineAsm::AD_ATT:
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
O << '$';
|
2019-12-31 03:33:56 +08:00
|
|
|
break;
|
|
|
|
case InlineAsm::AD_Intel:
|
|
|
|
O << "offset ";
|
|
|
|
break;
|
|
|
|
}
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintSymbolOperand(MO, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
break;
|
2019-02-09 04:48:56 +08:00
|
|
|
}
|
|
|
|
case MachineOperand::MO_BlockAddress: {
|
2019-04-12 06:47:13 +08:00
|
|
|
MCSymbol *Sym = GetBlockAddressSymbol(MO.getBlockAddress());
|
|
|
|
Sym->print(O, MAI);
|
2019-02-09 04:48:56 +08:00
|
|
|
break;
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
/// PrintModifiedOperand - Print subregisters based on supplied modifier,
|
|
|
|
/// deferring to PrintOperand() if no modifier was supplied or if operand is not
|
2019-04-11 03:01:44 +08:00
|
|
|
/// a register.
|
2019-04-12 06:47:13 +08:00
|
|
|
void X86AsmPrinter::PrintModifiedOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O, const char *Modifier) {
|
2019-04-11 03:01:44 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
if (!Modifier || MO.getType() != MachineOperand::MO_Register)
|
2019-04-12 06:47:13 +08:00
|
|
|
return PrintOperand(MI, OpNo, O);
|
2019-04-11 03:01:44 +08:00
|
|
|
if (MI->getInlineAsmDialect() == InlineAsm::AD_ATT)
|
|
|
|
O << '%';
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = MO.getReg();
|
2019-04-11 03:01:44 +08:00
|
|
|
if (strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
O << X86ATTInstPrinter::getRegisterName(Reg);
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
/// PrintPCRelImm - This is used to print an immediate value that ends up
|
2019-04-11 03:01:44 +08:00
|
|
|
/// being encoded as a pc-relative value. These print slightly differently, for
|
|
|
|
/// example, a $ is not emitted.
|
2019-04-12 06:47:13 +08:00
|
|
|
void X86AsmPrinter::PrintPCRelImm(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
2019-04-11 03:01:44 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
switch (MO.getType()) {
|
|
|
|
default: llvm_unreachable("Unknown pcrel immediate operand");
|
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
// pc-relativeness was handled when computing the value in the reg.
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo, O);
|
2019-04-11 03:01:44 +08:00
|
|
|
return;
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
O << MO.getImm();
|
|
|
|
return;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintSymbolOperand(MO, O);
|
2019-04-11 03:01:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
void X86AsmPrinter::PrintLeaMemReference(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O, const char *Modifier) {
|
|
|
|
const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
|
|
|
|
const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
|
|
|
|
const MachineOperand &DispSpec = MI->getOperand(OpNo + 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:
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintSymbolOperand(DispSpec, O);
|
[AsmPrinter] refactor to support %c w/ GlobalAddress'
Summary:
Targets like ARM, MSP430, PPC, and SystemZ have complex behavior when
printing the address of a MachineOperand::MO_GlobalAddress. Move that
handling into a new overriden method in each base class. A virtual
method was added to the base class for handling the generic case.
Refactors a few subclasses to support the target independent %a, %c, and
%n.
The patch also contains small cleanups for AVRAsmPrinter and
SystemZAsmPrinter.
It seems that NVPTXTargetLowering is possibly missing some logic to
transform GlobalAddressSDNodes for
TargetLowering::LowerAsmOperandForConstraint to handle with "i" extended
inline assembly asm constraints.
Fixes:
- https://bugs.llvm.org/show_bug.cgi?id=41402
- https://github.com/ClangBuiltLinux/linux/issues/449
Reviewers: echristo, void
Reviewed By: void
Subscribers: void, craig.topper, jholewinski, dschuff, jyknight, dylanmckay, sdardis, nemanjai, javed.absar, sbc100, jgravelle-google, eraman, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, jrtc27, atanasyan, jsji, llvm-commits, kees, tpimh, nathanchance, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60887
llvm-svn: 359337
2019-04-27 02:45:04 +08:00
|
|
|
break;
|
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)
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintModifiedOperand(MI, OpNo + X86::AddrBaseReg, O, Modifier);
|
2009-09-20 15:41:30 +08:00
|
|
|
|
|
|
|
if (IndexReg.getReg()) {
|
|
|
|
O << ',';
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintModifiedOperand(MI, OpNo + X86::AddrIndexReg, O, Modifier);
|
|
|
|
unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
|
2009-09-20 15:41:30 +08:00
|
|
|
if (ScaleVal != 1)
|
|
|
|
O << ',' << ScaleVal;
|
|
|
|
}
|
|
|
|
O << ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
void X86AsmPrinter::PrintMemReference(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O, const char *Modifier) {
|
|
|
|
assert(isMem(*MI, OpNo) && "Invalid memory reference!");
|
|
|
|
const MachineOperand &Segment = MI->getOperand(OpNo + X86::AddrSegmentReg);
|
2009-09-20 15:41:30 +08:00
|
|
|
if (Segment.getReg()) {
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintModifiedOperand(MI, OpNo + X86::AddrSegmentReg, O, Modifier);
|
2009-09-20 15:41:30 +08:00
|
|
|
O << ':';
|
|
|
|
}
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintLeaMemReference(MI, OpNo, O, Modifier);
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
2019-12-22 13:09:37 +08:00
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
void X86AsmPrinter::PrintIntelMemReference(const MachineInstr *MI,
|
2019-12-22 13:09:37 +08:00
|
|
|
unsigned OpNo, raw_ostream &O,
|
|
|
|
const char *Modifier) {
|
2019-04-12 06:47:13 +08:00
|
|
|
const MachineOperand &BaseReg = MI->getOperand(OpNo + X86::AddrBaseReg);
|
|
|
|
unsigned ScaleVal = MI->getOperand(OpNo + X86::AddrScaleAmt).getImm();
|
|
|
|
const MachineOperand &IndexReg = MI->getOperand(OpNo + X86::AddrIndexReg);
|
|
|
|
const MachineOperand &DispSpec = MI->getOperand(OpNo + X86::AddrDisp);
|
|
|
|
const MachineOperand &SegReg = MI->getOperand(OpNo + X86::AddrSegmentReg);
|
2013-11-01 01:18:07 +08:00
|
|
|
|
2019-12-22 13:09:37 +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;
|
|
|
|
|
2012-10-04 06:06:44 +08:00
|
|
|
// If this has a segment register, print it.
|
|
|
|
if (SegReg.getReg()) {
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo + X86::AddrSegmentReg, O);
|
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;
|
2019-12-22 13:09:37 +08:00
|
|
|
if (HasBaseReg) {
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo + X86::AddrBaseReg, O);
|
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 << '*';
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo + X86::AddrIndexReg, O);
|
2012-10-04 06:06:44 +08:00
|
|
|
NeedPlus = true;
|
|
|
|
}
|
|
|
|
|
2013-02-14 05:33:44 +08:00
|
|
|
if (!DispSpec.isImm()) {
|
|
|
|
if (NeedPlus) O << " + ";
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo + X86::AddrDisp, O);
|
2013-02-14 05:33:44 +08:00
|
|
|
} else {
|
|
|
|
int64_t DispVal = DispSpec.getImm();
|
2019-12-22 13:09:37 +08:00
|
|
|
if (DispVal || (!IndexReg.getReg() && !HasBaseReg)) {
|
2013-02-14 05:33:44 +08:00
|
|
|
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) {
|
Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Partial reverts in:
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
X86FixupLEAs.cpp - Some functions return unsigned and arguably should be MCRegister
X86FrameLowering.cpp - Some functions return unsigned and arguably should be MCRegister
HexagonBitSimplify.cpp - Function takes BitTracker::RegisterRef which appears to be unsigned&
MachineVerifier.cpp - Ambiguous operator==() given MCRegister and const Register
PPCFastISel.cpp - No Register::operator-=()
PeepholeOptimizer.cpp - TargetInstrInfo::optimizeLoadInstr() takes an unsigned&
MachineTraceMetrics.cpp - MachineTraceMetrics lacks a suitable constructor
Manual fixups in:
ARMFastISel.cpp - ARMEmitLoad() now takes a Register& instead of unsigned&
HexagonSplitDouble.cpp - Ternary operator was ambiguous between unsigned/Register
HexagonConstExtenders.cpp - Has a local class named Register, used llvm::Register instead of Register.
PPCFastISel.cpp - PPCEmitLoad() now takes a Register& instead of unsigned&
Depends on D65919
Reviewers: arsenm, bogner, craig.topper, RKSimon
Reviewed By: arsenm
Subscribers: RKSimon, craig.topper, lenary, aemerson, wuzish, jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65962
llvm-svn: 369041
2019-08-16 03:22:08 +08:00
|
|
|
Register Reg = MO.getReg();
|
2018-02-09 04:06:05 +08:00
|
|
|
bool EmitPercent = true;
|
|
|
|
|
2018-04-18 13:15:24 +08:00
|
|
|
if (!X86::GR8RegClass.contains(Reg) &&
|
|
|
|
!X86::GR16RegClass.contains(Reg) &&
|
|
|
|
!X86::GR32RegClass.contains(Reg) &&
|
|
|
|
!X86::GR64RegClass.contains(Reg))
|
|
|
|
return true;
|
|
|
|
|
2009-09-20 15:41:30 +08:00
|
|
|
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;
|
2018-02-09 04:06:05 +08:00
|
|
|
case 'V':
|
|
|
|
EmitPercent = false;
|
|
|
|
LLVM_FALLTHROUGH;
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-09 04:06:05 +08:00
|
|
|
if (EmitPercent)
|
|
|
|
O << '%';
|
|
|
|
|
|
|
|
O << X86ATTInstPrinter::getRegisterName(Reg);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
|
|
|
bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
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
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, 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:
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintSymbolOperand(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 << '(';
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(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:
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo, O);
|
2013-11-28 02:26:51 +08:00
|
|
|
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:
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintSymbolOperand(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 << '*';
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(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
|
2018-02-09 04:06:05 +08:00
|
|
|
case 'V': // Print native register without '%'
|
2009-09-20 15:41:30 +08:00
|
|
|
if (MO.isReg())
|
2013-11-27 15:34:09 +08:00
|
|
|
return printAsmMRegister(*this, MO, ExtraCode[0], O);
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case 'P': // This is the operand of a call, treat specially.
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintPCRelImm(MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
|
2018-03-02 22:28:56 +08:00
|
|
|
case 'n': // Negate the immediate or print a '-' before the operand.
|
2009-09-20 15:41:30 +08:00
|
|
|
// 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 << '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:47:13 +08:00
|
|
|
PrintOperand(MI, OpNo, O);
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
2010-04-04 13:29:35 +08:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
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':
|
2019-12-22 13:09:37 +08:00
|
|
|
if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
|
|
|
|
return true; // Unsupported modifier in Intel inline assembly.
|
|
|
|
} else {
|
|
|
|
PrintMemReference(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.
|
2019-12-22 13:09:37 +08:00
|
|
|
if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
|
|
|
|
PrintIntelMemReference(MI, OpNo, O, "no-rip");
|
|
|
|
} else {
|
|
|
|
PrintMemReference(MI, OpNo, O, "no-rip");
|
|
|
|
}
|
2009-09-20 15:41:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-12-22 13:09:37 +08:00
|
|
|
if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
|
|
|
|
PrintIntelMemReference(MI, OpNo, O, nullptr);
|
|
|
|
} else {
|
|
|
|
PrintMemReference(MI, OpNo, O, nullptr);
|
|
|
|
}
|
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
|
|
|
|
2018-06-05 05:07:35 +08:00
|
|
|
if (TT.isOSBinFormatELF()) {
|
|
|
|
// Assemble feature flags that may require creation of a note section.
|
|
|
|
unsigned FeatureFlagsAnd = 0;
|
|
|
|
if (M.getModuleFlag("cf-protection-branch"))
|
|
|
|
FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_IBT;
|
|
|
|
if (M.getModuleFlag("cf-protection-return"))
|
|
|
|
FeatureFlagsAnd |= ELF::GNU_PROPERTY_X86_FEATURE_1_SHSTK;
|
|
|
|
|
|
|
|
if (FeatureFlagsAnd) {
|
|
|
|
// Emit a .note.gnu.property section with the flags.
|
|
|
|
if (!TT.isArch32Bit() && !TT.isArch64Bit())
|
|
|
|
llvm_unreachable("CFProtection used on invalid architecture!");
|
|
|
|
MCSection *Cur = OutStreamer->getCurrentSectionOnly();
|
|
|
|
MCSection *Nt = MMI->getContext().getELFSection(
|
|
|
|
".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
|
|
|
|
OutStreamer->SwitchSection(Nt);
|
|
|
|
|
|
|
|
// Emitting note header.
|
|
|
|
int WordSize = TT.isArch64Bit() ? 8 : 4;
|
2019-09-27 20:54:21 +08:00
|
|
|
EmitAlignment(WordSize == 4 ? Align(4) : Align(8));
|
2018-06-05 05:07:35 +08:00
|
|
|
OutStreamer->EmitIntValue(4, 4 /*size*/); // data size for "GNU\0"
|
|
|
|
OutStreamer->EmitIntValue(8 + WordSize, 4 /*size*/); // Elf_Prop size
|
|
|
|
OutStreamer->EmitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4 /*size*/);
|
|
|
|
OutStreamer->EmitBytes(StringRef("GNU", 4)); // note name
|
|
|
|
|
|
|
|
// Emitting an Elf_Prop for the CET properties.
|
|
|
|
OutStreamer->EmitIntValue(ELF::GNU_PROPERTY_X86_FEATURE_1_AND, 4);
|
2019-01-05 05:25:01 +08:00
|
|
|
OutStreamer->EmitIntValue(4, 4); // data size
|
|
|
|
OutStreamer->EmitIntValue(FeatureFlagsAnd, 4); // data
|
2019-09-27 20:54:21 +08:00
|
|
|
EmitAlignment(WordSize == 4 ? Align(4) : Align(8)); // padding
|
2018-06-05 05:07:35 +08:00
|
|
|
|
|
|
|
OutStreamer->endSection(Nt);
|
|
|
|
OutStreamer->SwitchSection(Cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2018-09-19 17:58:30 +08:00
|
|
|
MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
|
|
|
|
OutStreamer->BeginCOFFSymbolDef(S);
|
|
|
|
OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
|
|
|
|
OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
|
|
|
|
OutStreamer->EndCOFFSymbolDef();
|
|
|
|
int64_t Feat00Flags = 0;
|
|
|
|
|
2015-02-06 03:06:45 +08:00
|
|
|
if (TT.getArch() == Triple::x86) {
|
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.
|
2018-09-19 17:58:30 +08:00
|
|
|
Feat00Flags |= 1;
|
2013-09-18 07:18:05 +08:00
|
|
|
}
|
2018-09-19 17:58:30 +08:00
|
|
|
|
Add Windows Control Flow Guard checks (/guard:cf).
Summary:
A new function pass (Transforms/CFGuard/CFGuard.cpp) inserts CFGuard checks on
indirect function calls, using either the check mechanism (X86, ARM, AArch64) or
or the dispatch mechanism (X86-64). The check mechanism requires a new calling
convention for the supported targets. The dispatch mechanism adds the target as
an operand bundle, which is processed by SelectionDAG. Another pass
(CodeGen/CFGuardLongjmp.cpp) identifies and emits valid longjmp targets, as
required by /guard:cf. This feature is enabled using the `cfguard` CC1 option.
Reviewers: thakis, rnk, theraven, pcc
Subscribers: ychen, hans, metalcanine, dmajor, tomrittervg, alex, mehdi_amini, mgorny, javed.absar, kristof.beyls, hiraditya, steven_wu, dexonsmith, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D65761
2019-10-28 21:22:19 +08:00
|
|
|
if (M.getModuleFlag("cfguard"))
|
2018-09-19 17:58:30 +08:00
|
|
|
Feat00Flags |= 0x800; // Object is CFG-aware.
|
|
|
|
|
|
|
|
OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
|
|
|
|
OutStreamer->EmitAssignment(
|
|
|
|
S, MCConstantExpr::create(Feat00Flags, 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*/);
|
|
|
|
}
|
|
|
|
|
2018-06-19 06:21:18 +08:00
|
|
|
static void emitNonLazyStubs(MachineModuleInfo *MMI, MCStreamer &OutStreamer) {
|
2014-07-15 06:57:27 +08:00
|
|
|
|
2018-06-19 06:21:18 +08:00
|
|
|
MachineModuleInfoMachO &MMIMacho =
|
|
|
|
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
|
|
|
|
|
|
|
// Output stubs for dynamically-linked functions.
|
|
|
|
MachineModuleInfoMachO::SymbolListTy Stubs;
|
|
|
|
|
|
|
|
// Output stubs for external and common global variables.
|
|
|
|
Stubs = MMIMacho.GetGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
|
|
|
OutStreamer.SwitchSection(MMI->getContext().getMachOSection(
|
|
|
|
"__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
|
|
|
|
SectionKind::getMetadata()));
|
|
|
|
|
|
|
|
for (auto &Stub : Stubs)
|
|
|
|
emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
|
|
|
|
|
|
|
|
Stubs.clear();
|
|
|
|
OutStreamer.AddBlankLine();
|
|
|
|
}
|
2014-07-15 06:57:27 +08:00
|
|
|
}
|
|
|
|
|
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()) {
|
2018-06-19 06:21:18 +08:00
|
|
|
// Mach-O uses non-lazy symbol stubs to encode per-TU information into
|
|
|
|
// global table for symbol lookup.
|
|
|
|
emitNonLazyStubs(MMI, *OutStreamer);
|
2009-09-20 15:41:30 +08:00
|
|
|
|
2018-06-19 06:21:18 +08:00
|
|
|
// Emit stack and fault map information.
|
2018-11-27 02:43:48 +08:00
|
|
|
emitStackMaps(SM);
|
2015-06-16 02:44:08 +08:00
|
|
|
FM.serializeToFaultMapSection();
|
2013-11-01 06:11:56 +08:00
|
|
|
|
2018-06-19 06:21:19 +08:00
|
|
|
// This flag tells the linker that no global symbols contain code that fall
|
|
|
|
// through to other global symbols (e.g. an 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);
|
2019-01-25 02:34:00 +08:00
|
|
|
} else if (TT.isOSBinFormatCOFF()) {
|
|
|
|
if (MMI->usesMSVCFloatingPoint()) {
|
|
|
|
// In Windows' libcmt.lib, there is a file which is linked in only if the
|
|
|
|
// symbol _fltused is referenced. Linking this in causes some
|
|
|
|
// side-effects:
|
|
|
|
//
|
|
|
|
// 1. For x86-32, it will set the x87 rounding mode to 53-bit instead of
|
|
|
|
// 64-bit mantissas at program start.
|
|
|
|
//
|
|
|
|
// 2. It links in support routines for floating-point in scanf and printf.
|
|
|
|
//
|
|
|
|
// MSVC emits an undefined reference to _fltused when there are any
|
|
|
|
// floating point operations in the program (including calls). A program
|
|
|
|
// that only has: `scanf("%f", &global_float);` may fail to trigger this,
|
|
|
|
// but oh well...that's a documented issue.
|
|
|
|
StringRef SymbolName =
|
|
|
|
(TT.getArch() == Triple::x86) ? "__fltused" : "_fltused";
|
|
|
|
MCSymbol *S = MMI->getContext().getOrCreateSymbol(SymbolName);
|
|
|
|
OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
|
|
|
|
return;
|
|
|
|
}
|
2018-11-27 02:43:48 +08:00
|
|
|
emitStackMaps(SM);
|
2019-01-25 02:34:00 +08:00
|
|
|
} else if (TT.isOSBinFormatELF()) {
|
2018-11-27 02:43:48 +08:00
|
|
|
emitStackMaps(SM);
|
2015-06-16 02:44:08 +08:00
|
|
|
FM.serializeToFaultMapSection();
|
|
|
|
}
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Target Registry Stuff
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Force static initialization.
|
CMake: Make most target symbols hidden by default
Summary:
For builds with LLVM_BUILD_LLVM_DYLIB=ON and BUILD_SHARED_LIBS=OFF
this change makes all symbols in the target specific libraries hidden
by default.
A new macro called LLVM_EXTERNAL_VISIBILITY has been added to mark symbols in these
libraries public, which is mainly needed for the definitions of the
LLVMInitialize* functions.
This patch reduces the number of public symbols in libLLVM.so by about
25%. This should improve load times for the dynamic library and also
make abi checker tools, like abidiff require less memory when analyzing
libLLVM.so
One side-effect of this change is that for builds with
LLVM_BUILD_LLVM_DYLIB=ON and LLVM_LINK_LLVM_DYLIB=ON some unittests that
access symbols that are no longer public will need to be statically linked.
Before and after public symbol counts (using gcc 8.2.1, ld.bfd 2.31.1):
nm before/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
36221
nm after/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
26278
Reviewers: chandlerc, beanz, mgorny, rnk, hans
Reviewed By: rnk, hans
Subscribers: merge_guards_bot, luismarques, smeenai, ldionne, lenary, s.egerton, pzheng, sameer.abuasal, MaskRay, wuzish, echristo, Jim, hiraditya, michaelplatings, chapuni, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, mgrang, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, kristina, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D54439
2020-01-15 11:15:07 +08:00
|
|
|
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86AsmPrinter() {
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterAsmPrinter<X86AsmPrinter> X(getTheX86_32Target());
|
|
|
|
RegisterAsmPrinter<X86AsmPrinter> Y(getTheX86_64Target());
|
2009-09-20 15:41:30 +08:00
|
|
|
}
|