[lld] [lld][WebAssembly] Report Unsupported PIC Relocations as Errors (PR #104926)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 17:11:14 PDT 2024


================
@@ -170,6 +170,19 @@ void scanRelocations(InputChunk *chunk) {
         if (requiresGOTAccess(sym))
           addGOTEntry(sym);
         break;
+      case R_WASM_TABLE_INDEX_REL_SLEB:
+      case R_WASM_TABLE_INDEX_REL_SLEB64:
+      case R_WASM_MEMORY_ADDR_REL_SLEB:
+      case R_WASM_MEMORY_ADDR_REL_SLEB64:
+        // These relocation types are only present in the code section and
+        // are not supported. It would require replacing the constant by using
+        // a GOT global.
+        if (sym->isUndefined())
+          error(toString(file) + ": relocation " +
+                relocTypeToString(reloc.Type) +
+                " is not supported against an undefined symbol `" +
+                toString(*sym) + "`");
+        break;
----------------
sbc100 wrote:

The above condition looks wrong for this block.   Shouldn't this be just guarded by `sym->isUndefined()` and nothing else?

We don't want to be reporting here is here for defined symbols in PIC mode (for example).    In fact, IIUC, these `REL` relocations are specifically designed for PIC mode.

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


More information about the llvm-commits mailing list