[PATCH] D61800: [WebAssembly] Refactor relocation processing. NFC.

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 13 09:40:33 PDT 2019


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL360598: [WebAssembly] Refactor relocation processing. NFC. (authored by sbc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61800?vs=199059&id=199282#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61800/new/

https://reviews.llvm.org/D61800

Files:
  lld/trunk/wasm/Writer.cpp


Index: lld/trunk/wasm/Writer.cpp
===================================================================
--- lld/trunk/wasm/Writer.cpp
+++ lld/trunk/wasm/Writer.cpp
@@ -1152,35 +1152,38 @@
   ObjFile *File = Chunk->File;
   ArrayRef<WasmSignature> Types = File->getWasmObj()->types();
   for (const WasmRelocation &Reloc : Chunk->getRelocations()) {
+    if (Reloc.Type == R_WASM_TYPE_INDEX_LEB) {
+      // Mark target type as live
+      File->TypeMap[Reloc.Index] = registerType(Types[Reloc.Index]);
+      File->TypeIsUsed[Reloc.Index] = true;
+      continue;
+    }
+
+    // Other relocation types all have a corresponding symbol
+    auto *Sym = File->getSymbols()[Reloc.Index];
     switch (Reloc.Type) {
     case R_WASM_TABLE_INDEX_I32:
     case R_WASM_TABLE_INDEX_SLEB:
     case R_WASM_TABLE_INDEX_REL_SLEB: {
-      FunctionSymbol *Sym = File->getFunctionSymbol(Reloc.Index);
-      if (Sym->hasTableIndex() || !Sym->hasFunctionIndex() || requiresGOTAccess(Sym))
+      auto *F = cast<FunctionSymbol>(Sym);
+      if (F->hasTableIndex() || !F->hasFunctionIndex() || requiresGOTAccess(F))
         break;
-      Sym->setTableIndex(TableBase + IndirectFunctions.size());
-      IndirectFunctions.emplace_back(Sym);
+      F->setTableIndex(TableBase + IndirectFunctions.size());
+      IndirectFunctions.emplace_back(F);
       break;
     }
     case R_WASM_TYPE_INDEX_LEB:
-      // Mark target type as live
-      File->TypeMap[Reloc.Index] = registerType(Types[Reloc.Index]);
-      File->TypeIsUsed[Reloc.Index] = true;
       break;
-    case R_WASM_GLOBAL_INDEX_LEB: {
-      auto* Sym = File->getSymbols()[Reloc.Index];
+    case R_WASM_GLOBAL_INDEX_LEB:
       if (!isa<GlobalSymbol>(Sym) && !Sym->isInGOT()) {
         Sym->setGOTIndex(NumImportedGlobals++);
         GOTSymbols.push_back(Sym);
       }
       break;
-    }
     case R_WASM_MEMORY_ADDR_SLEB:
     case R_WASM_MEMORY_ADDR_LEB:
-    case R_WASM_MEMORY_ADDR_REL_SLEB: {
+    case R_WASM_MEMORY_ADDR_REL_SLEB:
       if (!Config->Relocatable) {
-        auto* Sym = File->getSymbols()[Reloc.Index];
         if (Sym->isUndefined() && !Sym->isWeak()) {
           error(toString(File) + ": cannot resolve relocation of type " +
                 relocTypeToString(Reloc.Type) +
@@ -1189,34 +1192,29 @@
       }
       break;
     }
-    }
 
     if (Config->Pic) {
       switch (Reloc.Type) {
       case R_WASM_TABLE_INDEX_SLEB:
       case R_WASM_MEMORY_ADDR_SLEB:
-      case R_WASM_MEMORY_ADDR_LEB: {
+      case R_WASM_MEMORY_ADDR_LEB:
         // Certain relocation types can't be used when building PIC output, since
         // they would require absolute symbol addresses at link time.
-        Symbol *Sym = File->getSymbols()[Reloc.Index];
         error(toString(File) + ": relocation " +
               relocTypeToString(Reloc.Type) + " cannot be used againt symbol " +
               toString(*Sym) + "; recompile with -fPIC");
         break;
-      }
       case R_WASM_TABLE_INDEX_I32:
-      case R_WASM_MEMORY_ADDR_I32: {
+      case R_WASM_MEMORY_ADDR_I32:
         // These relocation types are only present in the data section and
         // will be converted into code by `generateRelocationCode`.  This code
         // requires the symbols to have GOT entires.
-        auto* Sym = File->getSymbols()[Reloc.Index];
         if (requiresGOTAccess(Sym) && !Sym->isInGOT()) {
           Sym->setGOTIndex(NumImportedGlobals++);
           GOTSymbols.push_back(Sym);
         }
         break;
       }
-      }
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61800.199282.patch
Type: text/x-patch
Size: 3529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190513/f2081271/attachment.bin>


More information about the llvm-commits mailing list