1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[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
This commit is contained in:
Sam Clegg 2018-12-12 23:40:58 +00:00
parent 67f6f7b2b0
commit 3d9006eb4f
8 changed files with 20 additions and 0 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -195,6 +195,7 @@ struct DylinkSection : CustomSection {
uint32_t MemoryAlignment;
uint32_t TableSize;
uint32_t TableAlignment;
std::vector<StringRef> Needed;
};
struct NameSection : CustomSection {

View File

@ -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];

View File

@ -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) {

View File

@ -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: ...

View File

@ -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 =

View File

@ -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;
}