[PATCH] D58892: [ELF] Split RW PT_LOAD on the PT_GNU_RELRO boundary
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 5 19:03:30 PST 2019
MaskRay updated this revision to Diff 189440.
MaskRay edited the summary of this revision.
MaskRay added reviewers: ruiu, pcc.
MaskRay added a comment.
This is independent from D56828 <https://reviews.llvm.org/D56828>.
Repository:
rLLD LLVM Linker
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58892/new/
https://reviews.llvm.org/D58892
Files:
ELF/Writer.cpp
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1946,6 +1946,29 @@
Load->add(Out::ElfHeader);
Load->add(Out::ProgramHeaders);
+ // PT_GNU_RELRO includes all sections that should be marked as
+ // read-only by dynamic linker after proccessing relocations.
+ // Current dynamic loaders only support one PT_GNU_RELRO PHDR, give
+ // an error message if more than one PT_GNU_RELRO PHDR is required.
+ PhdrEntry *RelRo = make<PhdrEntry>(PT_GNU_RELRO, PF_R);
+ bool InRelroPhdr = false;
+ OutputSection *RelroEnd = nullptr;
+ for (OutputSection *Sec : OutputSections) {
+ if (!needsPtLoad(Sec))
+ continue;
+ if (isRelroSection(Sec)) {
+ InRelroPhdr = true;
+ if (!RelroEnd)
+ RelRo->add(Sec);
+ else
+ error("section: " + Sec->Name + " is not contiguous with other relro" +
+ " sections");
+ } else if (InRelroPhdr) {
+ InRelroPhdr = false;
+ RelroEnd = Sec;
+ }
+ }
+
for (OutputSection *Sec : OutputSections) {
if (!(Sec->Flags & SHF_ALLOC))
break;
@@ -1963,7 +1986,8 @@
if (((Sec->LMAExpr ||
(Sec->LMARegion && (Sec->LMARegion != Load->FirstSec->LMARegion))) &&
Load->LastSec != Out::ProgramHeaders) ||
- Sec->MemRegion != Load->FirstSec->MemRegion || Flags != NewFlags) {
+ Sec->MemRegion != Load->FirstSec->MemRegion || Flags != NewFlags ||
+ Sec == RelroEnd) {
Load = AddHdr(PT_LOAD, NewFlags);
Flags = NewFlags;
@@ -1984,28 +2008,6 @@
if (OutputSection *Sec = In.Dynamic->getParent())
AddHdr(PT_DYNAMIC, Sec->getPhdrFlags())->add(Sec);
- // PT_GNU_RELRO includes all sections that should be marked as
- // read-only by dynamic linker after proccessing relocations.
- // Current dynamic loaders only support one PT_GNU_RELRO PHDR, give
- // an error message if more than one PT_GNU_RELRO PHDR is required.
- PhdrEntry *RelRo = make<PhdrEntry>(PT_GNU_RELRO, PF_R);
- bool InRelroPhdr = false;
- bool IsRelroFinished = false;
- for (OutputSection *Sec : OutputSections) {
- if (!needsPtLoad(Sec))
- continue;
- if (isRelroSection(Sec)) {
- InRelroPhdr = true;
- if (!IsRelroFinished)
- RelRo->add(Sec);
- else
- error("section: " + Sec->Name + " is not contiguous with other relro" +
- " sections");
- } else if (InRelroPhdr) {
- InRelroPhdr = false;
- IsRelroFinished = true;
- }
- }
if (RelRo->FirstSec)
Ret.push_back(RelRo);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58892.189440.patch
Type: text/x-patch
Size: 2573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190306/f6a29522/attachment.bin>
More information about the llvm-commits
mailing list