Skip to content

Commit a70d51e

Browse files
deraadtEricson2314
authored andcommitted
[LLD] Add support for .openbsd.mutable
(rebaser's note) adapted from: openbsd/src@bd249b5 In the linkers, collect objects in section "openbsd.mutable" and place them into a page-aligned region in the bss, with the right markers for kernel/ld.so to identify the region and skip making it immutable. While here, fix readelf/objdump versions to show all of this. ok miod kettenis
1 parent 7841520 commit a70d51e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lld/ELF/LinkerScript.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ static StringRef getOutputSectionName(const InputSectionBase *s) {
107107
for (StringRef v :
108108
{".data.rel.ro", ".data", ".rodata", ".bss.rel.ro", ".bss", ".ldata",
109109
".lrodata", ".lbss", ".gcc_except_table", ".init_array", ".fini_array",
110-
".tbss", ".tdata", ".ARM.exidx", ".ARM.extab", ".ctors", ".dtors"})
110+
".tbss", ".tdata", ".ARM.exidx", ".ARM.extab", ".ctors", ".dtors",
111+
".openbsd.randomdata", ".openbsd.mutable"})
111112
if (isSectionPrefix(v, s->name))
112113
return v;
113114

lld/ELF/ScriptParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,7 @@ unsigned ScriptParser::readPhdrType() {
16281628
.Case("PT_GNU_EH_FRAME", PT_GNU_EH_FRAME)
16291629
.Case("PT_GNU_STACK", PT_GNU_STACK)
16301630
.Case("PT_GNU_RELRO", PT_GNU_RELRO)
1631+
.Case("PT_OPENBSD_MUTABLE", PT_OPENBSD_MUTABLE)
16311632
.Case("PT_OPENBSD_RANDOMIZE", PT_OPENBSD_RANDOMIZE)
16321633
.Case("PT_OPENBSD_WXNEEDED", PT_OPENBSD_WXNEEDED)
16331634
.Case("PT_OPENBSD_BOOTDATA", PT_OPENBSD_BOOTDATA)

lld/ELF/Writer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,12 @@ SmallVector<PhdrEntry *, 0> Writer<ELFT>::createPhdrs(Partition &part) {
22452245
addHdr(PT_GNU_EH_FRAME, part.ehFrameHdr->getParent()->getPhdrFlags())
22462246
->add(part.ehFrameHdr->getParent());
22472247

2248+
// PT_OPENBSD_MUTABLE is an OpenBSD-specific feature. That makes
2249+
// the dynamic linker fill the segment with zero data, like bss, but
2250+
// it can be treated differently.
2251+
if (OutputSection *cmd = findSection(".openbsd.mutable", partNo))
2252+
addHdr(PT_OPENBSD_MUTABLE, cmd->getPhdrFlags())->add(cmd);
2253+
22482254
// PT_OPENBSD_RANDOMIZE is an OpenBSD-specific feature. That makes
22492255
// the dynamic linker fill the segment with random data.
22502256
if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo))

0 commit comments

Comments
 (0)