[llvm] [WebAssembly] Add WebAssembly::Specifier (PR #133116)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 09:45:30 PDT 2025


================
@@ -66,31 +67,33 @@ unsigned WebAssemblyWasmObjectWriter::getRelocType(
     const MCValue &Target, const MCFixup &Fixup,
     const MCSectionWasm &FixupSection, bool IsLocRel) const {
   auto &SymA = cast<MCSymbolWasm>(*Target.getAddSym());
-  auto Spec = Target.getSpecifier();
+  auto Spec = WebAssembly::Specifier(Target.getSpecifier());
   switch (Spec) {
-  case MCSymbolRefExpr::VK_GOT:
-  case MCSymbolRefExpr::VK_WASM_GOT_TLS:
+  case WebAssembly::S_GOT:
+    SymA.setUsedInGOT();
     return wasm::R_WASM_GLOBAL_INDEX_LEB;
-  case MCSymbolRefExpr::VK_WASM_TBREL:
+  case WebAssembly::S_GOT_TLS:
+    SymA.setUsedInGOT();
+    SymA.setTLS();
----------------
MaskRay wrote:

ELF targets do this as well. Probably should think of `getRelocType` as a helper function of `recordFunction`; `getRelocType` might change states. I need to think about how to refactor ELFObjectWriter recordRelocation and make it clearer, but I think `SymA.setUsedInGOT();` as part as the relocation type decision code is the right direction.

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


More information about the llvm-commits mailing list