[ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for Hexagon

This commit is contained in:
Fangrui Song 2023-09-15 23:10:17 -07:00
parent 693aa68b65
commit 71d7e69c56
2 changed files with 23 additions and 4 deletions

View File

@ -29,6 +29,7 @@ public:
RelExpr getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const override;
RelType getDynRel(RelType type) const override;
int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;
void relocate(uint8_t *loc, const Relocation &rel,
uint64_t val) const override;
void writePltHeader(uint8_t *buf) const override;
@ -386,6 +387,25 @@ RelType Hexagon::getDynRel(RelType type) const {
return R_HEX_NONE;
}
int64_t Hexagon::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
case R_HEX_NONE:
case R_HEX_GLOB_DAT:
case R_HEX_JMP_SLOT:
return 0;
case R_HEX_32:
case R_HEX_RELATIVE:
case R_HEX_DTPMOD_32:
case R_HEX_DTPREL_32:
case R_HEX_TPREL_32:
return SignExtend64<32>(read32(buf));
default:
internalLinkerError(getErrorLocation(buf),
"cannot read addend for relocation " + toString(type));
return 0;
}
}
TargetInfo *elf::getHexagonTargetInfo() {
static Hexagon target;
return &target;

View File

@ -1709,11 +1709,10 @@ static void setConfigs(opt::InputArgList &args) {
OPT_no_apply_dynamic_relocs, false) ||
!config->isRela;
// Validation of dynamic relocation addends is on by default for assertions
// builds (for supported targets) and disabled otherwise. Ideally we would
// 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.
// builds and disabled otherwise. This check is enabled when writeAddends is
// true.
#ifndef NDEBUG
bool checkDynamicRelocsDefault = m != EM_HEXAGON;
bool checkDynamicRelocsDefault = true;
#else
bool checkDynamicRelocsDefault = false;
#endif