[llvm] r348989 - [WebAssembly] Update dylink section parsing

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 12 15:40:59 PST 2018


Author: sbc
Date: Wed Dec 12 15:40:58 2018
New Revision: 348989

URL: http://llvm.org/viewvc/llvm-project?rev=348989&view=rev
Log:
[WebAssembly] Update dylink section parsing

This updates the format of the dylink section in accordance with
recent "spec" change:
  https://github.com/WebAssembly/tool-conventions/pull/77

Differential Revision: https://reviews.llvm.org/D55609

Modified:
    llvm/trunk/include/llvm/BinaryFormat/Wasm.h
    llvm/trunk/include/llvm/Object/Wasm.h
    llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h
    llvm/trunk/lib/Object/WasmObjectFile.cpp
    llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
    llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml
    llvm/trunk/tools/obj2yaml/wasm2yaml.cpp
    llvm/trunk/tools/yaml2obj/yaml2wasm.cpp

Modified: llvm/trunk/include/llvm/BinaryFormat/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Wasm.h?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Wasm.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h Wed Dec 12 15:40:58 2018
@@ -40,6 +40,7 @@ struct WasmDylinkInfo {
   uint32_t MemoryAlignment;  // P2 alignment of memory
   uint32_t TableSize;  // Table size in elements
   uint32_t TableAlignment;  // P2 alignment of table
+  std::vector<StringRef> Needed; // Shared library depenedencies
 };
 
 struct WasmExport {

Modified: llvm/trunk/include/llvm/Object/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Wasm.h?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Wasm.h (original)
+++ llvm/trunk/include/llvm/Object/Wasm.h Wed Dec 12 15:40:58 2018
@@ -201,6 +201,7 @@ public:
   Triple::ArchType getArch() const override;
   SubtargetFeatures getFeatures() const override;
   bool isRelocatableObject() const override;
+  bool isSharedObject() const;
 
   struct ReadContext {
     const uint8_t *Start;
@@ -271,6 +272,7 @@ private:
   std::vector<wasm::WasmFunctionName> DebugNames;
   uint32_t StartFunction = -1;
   bool HasLinkingSection = false;
+  bool HasDylinkSection = false;
   wasm::WasmLinkingData LinkingData;
   uint32_t NumImportedGlobals = 0;
   uint32_t NumImportedFunctions = 0;

Modified: llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/WasmYAML.h Wed Dec 12 15:40:58 2018
@@ -195,6 +195,7 @@ struct DylinkSection : CustomSection {
   uint32_t MemoryAlignment;
   uint32_t TableSize;
   uint32_t TableAlignment;
+  std::vector<StringRef> Needed;
 };
 
 struct NameSection : CustomSection {

Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Wed Dec 12 15:40:58 2018
@@ -319,6 +319,10 @@ Error WasmObjectFile::parseDylinkSection
   DylinkInfo.MemoryAlignment = readVaruint32(Ctx);
   DylinkInfo.TableSize = readVaruint32(Ctx);
   DylinkInfo.TableAlignment = readVaruint32(Ctx);
+  uint32_t Count = readVaruint32(Ctx);
+  while (Count--) {
+    DylinkInfo.Needed.push_back(readString(Ctx));
+  }
   if (Ctx.Ptr != Ctx.End)
     return make_error<GenericBinaryError>("dylink section ended prematurely",
                                           object_error::parse_failed);
@@ -1405,6 +1409,8 @@ SubtargetFeatures WasmObjectFile::getFea
 
 bool WasmObjectFile::isRelocatableObject() const { return HasLinkingSection; }
 
+bool WasmObjectFile::isSharedObject() const { return HasDylinkSection; }
+
 const WasmSection &WasmObjectFile::getWasmSection(DataRefImpl Ref) const {
   assert(Ref.d.a < Sections.size());
   return Sections[Ref.d.a];

Modified: llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/WasmYAML.cpp?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/WasmYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/WasmYAML.cpp Wed Dec 12 15:40:58 2018
@@ -55,6 +55,7 @@ static void sectionMapping(IO &IO, WasmY
   IO.mapRequired("MemoryAlignment", Section.MemoryAlignment);
   IO.mapRequired("TableSize", Section.TableSize);
   IO.mapRequired("TableAlignment", Section.TableAlignment);
+  IO.mapRequired("Needed", Section.Needed);
 }
 
 static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) {

Modified: llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml (original)
+++ llvm/trunk/test/ObjectYAML/wasm/dylink_section.yaml Wed Dec 12 15:40:58 2018
@@ -10,6 +10,7 @@ Sections:
     MemoryAlignment: 2
     TableSize:       1
     TableAlignment:  0
+    Needed:          [ libfoo.so, libbar.so ]
 ...
 # CHECK: --- !WASM
 # CHECK: FileHeader:
@@ -21,4 +22,7 @@ Sections:
 # CHECK:     MemoryAlignment: 2
 # CHECK:     TableSize:       1
 # CHECK:     TableAlignment:  0
+# CHECK:     Needed:
+# CHECK:       - libfoo.so
+# CHECK:       - libbar.so
 # CHECK: ...

Modified: llvm/trunk/tools/obj2yaml/wasm2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/wasm2yaml.cpp?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/wasm2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/wasm2yaml.cpp Wed Dec 12 15:40:58 2018
@@ -60,6 +60,7 @@ WasmDumper::dumpCustomSection(const Wasm
     DylinkSec->MemoryAlignment = Info.MemoryAlignment;
     DylinkSec->TableSize = Info.TableSize;
     DylinkSec->TableAlignment = Info.TableAlignment;
+    DylinkSec->Needed = Info.Needed;
     CustomSec = std::move(DylinkSec);
   } else if (WasmSec.Name == "name") {
     std::unique_ptr<WasmYAML::NameSection> NameSec =

Modified: llvm/trunk/tools/yaml2obj/yaml2wasm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2wasm.cpp?rev=348989&r1=348988&r2=348989&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2wasm.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2wasm.cpp Wed Dec 12 15:40:58 2018
@@ -140,6 +140,10 @@ int WasmWriter::writeSectionContent(raw_
   encodeULEB128(Section.MemoryAlignment, OS);
   encodeULEB128(Section.TableSize, OS);
   encodeULEB128(Section.TableAlignment, OS);
+  encodeULEB128(Section.Needed.size(), OS);
+  for (StringRef Needed : Section.Needed) {
+    writeStringRef(Needed, OS);
+  }
   return 0;
 }
 




More information about the llvm-commits mailing list