[lld] [lld][WebAssembly] Fix relocation of Wasm table index with GOT access (PR #104043)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 12:49:35 PDT 2024


================
@@ -102,13 +102,27 @@ void scanRelocations(InputChunk *chunk) {
     switch (reloc.Type) {
     case R_WASM_TABLE_INDEX_I32:
     case R_WASM_TABLE_INDEX_I64:
+      // These relocations target the data section and are handled
+      // by `generateRelocationCode`. GOT accesses are handled below.
+      if (requiresGOTAccess(sym))
+        break;
+      out.elemSec->addEntry(cast<FunctionSymbol>(sym));
+      break;
     case R_WASM_TABLE_INDEX_SLEB:
     case R_WASM_TABLE_INDEX_SLEB64:
     case R_WASM_TABLE_INDEX_REL_SLEB:
     case R_WASM_TABLE_INDEX_REL_SLEB64:
-      if (requiresGOTAccess(sym))
-        break;
-      out.elemSec->addEntry(cast<FunctionSymbol>(sym));
+      // These relocations target the code section and can only be resolved
+      // at linking time.
----------------
sbc100 wrote:

I'm not sure I understand `can only be resolved at linking time`.  Isn't that true of all relocations?   If they could be resolved at compile time then we would use a relocation at all, no?

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


More information about the llvm-commits mailing list