[llvm] r332005 - [WebAssembly] Create section start symbols automatically for all sections
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu May 10 10:38:35 PDT 2018
Author: sbc
Date: Thu May 10 10:38:35 2018
New Revision: 332005
URL: http://llvm.org/viewvc/llvm-project?rev=332005&view=rev
Log:
[WebAssembly] Create section start symbols automatically for all sections
These symbols only get included in the output symbols table if
they are used in a relocation.
This behaviour matches more closely the ELF object writer.
Differential Revision: https://reviews.llvm.org/D46561
Modified:
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCObjectFileInfo.cpp
llvm/trunk/lib/MC/MCWasmStreamer.cpp
llvm/trunk/lib/MC/WasmObjectWriter.cpp
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=332005&r1=332004&r2=332005&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu May 10 10:38:35 2018
@@ -515,15 +515,18 @@ MCSectionWasm *MCContext::getWasmSection
StringRef CachedName = Entry.first.SectionName;
- MCSymbol *Begin = nullptr;
- if (BeginSymName) {
- Begin = createSymbol(BeginSymName, false, false);
- cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
- }
+ MCSymbol *Begin = createSymbol(CachedName, false, false);
+ cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
MCSectionWasm *Result = new (WasmAllocator.Allocate())
MCSectionWasm(CachedName, Kind, GroupSym, UniqueID, Begin);
Entry.second = Result;
+
+ auto *F = new MCDataFragment();
+ Result->getFragmentList().insert(Result->begin(), F);
+ F->setParent(Result);
+ Begin->setFragment(F);
+
return Result;
}
Modified: llvm/trunk/lib/MC/MCObjectFileInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectFileInfo.cpp?rev=332005&r1=332004&r2=332005&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectFileInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectFileInfo.cpp Thu May 10 10:38:35 2018
@@ -861,27 +861,29 @@ void MCObjectFileInfo::initCOFFMCObjectF
}
void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
- // TODO: Set the section types and flags.
TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
- // TODO: Set the section types and flags.
- DwarfLineSection = Ctx->getWasmSection(".debug_line", SectionKind::getMetadata(), ".debug_line");
+ DwarfLineSection =
+ Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
DwarfLineStrSection =
Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
- DwarfStrSection = Ctx->getWasmSection(".debug_str", SectionKind::getMetadata(), ".debug_str");
- DwarfLocSection = Ctx->getWasmSection(
- ".debug_loc", SectionKind::getMetadata(), ".debug_loc");
- DwarfAbbrevSection = Ctx->getWasmSection(
- ".debug_abbrev", SectionKind::getMetadata(), ".debug_abbrev");
+ DwarfStrSection =
+ Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
+ DwarfLocSection =
+ Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
+ DwarfAbbrevSection =
+ Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
- DwarfRangesSection = Ctx->getWasmSection(
- ".debug_ranges", SectionKind::getMetadata(), ".debug_ranges");
- DwarfMacinfoSection = Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata(), ".debug_macinfo");
+ DwarfRangesSection =
+ Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
+ DwarfMacinfoSection =
+ Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
- DwarfInfoSection = Ctx->getWasmSection(".debug_info", SectionKind::getMetadata(), ".debug_info");
+ DwarfInfoSection =
+ Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
Modified: llvm/trunk/lib/MC/MCWasmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWasmStreamer.cpp?rev=332005&r1=332004&r2=332005&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWasmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCWasmStreamer.cpp Thu May 10 10:38:35 2018
@@ -66,6 +66,7 @@ void MCWasmStreamer::ChangeSection(MCSec
Asm.registerSymbol(*Grp);
this->MCObjectStreamer::ChangeSection(Section, Subsection);
+ Asm.registerSymbol(*Section->getBeginSymbol());
}
void MCWasmStreamer::EmitWeakReference(MCSymbol *Alias,
Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=332005&r1=332004&r2=332005&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Thu May 10 10:38:35 2018
@@ -1204,9 +1204,9 @@ void WasmObjectWriter::writeObject(MCAss
MCSymbol* Begin = Sec.getBeginSymbol();
if (Begin) {
WasmIndices[cast<MCSymbolWasm>(Begin)] = CustomSections.size();
- if (Name != Begin->getName())
+ if (SectionName != Begin->getName())
report_fatal_error("section name and begin symbol should match: " +
- Twine(Name));
+ Twine(SectionName));
}
CustomSections.emplace_back(Name, &Section);
}
@@ -1405,16 +1405,27 @@ void WasmObjectWriter::writeObject(MCAss
continue;
if (WS.getFragmentList().empty())
continue;
- if (WS.getFragmentList().size() != 2)
+
+ // init_array is expected to contain a single non-empty data fragment
+ if (WS.getFragmentList().size() != 3)
report_fatal_error("only one .init_array section fragment supported");
- const MCFragment &AlignFrag = *WS.begin();
+
+ auto IT = WS.begin();
+ const MCFragment &EmptyFrag = *IT;
+ if (EmptyFrag.getKind() != MCFragment::FT_Data)
+ report_fatal_error(".init_array section should be aligned");
+
+ IT = std::next(IT);
+ const MCFragment &AlignFrag = *IT;
if (AlignFrag.getKind() != MCFragment::FT_Align)
report_fatal_error(".init_array section should be aligned");
if (cast<MCAlignFragment>(AlignFrag).getAlignment() != (is64Bit() ? 8 : 4))
report_fatal_error(".init_array section should be aligned for pointers");
- const MCFragment &Frag = *std::next(WS.begin());
+
+ const MCFragment &Frag = *std::next(IT);
if (Frag.hasInstructions() || Frag.getKind() != MCFragment::FT_Data)
report_fatal_error("only data supported in .init_array section");
+
uint16_t Priority = UINT16_MAX;
unsigned PrefixLength = strlen(".init_array");
if (WS.getSectionName().size() > PrefixLength) {
More information about the llvm-commits
mailing list