-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[LLD] Extend special OpenBSD support, but scope under ELFOSABI #97122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -601,10 +601,16 @@ static bool isRelroSection(const OutputSection *sec) { | |
// ELF in spirit. But in reality many linker features depend on | ||
// magic section names. | ||
StringRef s = sec->name; | ||
return s == ".data.rel.ro" || s == ".bss.rel.ro" || s == ".ctors" || | ||
s == ".dtors" || s == ".jcr" || s == ".eh_frame" || | ||
s == ".fini_array" || s == ".init_array" || | ||
s == ".openbsd.randomdata" || s == ".preinit_array"; | ||
|
||
bool abiAgnostic = s == ".data.rel.ro" || s == ".bss.rel.ro" || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be fine to keep this unchanged. We can add the osabi check if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MaskRay I would sort of like to change it for consistency. I ended up duplicating the test I had to change so we have a Linux and OpenBSD version, and this makes me feel better about coverage, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (And checked locally that both the new tests worked, and the old test failed.) |
||
s == ".ctors" || s == ".dtors" || s == ".jcr" || | ||
s == ".eh_frame" || s == ".fini_array" || | ||
s == ".init_array" || s == ".preinit_array"; | ||
|
||
bool abiSpecific = | ||
config->osabi == ELFOSABI_OPENBSD && s == ".openbsd.randomdata"; | ||
|
||
return abiAgnostic || abiSpecific; | ||
} | ||
|
||
// We compute a rank for each section. The rank indicates where the | ||
|
@@ -2273,10 +2279,22 @@ SmallVector<PhdrEntry *, 0> Writer<ELFT>::createPhdrs(Partition &part) { | |
addHdr(PT_GNU_EH_FRAME, part.ehFrameHdr->getParent()->getPhdrFlags()) | ||
->add(part.ehFrameHdr->getParent()); | ||
|
||
// PT_OPENBSD_RANDOMIZE is an OpenBSD-specific feature. That makes | ||
// the dynamic linker fill the segment with random data. | ||
if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo)) | ||
addHdr(PT_OPENBSD_RANDOMIZE, cmd->getPhdrFlags())->add(cmd); | ||
if (config->osabi == ELFOSABI_OPENBSD) { | ||
// PT_OPENBSD_MUTABLE makes the dynamic linker fill the segment with | ||
// zero data, like bss, but it can be treated differently. | ||
if (OutputSection *cmd = findSection(".openbsd.mutable", partNo)) | ||
addHdr(PT_OPENBSD_MUTABLE, cmd->getPhdrFlags())->add(cmd); | ||
|
||
// PT_OPENBSD_RANDOMIZE makes the dynamic linker fill the segment | ||
// with random data. | ||
if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo)) | ||
addHdr(PT_OPENBSD_RANDOMIZE, cmd->getPhdrFlags())->add(cmd); | ||
|
||
// PT_OPENBSD_SYSCALLS makes the kernel and dynamic linker register | ||
// system call sites. | ||
if (OutputSection *cmd = findSection(".openbsd.syscalls", partNo)) | ||
addHdr(PT_OPENBSD_SYSCALLS, cmd->getPhdrFlags())->add(cmd); | ||
} | ||
|
||
if (config->zGnustack != GnuStackKind::None) { | ||
// PT_GNU_STACK is a special section to tell the loader to make the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// REQUIRES: x86 | ||
|
||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-openbsd %s -o %t.o | ||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-openbsd %p/Inputs/shared.s -o %t2.o | ||
// RUN: ld.lld -shared %t2.o -o %t2.so | ||
|
||
// RUN: ld.lld %t.o %t2.so -z now -z norelro -z relro -o %t | ||
// RUN: llvm-readelf -l %t | FileCheck --check-prefix=CHECK --check-prefix=FULLRELRO %s | ||
|
||
// RUN: ld.lld %t.o %t2.so -z norelro -z relro -o %t | ||
// RUN: llvm-readelf -l %t | FileCheck --check-prefix=CHECK --check-prefix=PARTRELRO %s | ||
|
||
// RUN: ld.lld %t.o %t2.so -z norelro -o %t | ||
// RUN: llvm-readelf -l %t | FileCheck --check-prefix=NORELRO %s | ||
|
||
// CHECK: Program Headers: | ||
// CHECK-NEXT: Type | ||
// CHECK-NEXT: PHDR | ||
// CHECK-NEXT: LOAD | ||
// CHECK-NEXT: LOAD | ||
// CHECK-NEXT: LOAD | ||
// CHECK-NEXT: LOAD | ||
// CHECK-NEXT: DYNAMIC | ||
// CHECK-NEXT: GNU_RELRO | ||
// CHECK: Section to Segment mapping: | ||
|
||
// FULLRELRO: 03 .openbsd.randomdata .dynamic .got .got.plt .relro_padding {{$}} | ||
// PARTRELRO: 03 .openbsd.randomdata .dynamic .got .relro_padding {{$}} | ||
|
||
|
||
// NORELRO-NOT: GNU_RELRO | ||
|
||
.global _start | ||
_start: | ||
.long bar | ||
jmp *bar2@GOTPCREL(%rip) | ||
|
||
.section .data,"aw" | ||
.quad 0 | ||
|
||
.zero 4 | ||
.section .foo,"aw" | ||
.section .bss,"",@nobits | ||
|
||
.section .openbsd.randomdata, "aw" | ||
.quad 0 |
Uh oh!
There was an error while loading. Please reload this page.