[PATCH] D23352: [ELF] - Linkerscript: implemented simple heuristic for placing orphan sections.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 15 00:02:27 PDT 2016
grimar added inline comments.
================
Comment at: ELF/LinkerScript.cpp:276
@@ +275,3 @@
+
+ auto R = std::find_if(OutputSections->rbegin(), OutputSections->rend(),
+ [&](OutputSectionBase<ELFT> *S) {
----------------
ruiu wrote:
> Why do you have to use rbegin and rend?
I am searching the last section with the same access attributes to place orphan right after. So I had to search from the end to start.
I`ve added notes for each piece of code below.
================
Comment at: ELF/LinkerScript.cpp:279
@@ +278,3 @@
+ return getAccessFlags(S) == getAccessFlags(Orphan);
+ });
+
----------------
1) At first I search the last section with the attributes equal to atributes of orphan I am inserting.
================
Comment at: ELF/LinkerScript.cpp:286
@@ +285,3 @@
+ return;
+ }
+
----------------
2) If there is no section with the same attributes - I just add orphan to the end, also I create and add output section command either to the end.
================
Comment at: ELF/LinkerScript.cpp:289
@@ +288,3 @@
+ StringRef InsertAfter = (*R)->getName();
+ OutputSections->insert(R.base(), Orphan);
+
----------------
3. I add orphan to the position I found above and take the name of the section which goes before the orphan. This name is required to find the proper position for new OutputSectionCommand.
================
Comment at: ELF/LinkerScript.cpp:297
@@ +296,3 @@
+ });
+ ScriptConfig->Commands.emplace(I + 1, Cmd);
+}
----------------
Please see new notes above. That piece is:
4. Find the proper place for new OutputSectionCommand and add it. This position matches the position of orphan section added:
OutputSections content: Sec1 Sec2 **Oprhan **Sec4
ScriptConfig->Commands content: Cmd_Sec1 Cmd_Sec2 **Cmd_Orphan **Cmd_Sec4
https://reviews.llvm.org/D23352
More information about the llvm-commits
mailing list