[lld] [lld][LoongArch] Support the R_LARCH_{ADD,SUB}_ULEB128 relocation types (PR #81133)

Jinyang He via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 00:13:33 PST 2024


================
@@ -153,6 +154,20 @@ static bool isJirl(uint32_t insn) {
   return (insn & 0xfc000000) == JIRL;
 }
 
+static void handleUleb128(uint8_t *loc, uint64_t val) {
+  const uint32_t maxcount = 1 + (config->is64 ? 64 : 32) / 7;
+  uint32_t count;
+  uint64_t orig = decodeULEB128(loc, &count);
+  if (count > maxcount)
+    errorOrWarn(getErrorLocation(loc) + "extra space for uleb128");
+  uint64_t mask = config->is64 ? -1 : -1u;
----------------
MQ-mengqing wrote:

I can add the same test as a.o for 32-bit.

`uleb128(-1u) == 0x0f'ff'ff'ff'ff`. Assuming it reserved 5 bytes space and we executing SUB -1 on 32-bit first, then without this mask we might get 0x7f'ff'ff'ff'ff, which [35:33] is 1. These relocations is relocated address, and address should be limited in 32-bit on ELF32. So we need this mask to avoid breaking the high-space.

https://github.com/llvm/llvm-project/pull/81133


More information about the llvm-commits mailing list