[PATCH] D41038: [WebAssembly] Preserve ordering of global symbols

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 15:22:03 PST 2017


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.

This change restores the behaviour that global indexes
are assigned in object file order.  This was accidentally
changed in https://reviews.llvm.org/D40859.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D41038

Files:
  test/wasm/data-layout.ll
  wasm/Writer.cpp


Index: wasm/Writer.cpp
===================================================================
--- wasm/Writer.cpp
+++ wasm/Writer.cpp
@@ -614,18 +614,16 @@
   for (ObjFile *File : Symtab->ObjectFiles) {
     DEBUG(dbgs() << "assignSymbolIndexes: " << File->getName() << "\n");
     for (Symbol *Sym : File->getSymbols()) {
-      if (Sym->hasOutputIndex() || !Sym->isDefined())
-        continue;
-
-      if (Sym->isFunction()) {
-        if (Sym->getFile() && isa<ObjFile>(Sym->getFile())) {
+      // Assign indexes for symbols defined with this file.
+      if (Sym->isDefined() && File == Sym->getFile()) {
+        if (Sym->isFunction()) {
           auto *Obj = cast<ObjFile>(Sym->getFile());
           Sym->setOutputIndex(Obj->FunctionIndexOffset +
                               Sym->getFunctionIndex());
+        } else if (Config->EmitRelocs) {
+          DefinedGlobals.emplace_back(Sym);
+          Sym->setOutputIndex(GlobalIndex++);
         }
-      } else if (Config->EmitRelocs) {
-        DefinedGlobals.emplace_back(Sym);
-        Sym->setOutputIndex(GlobalIndex++);
       }
     }
   }
Index: test/wasm/data-layout.ll
===================================================================
--- test/wasm/data-layout.ll
+++ test/wasm/data-layout.ll
@@ -20,27 +20,27 @@
 ; CHECK-NEXT:         Mutable:         false
 ; CHECK-NEXT:         InitExpr:
 ; CHECK-NEXT:           Opcode:          I32_CONST
-; CHECK-NEXT:           Value:           1052
+; CHECK-NEXT:           Value:           1024
 ; CHECK-NEXT:       - Type:            I32
 ; CHECK-NEXT:         Mutable:         false
 ; CHECK-NEXT:         InitExpr:
 ; CHECK-NEXT:           Opcode:          I32_CONST
-; CHECK-NEXT:           Value:           1024
+; CHECK-NEXT:           Value:           1040
 ; CHECK-NEXT:       - Type:            I32
 ; CHECK-NEXT:         Mutable:         false
 ; CHECK-NEXT:         InitExpr:
 ; CHECK-NEXT:           Opcode:          I32_CONST
-; CHECK-NEXT:           Value:           1040
+; CHECK-NEXT:           Value:           1048
 ; CHECK-NEXT:       - Type:            I32
 ; CHECK-NEXT:         Mutable:         false
 ; CHECK-NEXT:         InitExpr:
 ; CHECK-NEXT:           Opcode:          I32_CONST
-; CHECK-NEXT:           Value:           1048
+; CHECK-NEXT:           Value:           1052
 
 ; CHECK:       - Type:            DATA
 ; CHECK-NEXT:     Relocations:
 ; CHECK-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_I32
-; CHECK-NEXT:         Index:           1
+; CHECK-NEXT:         Index:           4
 ; CHECK-NEXT:         Offset:          0x0000001F
 ; CHECK-NEXT:     Segments:
 ; CHECK-NEXT:       - SectionOffset:   7


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41038.126224.patch
Type: text/x-patch
Size: 2666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171208/25497a44/attachment.bin>


More information about the llvm-commits mailing list