[llvm] r366172 - [RISCV] Make RISCVELFObjectWriter::getRelocType check IsPCRel
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 20:47:34 PDT 2019
Author: asb
Date: Mon Jul 15 20:47:34 2019
New Revision: 366172
URL: http://llvm.org/viewvc/llvm-project?rev=366172&view=rev
Log:
[RISCV] Make RISCVELFObjectWriter::getRelocType check IsPCRel
Previously, this function didn't check the IsPCRel argument. But doing so is a
useful check for errors, and also seemingly necessary for FK_Data_4 (which we
produce a R_RISCV_32_PCREL relocation for if IsPCRel).
Other than R_RISCV_32_PCREL, this should be NFC. Future exception handling
related patches will include tests that capture this behaviour.
Modified:
llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
Modified: llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp?rev=366172&r1=366171&r2=366172&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp Mon Jul 15 20:47:34 2019
@@ -48,7 +48,42 @@ unsigned RISCVELFObjectWriter::getRelocT
const MCFixup &Fixup,
bool IsPCRel) const {
// Determine the type of the relocation
- switch ((unsigned)Fixup.getKind()) {
+ unsigned Kind = Fixup.getKind();
+ if (IsPCRel) {
+ switch (Kind) {
+ default:
+ llvm_unreachable("invalid fixup kind!");
+ case FK_Data_4:
+ case FK_PCRel_4:
+ return ELF::R_RISCV_32_PCREL;
+ case RISCV::fixup_riscv_pcrel_hi20:
+ return ELF::R_RISCV_PCREL_HI20;
+ case RISCV::fixup_riscv_pcrel_lo12_i:
+ return ELF::R_RISCV_PCREL_LO12_I;
+ case RISCV::fixup_riscv_pcrel_lo12_s:
+ return ELF::R_RISCV_PCREL_LO12_S;
+ case RISCV::fixup_riscv_got_hi20:
+ return ELF::R_RISCV_GOT_HI20;
+ case RISCV::fixup_riscv_tls_got_hi20:
+ return ELF::R_RISCV_TLS_GOT_HI20;
+ case RISCV::fixup_riscv_tls_gd_hi20:
+ return ELF::R_RISCV_TLS_GD_HI20;
+ case RISCV::fixup_riscv_jal:
+ return ELF::R_RISCV_JAL;
+ case RISCV::fixup_riscv_branch:
+ return ELF::R_RISCV_BRANCH;
+ case RISCV::fixup_riscv_rvc_jump:
+ return ELF::R_RISCV_RVC_JUMP;
+ case RISCV::fixup_riscv_rvc_branch:
+ return ELF::R_RISCV_RVC_BRANCH;
+ case RISCV::fixup_riscv_call:
+ return ELF::R_RISCV_CALL;
+ case RISCV::fixup_riscv_call_plt:
+ return ELF::R_RISCV_CALL_PLT;
+ }
+ }
+
+ switch (Kind) {
default:
llvm_unreachable("invalid fixup kind!");
case FK_Data_4:
@@ -77,14 +112,6 @@ unsigned RISCVELFObjectWriter::getRelocT
return ELF::R_RISCV_LO12_I;
case RISCV::fixup_riscv_lo12_s:
return ELF::R_RISCV_LO12_S;
- case RISCV::fixup_riscv_pcrel_hi20:
- return ELF::R_RISCV_PCREL_HI20;
- case RISCV::fixup_riscv_pcrel_lo12_i:
- return ELF::R_RISCV_PCREL_LO12_I;
- case RISCV::fixup_riscv_pcrel_lo12_s:
- return ELF::R_RISCV_PCREL_LO12_S;
- case RISCV::fixup_riscv_got_hi20:
- return ELF::R_RISCV_GOT_HI20;
case RISCV::fixup_riscv_tprel_hi20:
return ELF::R_RISCV_TPREL_HI20;
case RISCV::fixup_riscv_tprel_lo12_i:
@@ -93,22 +120,6 @@ unsigned RISCVELFObjectWriter::getRelocT
return ELF::R_RISCV_TPREL_LO12_S;
case RISCV::fixup_riscv_tprel_add:
return ELF::R_RISCV_TPREL_ADD;
- case RISCV::fixup_riscv_tls_got_hi20:
- return ELF::R_RISCV_TLS_GOT_HI20;
- case RISCV::fixup_riscv_tls_gd_hi20:
- return ELF::R_RISCV_TLS_GD_HI20;
- case RISCV::fixup_riscv_jal:
- return ELF::R_RISCV_JAL;
- case RISCV::fixup_riscv_branch:
- return ELF::R_RISCV_BRANCH;
- case RISCV::fixup_riscv_rvc_jump:
- return ELF::R_RISCV_RVC_JUMP;
- case RISCV::fixup_riscv_rvc_branch:
- return ELF::R_RISCV_RVC_BRANCH;
- case RISCV::fixup_riscv_call:
- return ELF::R_RISCV_CALL;
- case RISCV::fixup_riscv_call_plt:
- return ELF::R_RISCV_CALL_PLT;
case RISCV::fixup_riscv_relax:
return ELF::R_RISCV_RELAX;
case RISCV::fixup_riscv_align:
More information about the llvm-commits
mailing list