summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-12-12 23:40:58 +0000
committerSam Clegg <sbc@chromium.org>2018-12-12 23:40:58 +0000
commit03801256d86eb0d22dc7d489ed4ec0eec9ace6b6 (patch)
tree8dff16dade50cba59768a25aea61e4c691d7832b
parent744c3c327fbaa3548c4af62694e7c3eeca8b4f6f (diff)
downloadbcm5719-llvm-03801256d86eb0d22dc7d489ed4ec0eec9ace6b6.tar.gz
bcm5719-llvm-03801256d86eb0d22dc7d489ed4ec0eec9ace6b6.zip
[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 llvm-svn: 348989
-rw-r--r--llvm/include/llvm/BinaryFormat/Wasm.h1
-rw-r--r--llvm/include/llvm/Object/Wasm.h2
-rw-r--r--llvm/include/llvm/ObjectYAML/WasmYAML.h1
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp6
-rw-r--r--llvm/lib/ObjectYAML/WasmYAML.cpp1
-rw-r--r--llvm/test/ObjectYAML/wasm/dylink_section.yaml4
-rw-r--r--llvm/tools/obj2yaml/wasm2yaml.cpp1
-rw-r--r--llvm/tools/yaml2obj/yaml2wasm.cpp4
8 files changed, 20 insertions, 0 deletions
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h
index dc1cfd8e7b9..9b8ca28de66 100644
--- a/llvm/include/llvm/BinaryFormat/Wasm.h
+++ b/llvm/include/llvm/BinaryFormat/Wasm.h
@@ -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 {
diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h
index 902f8a49317..2edb93873da 100644
--- a/llvm/include/llvm/Object/Wasm.h
+++ b/llvm/include/llvm/Object/Wasm.h
@@ -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;
diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h
index e3fc030bc73..406dd7cb515 100644
--- a/llvm/include/llvm/ObjectYAML/WasmYAML.h
+++ b/llvm/include/llvm/ObjectYAML/WasmYAML.h
@@ -195,6 +195,7 @@ struct DylinkSection : CustomSection {
uint32_t MemoryAlignment;
uint32_t TableSize;
uint32_t TableAlignment;
+ std::vector<StringRef> Needed;
};
struct NameSection : CustomSection {
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 895d45c470f..1a687d94d7f 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -319,6 +319,10 @@ Error WasmObjectFile::parseDylinkSection(ReadContext &Ctx) {
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::getFeatures() const {
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];
diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp
index 2bc971a46b3..b97803340c0 100644
--- a/llvm/lib/ObjectYAML/WasmYAML.cpp
+++ b/llvm/lib/ObjectYAML/WasmYAML.cpp
@@ -55,6 +55,7 @@ static void sectionMapping(IO &IO, WasmYAML::DylinkSection &Section) {
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) {
diff --git a/llvm/test/ObjectYAML/wasm/dylink_section.yaml b/llvm/test/ObjectYAML/wasm/dylink_section.yaml
index ea9d03f9efe..9cc3f7d0a4e 100644
--- a/llvm/test/ObjectYAML/wasm/dylink_section.yaml
+++ b/llvm/test/ObjectYAML/wasm/dylink_section.yaml
@@ -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: ...
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp
index ebfe0781036..7581bbef50a 100644
--- a/llvm/tools/obj2yaml/wasm2yaml.cpp
+++ b/llvm/tools/obj2yaml/wasm2yaml.cpp
@@ -60,6 +60,7 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) {
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 =
diff --git a/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp
index 0809cc458ac..7fd0bb06934 100644
--- a/llvm/tools/yaml2obj/yaml2wasm.cpp
+++ b/llvm/tools/yaml2obj/yaml2wasm.cpp
@@ -140,6 +140,10 @@ int WasmWriter::writeSectionContent(raw_ostream &OS,
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;
}
OpenPOWER on IntegriCloud