[PATCH] D23352: [ELF] - Linkerscript: implemented simple heuristic for placing orphan sections.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 14:48:00 PDT 2016


ruiu added inline comments.

================
Comment at: ELF/LinkerScript.cpp:257
@@ +256,3 @@
+template <class ELFT>
+static typename ELFT::uint getAccessFlags(OutputSectionBase<ELFT> *Sec) {
+  return Sec->getFlags() & (SHF_WRITE | SHF_ALLOC | SHF_EXECINSTR);
----------------
Let's name this `getPermissions` as this is RWX permissions.

================
Comment at: ELF/LinkerScript.cpp:270
@@ +269,3 @@
+  bool IsNew;
+  OutputSectionBase<ELFT> *Orphan;
+  std::tie(Orphan, IsNew) = Factory.create(C, OutputName);
----------------
Orphan sections are a concept of input sections. I don't think we call output sections containing orphan sections as orphan sections. So let's name this OutSec.

================
Comment at: ELF/LinkerScript.cpp:276
@@ +275,3 @@
+
+  auto R = std::find_if(OutputSections->rbegin(), OutputSections->rend(),
+                        [&](OutputSectionBase<ELFT> *S) {
----------------
Why do you have to use rbegin and rend?

================
Comment at: ELF/LinkerScript.cpp:281-297
@@ +280,19 @@
+
+  OutputSectionCommand *Cmd = new OutputSectionCommand(OutputName);
+  if (R == OutputSections->rend()) {
+    OutputSections->push_back(Orphan);
+    ScriptConfig->Commands.emplace_back(Cmd);
+    return;
+  }
+
+  StringRef InsertAfter = (*R)->getName();
+  OutputSections->insert(R.base(), Orphan);
+
+  auto I = llvm::find_if(
+      ScriptConfig->Commands, [&](std::unique_ptr<BaseCommand> &Base) {
+        if (auto *O = dyn_cast<OutputSectionCommand>(Base.get()))
+          return O->Name == InsertAfter;
+        return false;
+      });
+  ScriptConfig->Commands.emplace(I + 1, Cmd);
+}
----------------
This code is hard to understand. In short, what are you trying to do in this function?


https://reviews.llvm.org/D23352





More information about the llvm-commits mailing list