[llvm] r337950 - [COFF] Hoist constant pool handling from X86AsmPrinter into AsmPrinter
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 25 11:35:31 PDT 2018
Author: mstorsjo
Date: Wed Jul 25 11:35:31 2018
New Revision: 337950
URL: http://llvm.org/viewvc/llvm-project?rev=337950&view=rev
Log:
[COFF] Hoist constant pool handling from X86AsmPrinter into AsmPrinter
In SVN r334523, the first half of comdat constant pool handling was
hoisted from X86WindowsTargetObjectFile (which despite the name only
was used for msvc targets) into the arch independent
TargetLoweringObjectFileCOFF, but the other half of the handling was
left behind in X86AsmPrinter::GetCPISymbol.
With only half of the handling in place, inconsistent comdat
sections/symbols are created, causing issues with both GNU binutils
(avoided for X86 in SVN r335918) and with the MS linker, which
would complain like this:
fatal error LNK1143: invalid or corrupt file: no symbol for COMDAT section 0x4
Differential Revision: https://reviews.llvm.org/D49644
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h
llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
llvm/trunk/lib/Target/X86/X86AsmPrinter.h
llvm/trunk/test/CodeGen/AArch64/win_cst_pool.ll
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=337950&r1=337949&r2=337950&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Jul 25 11:35:31 2018
@@ -87,6 +87,7 @@
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
@@ -2663,6 +2664,25 @@ MCSymbol *AsmPrinter::GetBlockAddressSym
/// GetCPISymbol - Return the symbol for the specified constant pool entry.
MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
+ if (getSubtargetInfo().getTargetTriple().isKnownWindowsMSVCEnvironment()) {
+ const MachineConstantPoolEntry &CPE =
+ MF->getConstantPool()->getConstants()[CPID];
+ if (!CPE.isMachineConstantPoolEntry()) {
+ const DataLayout &DL = MF->getDataLayout();
+ SectionKind Kind = CPE.getSectionKind(&DL);
+ const Constant *C = CPE.Val.ConstVal;
+ unsigned Align = CPE.Alignment;
+ if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
+ getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) {
+ if (MCSymbol *Sym = S->getCOMDATSymbol()) {
+ if (Sym->isUndefined())
+ OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
+ return Sym;
+ }
+ }
+ }
+ }
+
const DataLayout &DL = getDataLayout();
return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
"CPI" + Twine(getFunctionNumber()) + "_" +
Modified: llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp?rev=337950&r1=337949&r2=337950&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp Wed Jul 25 11:35:31 2018
@@ -242,9 +242,7 @@ MCSymbol *AArch64AsmPrinter::GetCPISymbo
Twine(getDataLayout().getLinkerPrivateGlobalPrefix()) + "CPI" +
Twine(getFunctionNumber()) + "_" + Twine(CPID));
- return OutContext.getOrCreateSymbol(
- Twine(getDataLayout().getPrivateGlobalPrefix()) + "CPI" +
- Twine(getFunctionNumber()) + "_" + Twine(CPID));
+ return AsmPrinter::GetCPISymbol(CPID);
}
void AArch64AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNum,
Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=337950&r1=337949&r2=337950&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Wed Jul 25 11:35:31 2018
@@ -235,6 +235,15 @@ void ARMAsmPrinter::printOperand(const M
}
}
+MCSymbol *ARMAsmPrinter::GetCPISymbol(unsigned CPID) const {
+ // The AsmPrinter::GetCPISymbol superclass method tries to use CPID as
+ // indexes in MachineConstantPool, which isn't in sync with indexes used here.
+ const DataLayout &DL = getDataLayout();
+ return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
+ "CPI" + Twine(getFunctionNumber()) + "_" +
+ Twine(CPID));
+}
+
//===--------------------------------------------------------------------===//
MCSymbol *ARMAsmPrinter::
Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h?rev=337950&r1=337949&r2=337950&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.h Wed Jul 25 11:35:31 2018
@@ -101,7 +101,9 @@ public:
void EmitEndOfAsmFile(Module &M) override;
void EmitXXStructor(const DataLayout &DL, const Constant *CV) override;
void EmitGlobalVariable(const GlobalVariable *GV) override;
-
+
+ MCSymbol *GetCPISymbol(unsigned CPID) const;
+
// lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
Modified: llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp?rev=337950&r1=337949&r2=337950&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp Wed Jul 25 11:35:31 2018
@@ -608,29 +608,6 @@ void X86AsmPrinter::EmitStartOfAsmFile(M
OutStreamer->EmitAssemblerFlag(MCAF_Code16);
}
-MCSymbol *X86AsmPrinter::GetCPISymbol(unsigned CPID) const {
- if (Subtarget->isTargetKnownWindowsMSVC()) {
- const MachineConstantPoolEntry &CPE =
- MF->getConstantPool()->getConstants()[CPID];
- if (!CPE.isMachineConstantPoolEntry()) {
- const DataLayout &DL = MF->getDataLayout();
- SectionKind Kind = CPE.getSectionKind(&DL);
- const Constant *C = CPE.Val.ConstVal;
- unsigned Align = CPE.Alignment;
- if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
- getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) {
- if (MCSymbol *Sym = S->getCOMDATSymbol()) {
- if (Sym->isUndefined())
- OutStreamer->EmitSymbolAttribute(Sym, MCSA_Global);
- return Sym;
- }
- }
- }
- }
-
- return AsmPrinter::GetCPISymbol(CPID);
-}
-
static void
emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
MachineModuleInfoImpl::StubValueTy &MCSym) {
Modified: llvm/trunk/lib/Target/X86/X86AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmPrinter.h?rev=337950&r1=337949&r2=337950&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.h (original)
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.h Wed Jul 25 11:35:31 2018
@@ -130,9 +130,6 @@ public:
unsigned AsmVariant, const char *ExtraCode,
raw_ostream &OS) override;
- /// Return the symbol for the specified constant pool entry.
- MCSymbol *GetCPISymbol(unsigned CPID) const override;
-
bool doInitialization(Module &M) override {
SMShadowTracker.reset(0);
SM.reset();
Modified: llvm/trunk/test/CodeGen/AArch64/win_cst_pool.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/win_cst_pool.ll?rev=337950&r1=337949&r2=337950&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/win_cst_pool.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/win_cst_pool.ll Wed Jul 25 11:35:31 2018
@@ -1,8 +1,19 @@
+; RUN: llc < %s -mtriple=aarch64-win32-msvc | FileCheck %s
; RUN: llc < %s -mtriple=aarch64-win32-gnu | FileCheck -check-prefix=MINGW %s
define double @double() {
ret double 0x0000000000800000
}
+; CHECK: .globl __real at 0000000000800000
+; CHECK-NEXT: .section .rdata,"dr",discard,__real at 0000000000800000
+; CHECK-NEXT: .p2align 3
+; CHECK-NEXT: __real at 0000000000800000:
+; CHECK-NEXT: .xword 8388608
+; CHECK: double:
+; CHECK: adrp x8, __real at 0000000000800000
+; CHECK-NEXT: ldr d0, [x8, __real at 0000000000800000]
+; CHECK-NEXT: ret
+
; MINGW: .section .rdata,"dr"
; MINGW-NEXT: .p2align 3
; MINGW-NEXT: [[LABEL:\.LC.*]]:
More information about the llvm-commits
mailing list