[PATCH] D22589: [ELF] - Introduce output section description class for holding section command
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 20 13:46:55 PDT 2016
grimar created this revision.
grimar added a reviewer: ruiu.
grimar added subscribers: llvm-commits, grimar, evgeny777.
OutputSectionDescription represents the state of SectionKind linker script command.
Previously Phdrs and Filler were somewhere outside when at fact they are a part
of output section description:
https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description
That is the first patch to support "tree" view of LS.
https://reviews.llvm.org/D22589
Files:
ELF/LinkerScript.cpp
ELF/LinkerScript.h
Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -46,11 +46,16 @@
// SectionKind is a description of output section, like ".data :..."
enum SectionsCommandKind { SectionKind, AssignmentKind };
+struct OutputSectionDescription {
+ std::vector<StringRef> Phdrs;
+ std::vector<uint8_t> Filler;
+};
+
struct SectionsCommand {
SectionsCommandKind Kind;
std::vector<StringRef> Expr;
StringRef Name;
- std::vector<StringRef> Phdrs;
+ OutputSectionDescription Section;
};
struct PhdrsCommand {
@@ -65,9 +70,6 @@
// SECTIONS commands.
std::vector<SectionRule> Sections;
- // Section fill attribute for each section.
- llvm::StringMap<std::vector<uint8_t>> Filler;
-
// Used to assign addresses to sections.
std::vector<SectionsCommand> Commands;
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -402,10 +402,10 @@
template <class ELFT>
ArrayRef<uint8_t> LinkerScript<ELFT>::getFiller(StringRef Name) {
- auto I = Opt.Filler.find(Name);
- if (I == Opt.Filler.end())
- return {};
- return I->second;
+ for (SectionsCommand &Cmd : Opt.Commands)
+ if (Cmd.Kind == SectionKind && Cmd.Name == Name)
+ return Cmd.Section.Filler;
+ return {};
}
// Returns the index of the given section name in linker script
@@ -455,8 +455,9 @@
if (Cmd.Kind != SectionKind || Cmd.Name != Name)
continue;
+ OutputSectionDescription &OutSec = Cmd.Section;
std::vector<size_t> Indices;
- for (StringRef PhdrName : Cmd.Phdrs) {
+ for (StringRef PhdrName : OutSec.Phdrs) {
auto ItPhdr =
std::find_if(Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(),
[&](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; });
@@ -710,7 +711,7 @@
void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
Opt.Commands.push_back({SectionKind, {}, OutSec, {}});
- SectionsCommand &Cmd = Opt.Commands.back();
+ OutputSectionDescription &S = Opt.Commands.back().Section;
expect(":");
expect("{");
@@ -734,16 +735,16 @@
setError("unknown command " + Tok);
}
}
- Cmd.Phdrs = readOutputSectionPhdrs();
+ S.Phdrs = readOutputSectionPhdrs();
StringRef Tok = peek();
if (Tok.startswith("=")) {
if (!Tok.startswith("=0x")) {
setError("filler should be a hexadecimal value");
return;
}
Tok = Tok.substr(3);
- Opt.Filler[OutSec] = parseHex(Tok);
+ S.Filler = parseHex(Tok);
next();
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22589.64751.patch
Type: text/x-patch
Size: 2643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160720/1523dce3/attachment.bin>
More information about the llvm-commits
mailing list