diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -24,6 +24,7 @@ public: RISCV(); uint32_t calcEFlags() const override; + int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override; void writeGotHeader(uint8_t *buf) const override; void writeGotPlt(uint8_t *buf, const Symbol &s) const override; void writeIgotPlt(uint8_t *buf, const Symbol &s) const override; @@ -134,6 +135,27 @@ return target; } +int64_t RISCV::getImplicitAddend(const uint8_t *buf, RelType type) const { + switch (type) { + default: + internalLinkerError(getErrorLocation(buf), + "cannot read addend for relocation " + toString(type)); + return 0; + case R_RISCV_32: + case R_RISCV_TLS_DTPMOD32: + case R_RISCV_TLS_DTPREL32: + return SignExtend64<32>(read32le(buf)); + case R_RISCV_64: + return read64le(buf); + case R_RISCV_RELATIVE: + case R_RISCV_IRELATIVE: + return config->is64 ? read64le(buf) : read32le(buf); + case R_RISCV_NONE: + case R_RISCV_JUMP_SLOT: + return 0; // The stored value at this location is not the addend. + } +} + void RISCV::writeGotHeader(uint8_t *buf) const { if (config->is64) write64le(buf, mainPart->dynamic->getVA()); diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1385,8 +1385,8 @@ // enable the debug checks for all targets, but currently not all targets // have support for reading Elf_Rel addends, so we only enable for a subset. #ifndef NDEBUG - bool checkDynamicRelocsDefault = - m == EM_ARM || m == EM_386 || m == EM_MIPS || m == EM_X86_64; + bool checkDynamicRelocsDefault = m == EM_ARM || m == EM_386 || m == EM_MIPS || + m == EM_X86_64 || m == EM_RISCV; #else bool checkDynamicRelocsDefault = false; #endif