Skip to content

Commit f5c3bab

Browse files
committed
[LLD] Scope OpenBSD special section handling under that ELFOSABI
As the preexisting comment (that I referred to) says: > section names shouldn't be significant in ELF in spirit. so scoping OSABI-specific magic name hacks to just the OSABI in question limits the degree to which we deviate from that "spirit" for all other OSABIs. OpenBSD in particular is very fast moving, having added a number of special sections, etc. in recent years. It is unclear how possible / reasonable it is for upstream to implement all these features in any event, but scoping like this at least mitigates the fallout for other OSABIs systems which wish to be more slow-moving.
1 parent 449b3ec commit f5c3bab

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

lld/ELF/Writer.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,16 @@ static bool isRelroSection(const OutputSection *sec) {
601601
// ELF in spirit. But in reality many linker features depend on
602602
// magic section names.
603603
StringRef s = sec->name;
604-
return s == ".data.rel.ro" || s == ".bss.rel.ro" || s == ".ctors" ||
605-
s == ".dtors" || s == ".jcr" || s == ".eh_frame" ||
606-
s == ".fini_array" || s == ".init_array" ||
607-
s == ".openbsd.randomdata" || s == ".preinit_array";
604+
605+
bool abiAgnostic = s == ".data.rel.ro" || s == ".bss.rel.ro" ||
606+
s == ".ctors" || s == ".dtors" || s == ".jcr" ||
607+
s == ".eh_frame" || s == ".fini_array" ||
608+
s == ".init_array" || s == ".preinit_array";
609+
610+
bool abiSpecific =
611+
config->osabi == ELFOSABI_OPENBSD && s == ".openbsd.randomdata";
612+
613+
return abiAgnostic || abiSpecific;
608614
}
609615

610616
// We compute a rank for each section. The rank indicates where the
@@ -2273,21 +2279,26 @@ SmallVector<PhdrEntry *, 0> Writer<ELFT>::createPhdrs(Partition &part) {
22732279
addHdr(PT_GNU_EH_FRAME, part.ehFrameHdr->getParent()->getPhdrFlags())
22742280
->add(part.ehFrameHdr->getParent());
22752281

2276-
// PT_OPENBSD_MUTABLE is an OpenBSD-specific feature. That makes
2277-
// the dynamic linker fill the segment with zero data, like bss, but
2278-
// it can be treated differently.
2279-
if (OutputSection *cmd = findSection(".openbsd.mutable", partNo))
2280-
addHdr(PT_OPENBSD_MUTABLE, cmd->getPhdrFlags())->add(cmd);
2281-
2282-
// PT_OPENBSD_RANDOMIZE is an OpenBSD-specific feature. That makes
2283-
// the dynamic linker fill the segment with random data.
2284-
if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo))
2285-
addHdr(PT_OPENBSD_RANDOMIZE, cmd->getPhdrFlags())->add(cmd);
2286-
2287-
// PT_OPENBSD_SYSCALLS is an OpenBSD-specific feature. That makes
2288-
// the kernel and dynamic linker register system call sites.
2289-
if (OutputSection *cmd = findSection(".openbsd.syscalls", partNo))
2290-
addHdr(PT_OPENBSD_SYSCALLS, cmd->getPhdrFlags())->add(cmd);
2282+
// Handle OpenBSD-specific section types for OpenBSD "OS ABI".
2283+
//
2284+
// Scoped to just this "OS ABI" because, as is written below "section
2285+
// names shouldn't be significant in ELF in spirit".
2286+
if (config->osabi == ELFOSABI_OPENBSD) {
2287+
// PT_OPENBSD_MUTABLE makes the dynamic linker fill the segment with
2288+
// zero data, like bss, but it can be treated differently.
2289+
if (OutputSection *cmd = findSection(".openbsd.mutable", partNo))
2290+
addHdr(PT_OPENBSD_MUTABLE, cmd->getPhdrFlags())->add(cmd);
2291+
2292+
// PT_OPENBSD_RANDOMIZE makes the dynamic linker fill the segment
2293+
// with random data.
2294+
if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo))
2295+
addHdr(PT_OPENBSD_RANDOMIZE, cmd->getPhdrFlags())->add(cmd);
2296+
2297+
// PT_OPENBSD_SYSCALLS makes the kernel and dynamic linker register
2298+
// system call sites.
2299+
if (OutputSection *cmd = findSection(".openbsd.syscalls", partNo))
2300+
addHdr(PT_OPENBSD_SYSCALLS, cmd->getPhdrFlags())->add(cmd);
2301+
}
22912302

22922303
if (config->zGnustack != GnuStackKind::None) {
22932304
// PT_GNU_STACK is a special section to tell the loader to make the

0 commit comments

Comments
 (0)