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

Luc Blaeser via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 02:08:37 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.
+      if (requiresGOTAccess(sym)) {
+        addGOTEntry(sym);
+      }
----------------
luc-blaeser wrote:

Thank you. I refactored it (including other occurrences in the change).

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


More information about the llvm-commits mailing list