[lld] 71d7e69 - [ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for Hexagon

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 23:10:21 PDT 2023


Author: Fangrui Song
Date: 2023-09-15T23:10:17-07:00
New Revision: 71d7e69c5611e416f34a4ee6223b951f3b0ceda2

URL: https://github.com/llvm/llvm-project/commit/71d7e69c5611e416f34a4ee6223b951f3b0ceda2
DIFF: https://github.com/llvm/llvm-project/commit/71d7e69c5611e416f34a4ee6223b951f3b0ceda2.diff

LOG: [ELF] Implement getImplicitAddend and enable checkDynamicRelocsDefault for Hexagon

Added: 
    

Modified: 
    lld/ELF/Arch/Hexagon.cpp
    lld/ELF/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index bc26653697c7899..54821c299bde9e2 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -29,6 +29,7 @@ class Hexagon final : public TargetInfo {
   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 ⌖

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index e08edc83d108f01..bf3516192df39e9 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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


        


More information about the llvm-commits mailing list