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

Lu Weining via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 18 02:29:56 PST 2024


================
@@ -153,6 +154,22 @@ static bool isJirl(uint32_t insn) {
   return (insn & 0xfc000000) == JIRL;
 }
 
+static void handleUleb128(uint8_t *loc, uint64_t val) {
+  const char *err = nullptr;
+  uint32_t count, maxcount = 1 + (config->is64 ? 64 : 32) / 7;
+  uint64_t mask = config->is64 ? -1 : -1;
+  uint64_t orig = decodeULEB128(loc, &count, nullptr, &err);
+  if (err)
+    fatal(getErrorLocation(loc) + "could not decode uleb128 value: " + err);
+  if (count > maxcount)
+    errorOrWarn(getErrorLocation(loc) + "extra space for uleb128");
+  else if (count < maxcount)
+    mask = (1 << 7 * count) - 1;
+
+  val = (orig + val) & mask;
----------------
SixWeining wrote:

Should we do overflow check for `(orig + val)`?

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


More information about the llvm-commits mailing list