From: Shiva Chen Date: Tue, 15 May 2018 01:28:50 +0000 (+0000) Subject: [RISCV] Define FeatureRelax and shouldForceRelocation for RISCV linker relaxation X-Git-Tag: android-x86-7.1-r4~1104 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=90842deba1cb8daddd6aff1b5a340b2fc36755c6;p=android-x86%2Fexternal-llvm.git [RISCV] Define FeatureRelax and shouldForceRelocation for RISCV linker relaxation 1. Deine FeatureRelax to enable/disable linker relaxation. 2. Define shouldForceRelocation to preserve relocation types even if the fixup can be resolved when linker relaxation enabled. This is necessary for correctness as offsets may change during relaxation. Differential Revision: https://reviews.llvm.org/D46674 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332318 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp index 65425e4b156..9c4ca811ce3 100644 --- a/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -43,6 +43,14 @@ public: std::unique_ptr createObjectWriter(raw_pwrite_stream &OS) const override; + // If linker relaxation is enabled, always emit relocations even if the fixup + // can be resolved. This is necessary for correctness as offsets may change + // during relaxation. + bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, + const MCValue &Target) override { + return STI.getFeatureBits()[RISCV::FeatureRelax]; + } + bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const override; diff --git a/lib/Target/RISCV/RISCV.td b/lib/Target/RISCV/RISCV.td index 3e80d745b82..281378cb2ee 100644 --- a/lib/Target/RISCV/RISCV.td +++ b/lib/Target/RISCV/RISCV.td @@ -55,6 +55,10 @@ def IsRV32 : Predicate<"!Subtarget->is64Bit()">, def RV64 : HwMode<"+64bit">; def RV32 : HwMode<"-64bit">; +def FeatureRelax + : SubtargetFeature<"relax", "EnableLinkerRelax", "true", + "Enable Linker relaxation.">; + //===----------------------------------------------------------------------===// // Registers, calling conventions, instruction descriptions. //===----------------------------------------------------------------------===// diff --git a/lib/Target/RISCV/RISCVSubtarget.h b/lib/Target/RISCV/RISCVSubtarget.h index 928ba5815a2..0e09391e782 100644 --- a/lib/Target/RISCV/RISCVSubtarget.h +++ b/lib/Target/RISCV/RISCVSubtarget.h @@ -36,6 +36,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo { bool HasStdExtD = false; bool HasStdExtC = false; bool HasRV64 = false; + bool EnableLinkerRelax = false; unsigned XLen = 32; MVT XLenVT = MVT::i32; RISCVFrameLowering FrameLowering; @@ -77,6 +78,7 @@ public: bool hasStdExtD() const { return HasStdExtD; } bool hasStdExtC() const { return HasStdExtC; } bool is64Bit() const { return HasRV64; } + bool enableLinkerRelax() const { return EnableLinkerRelax; } MVT getXLenVT() const { return XLenVT; } unsigned getXLen() const { return XLen; } };