[PATCH] D43940: [WebAssembly] Reorder reloc sections to come between symtab and name

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 2 09:03:30 PST 2018


ncw updated this revision to Diff 136767.
ncw retitled this revision from "[WebAssembly] Reorder reloc sections to come after symtab and validate section order" to "[WebAssembly] Reorder reloc sections to come between symtab and name".
ncw edited the summary of this revision.
ncw added a comment.

Updated to pull out all the validation stuff into another patch, this just reorders the output to be: linking,relocs,name.


Repository:
  rL LLVM

https://reviews.llvm.org/D43940

Files:
  lib/MC/WasmObjectWriter.cpp
  test/Object/Inputs/trivial-object-test.wasm
  test/tools/llvm-objdump/Inputs/trivial.obj.wasm
  test/tools/llvm-objdump/wasm.txt
  test/tools/llvm-readobj/Inputs/trivial.obj.wasm
  test/tools/llvm-readobj/sections.test
  tools/yaml2obj/yaml2wasm.cpp


Index: tools/yaml2obj/yaml2wasm.cpp
===================================================================
--- tools/yaml2obj/yaml2wasm.cpp
+++ tools/yaml2obj/yaml2wasm.cpp
@@ -459,16 +459,9 @@
   writeUint32(OS, Obj.Header.Version);
 
   // Write each section
-  uint32_t LastType = 0;
   for (const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
-    uint32_t Type = Sec->Type;
-    if (Type != wasm::WASM_SEC_CUSTOM) {
-      if (Type < LastType) {
-        errs() << "Out of order section type: " << Type << "\n";
-        return 1;
-      }
-      LastType = Type;
-    }
+    if (isa<WasmYAML::NameSection>(Sec.get()))
+      continue; // Write it out after the relocs
 
     encodeULEB128(Sec->Type, OS);
     std::string OutString;
@@ -535,6 +528,21 @@
     OS << OutString;
   }
 
+  // Write out the "name" section last, if any
+  for (const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
+    if (auto S = dyn_cast<WasmYAML::NameSection>(Sec.get())) {
+      encodeULEB128(Sec->Type, OS);
+      std::string OutString;
+      raw_string_ostream StringStream(OutString);
+      if (auto Err = writeSectionContent(StringStream, *S))
+        return Err;
+      StringStream.flush();
+
+      encodeULEB128(OutString.size(), OS);
+      OS << OutString;
+    }
+  }
+
   return 0;
 }
 
Index: test/tools/llvm-readobj/sections.test
===================================================================
--- test/tools/llvm-readobj/sections.test
+++ test/tools/llvm-readobj/sections.test
@@ -528,14 +528,14 @@
 WASM-NEXT:   }
 WASM-NEXT:   Section {
 WASM-NEXT:     Type: CUSTOM (0x0)
-WASM-NEXT:     Size: 23
+WASM-NEXT:     Size: 65
 WASM-NEXT:     Offset: 191
-WASM-NEXT:     Name: reloc.CODE
+WASM-NEXT:     Name: linking
 WASM-NEXT:   }
 WASM-NEXT:   Section {
 WASM-NEXT:     Type: CUSTOM (0x0)
-WASM-NEXT:     Size: 65
-WASM-NEXT:     Offset: 220
-WASM-NEXT:     Name: linking
+WASM-NEXT:     Size: 23
+WASM-NEXT:     Offset: 262
+WASM-NEXT:     Name: reloc.CODE
 WASM-NEXT:   }
 WASM-NEXT: ]
Index: test/tools/llvm-objdump/wasm.txt
===================================================================
--- test/tools/llvm-objdump/wasm.txt
+++ test/tools/llvm-objdump/wasm.txt
@@ -7,8 +7,8 @@
 # CHECK-NEXT:  2 FUNCTION      00000002 0000000000000000
 # CHECK-NEXT:  3 CODE          00000019 0000000000000000 TEXT
 # CHECK-NEXT:  4 DATA          0000001c 0000000000000000 DATA
-# CHECK-NEXT:  5 reloc.CODE    00000017 0000000000000000
-# CHECK-NEXT:  6 linking       00000055 0000000000000000
+# CHECK-NEXT:  5 linking       00000055 0000000000000000
+# CHECK-NEXT:  6 reloc.CODE    00000017 0000000000000000
 
 # RUN: llvm-objdump -p %p/Inputs/trivial.obj.wasm | FileCheck %s -check-prefix CHECK-HEADER
 
Index: lib/MC/WasmObjectWriter.cpp
===================================================================
--- lib/MC/WasmObjectWriter.cpp
+++ lib/MC/WasmObjectWriter.cpp
@@ -1307,9 +1307,9 @@
   writeElemSection(TableElems);
   writeCodeSection(Asm, Layout, Functions);
   writeDataSection();
+  writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats);
   writeCodeRelocSection();
   writeDataRelocSection();
-  writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats);
 
   // TODO: Translate the .comment section to the output.
   // TODO: Translate debug sections to the output.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43940.136767.patch
Type: text/x-patch
Size: 3321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/c59d9fbe/attachment.bin>


More information about the llvm-commits mailing list