[PATCH] D22672: [ELF] - Linkerscript: cleanup of LinkerScript<ELFT>::createSections().
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 22 05:30:18 PDT 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.
It is becoming harder to update the AddInputSec functor.
I suggest the next cleanup.
https://reviews.llvm.org/D22672
Files:
ELF/LinkerScript.cpp
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -258,6 +258,18 @@
}
template <class ELFT>
+bool canAddSection(InputSectionBase<ELFT> *C, ConstraintKind Kind) {
+ if (Kind == NoConstraint)
+ return true;
+ bool Writable = C->getSectionHdr()->sh_flags & SHF_WRITE;
+ if (Kind == ReadWrite && !Writable)
+ return false;
+ if (Kind == ReadOnly && Writable)
+ return false;
+ return true;
+}
+
+template <class ELFT>
std::vector<OutputSectionBase<ELFT> *>
LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
typedef const std::unique_ptr<ObjectFile<ELFT>> ObjectFile;
@@ -273,12 +285,7 @@
std::tie(Sec, IsNew) = Factory.create(C, Name);
if (IsNew)
Result.push_back(Sec);
- if ((!(C->getSectionHdr()->sh_flags & SHF_WRITE)) &&
- Constraint == ReadWrite) {
- Removed.insert(Sec);
- return;
- }
- if ((C->getSectionHdr()->sh_flags & SHF_WRITE) && Constraint == ReadOnly) {
+ if (!canAddSection(C, Constraint)) {
Removed.insert(Sec);
return;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22672.65058.patch
Type: text/x-patch
Size: 1177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160722/e086723a/attachment.bin>
More information about the llvm-commits
mailing list