[PATCH] D34781: Introduce a MCReloc class
Rafael Ávila de Espíndola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 14:29:42 PDT 2017
rafael created this revision.
Herald added subscribers: kbarton, aheejin, kristof.beyls, sbc100, javed.absar, nhaehnle, nemanjai, sdardis, jyknight, arsenm, aemerson.
Trying to fix a bug in this area I realized just how confusing the code is. The are subtly different information in different variables. For example,
- What relocation should we map FK_Data_1 to? What if IsPCRel was set to true?
- What is the addend? FixedValue or Target.getConstant()?
- What is the meaning of "foo - bar at got"?
- There is *a lot* of duplicated code is the various obj writers.
This leads to situation where each target ( ARMELFObjectWriter::GetRelocTypeInner for example) has code that looks like
if (IsPCRel) {
big switch
} else {
very similar big switch
}
This patches introduces a MCReloc to represent the result of evaluating a MCFixup. It is a mutable structure, unlike MCFixup. This allows us to update it when we convert a relocation to be PCRel. In this patch that is done for ELF, but I have a follow up to share the code with COFF (and hopefully MachO and WebAsm).
With that we don't need the IsPCRel argument anymore. This should allow big cleanups in a followup patch.
The MCReloc also avoids any confusion as to the value to be created. There is only one constant. It is also impossible to represent broken things like "foo - bar at got".
The one downside is with scattered relocations on MachO that now need to do a bit more work. I think it is well worth it.
In this patch there are a few hacks to reduce its size. I intend to clean that up in a followup patch.
https://reviews.llvm.org/D34781
Files:
include/llvm/MC/MCAsmBackend.h
include/llvm/MC/MCAssembler.h
include/llvm/MC/MCELFObjectWriter.h
include/llvm/MC/MCFixup.h
include/llvm/MC/MCMachObjectWriter.h
include/llvm/MC/MCObjectWriter.h
include/llvm/MC/MCWasmObjectWriter.h
include/llvm/MC/MCWinCOFFObjectWriter.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCAsmBackend.cpp
lib/MC/MCAssembler.cpp
lib/MC/MachObjectWriter.cpp
lib/MC/WasmObjectWriter.cpp
lib/MC/WinCOFFObjectWriter.cpp
lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
lib/Target/AArch64/MCTargetDesc/AArch64FixupKinds.h
lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp
lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
lib/Target/ARM/MCTargetDesc/ARMFixupKinds.h
lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
lib/Target/ARM/MCTargetDesc/ARMWinCOFFObjectWriter.cpp
lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
lib/Target/Lanai/MCTargetDesc/LanaiAsmBackend.cpp
lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h
lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
lib/Target/PowerPC/MCTargetDesc/PPCFixupKinds.h
lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp
lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp
lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp
lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34781.104509.patch
Type: text/x-patch
Size: 122902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170628/e07deba1/attachment-0001.bin>
More information about the llvm-commits
mailing list