summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/BinaryFormat/Wasm.h5
-rw-r--r--llvm/include/llvm/Object/Wasm.h2
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp17
-rw-r--r--llvm/tools/obj2yaml/wasm2yaml.cpp16
4 files changed, 20 insertions, 20 deletions
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h
index eab1a546f36..e1a872c8ad5 100644
--- a/llvm/include/llvm/BinaryFormat/Wasm.h
+++ b/llvm/include/llvm/BinaryFormat/Wasm.h
@@ -101,7 +101,7 @@ struct WasmFunction {
uint32_t CodeSectionOffset;
uint32_t Size;
StringRef Name; // from the "linking" or "names" section
- StringRef Comdat; // from the "comdat info" section
+ uint32_t Comdat; // from the "comdat info" section
};
struct WasmDataSegment {
@@ -111,7 +111,7 @@ struct WasmDataSegment {
StringRef Name;
uint32_t Alignment;
uint32_t Flags;
- StringRef Comdat; // from the "comdat info" section
+ uint32_t Comdat; // from the "comdat info" section
};
struct WasmElemSegment {
@@ -160,6 +160,7 @@ struct WasmFunctionName {
struct WasmLinkingData {
std::vector<WasmInitFunc> InitFunctions;
+ std::vector<StringRef> Comdats;
std::vector<WasmSymbolInfo> SymbolTable;
};
diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h
index 5c2fee2dd3f..d49acf3a38a 100644
--- a/llvm/include/llvm/Object/Wasm.h
+++ b/llvm/include/llvm/Object/Wasm.h
@@ -141,7 +141,6 @@ public:
ArrayRef<wasm::WasmElemSegment> elements() const { return ElemSegments; }
ArrayRef<WasmSegment> dataSegments() const { return DataSegments; }
ArrayRef<wasm::WasmFunction> functions() const { return Functions; }
- ArrayRef<StringRef> comdats() const { return Comdats; }
ArrayRef<wasm::WasmFunctionName> debugNames() const { return DebugNames; }
uint32_t startFunction() const { return StartFunction; }
uint32_t getNumImportedGlobals() const { return NumImportedGlobals; }
@@ -255,7 +254,6 @@ private:
std::vector<WasmSegment> DataSegments;
std::vector<wasm::WasmFunction> Functions;
std::vector<WasmSymbol> Symbols;
- std::vector<StringRef> Comdats;
std::vector<wasm::WasmFunctionName> DebugNames;
uint32_t StartFunction = -1;
bool HasLinkingSection = false;
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 65ae0639d4f..0c78631da25 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -485,12 +485,12 @@ Error WasmObjectFile::parseLinkingSectionComdat(const uint8_t *&Ptr,
{
uint32_t ComdatCount = readVaruint32(Ptr);
StringSet<> ComdatSet;
- while (ComdatCount--) {
+ for (unsigned ComdatIndex = 0; ComdatIndex < ComdatCount; ++ComdatIndex) {
StringRef Name = readString(Ptr);
if (Name.empty() || !ComdatSet.insert(Name).second)
return make_error<GenericBinaryError>("Bad/duplicate COMDAT name " + Twine(Name),
object_error::parse_failed);
- Comdats.emplace_back(Name);
+ LinkingData.Comdats.emplace_back(Name);
uint32_t Flags = readVaruint32(Ptr);
if (Flags != 0)
return make_error<GenericBinaryError>("Unsupported COMDAT flags",
@@ -508,19 +508,19 @@ Error WasmObjectFile::parseLinkingSectionComdat(const uint8_t *&Ptr,
if (Index >= DataSegments.size())
return make_error<GenericBinaryError>("COMDAT data index out of range",
object_error::parse_failed);
- if (!DataSegments[Index].Data.Comdat.empty())
+ if (DataSegments[Index].Data.Comdat != UINT32_MAX)
return make_error<GenericBinaryError>("Data segment in two COMDATs",
object_error::parse_failed);
- DataSegments[Index].Data.Comdat = Name;
+ DataSegments[Index].Data.Comdat = ComdatIndex;
break;
case wasm::WASM_COMDAT_FUNCTION:
if (!isDefinedFunctionIndex(Index))
return make_error<GenericBinaryError>("COMDAT function index out of range",
object_error::parse_failed);
- if (!getDefinedFunction(Index).Comdat.empty())
+ if (getDefinedFunction(Index).Comdat != UINT32_MAX)
return make_error<GenericBinaryError>("Function in two COMDATs",
object_error::parse_failed);
- getDefinedFunction(Index).Comdat = Name;
+ getDefinedFunction(Index).Comdat = ComdatIndex;
break;
}
}
@@ -878,6 +878,8 @@ Error WasmObjectFile::parseCodeSection(const uint8_t *Ptr, const uint8_t *End) {
uint32_t BodySize = FunctionEnd - Ptr;
Function.Body = ArrayRef<uint8_t>(Ptr, BodySize);
+ // This will be set later when reading in the linking metadata section.
+ Function.Comdat = UINT32_MAX;
Ptr += BodySize;
assert(Ptr == FunctionEnd);
Functions.push_back(Function);
@@ -924,8 +926,11 @@ Error WasmObjectFile::parseDataSection(const uint8_t *Ptr, const uint8_t *End) {
return Err;
uint32_t Size = readVaruint32(Ptr);
Segment.Data.Content = ArrayRef<uint8_t>(Ptr, Size);
+ // The rest of these Data fields are set later, when reading in the linking
+ // metadata section.
Segment.Data.Alignment = 0;
Segment.Data.Flags = 0;
+ Segment.Data.Comdat = UINT32_MAX;
Segment.SectionOffset = Ptr - Start;
Ptr += Size;
DataSegments.push_back(Segment);
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp
index 1abd7b8702e..29bf9b5e25e 100644
--- a/llvm/tools/obj2yaml/wasm2yaml.cpp
+++ b/llvm/tools/obj2yaml/wasm2yaml.cpp
@@ -62,15 +62,12 @@ std::unique_ptr<WasmYAML::CustomSection> WasmDumper::dumpCustomSection(const Was
CustomSec = std::move(NameSec);
} else if (WasmSec.Name == "linking") {
std::unique_ptr<WasmYAML::LinkingSection> LinkingSec = make_unique<WasmYAML::LinkingSection>();
- std::map<StringRef,size_t> ComdatIndexes;
- for (StringRef ComdatName : Obj.comdats()) {
- ComdatIndexes[ComdatName] = LinkingSec->Comdats.size();
+ ArrayRef<StringRef> Comdats = Obj.linkingData().Comdats;
+ for (StringRef ComdatName : Comdats)
LinkingSec->Comdats.emplace_back(WasmYAML::Comdat{ComdatName, {}});
- }
for (auto &Func : Obj.functions()) {
- if (!Func.Comdat.empty()) {
- auto &Comdat = LinkingSec->Comdats[ComdatIndexes[Func.Comdat]];
- Comdat.Entries.emplace_back(
+ if (Func.Comdat != UINT32_MAX) {
+ LinkingSec->Comdats[Func.Comdat].Entries.emplace_back(
WasmYAML::ComdatEntry{wasm::WASM_COMDAT_FUNCTION, Func.Index});
}
}
@@ -84,9 +81,8 @@ std::unique_ptr<WasmYAML::CustomSection> WasmDumper::dumpCustomSection(const Was
SegmentInfo.Flags = Segment.Data.Flags;
LinkingSec->SegmentInfos.push_back(SegmentInfo);
}
- if (!Segment.Data.Comdat.empty()) {
- auto &Comdat = LinkingSec->Comdats[ComdatIndexes[Segment.Data.Comdat]];
- Comdat.Entries.emplace_back(
+ if (Segment.Data.Comdat != UINT32_MAX) {
+ LinkingSec->Comdats[Segment.Data.Comdat].Entries.emplace_back(
WasmYAML::ComdatEntry{wasm::WASM_COMDAT_DATA, SegmentIndex});
}
SegmentIndex++;
OpenPOWER on IntegriCloud