Skip to content

Commit

Permalink
Collect .openbsd.syscalls sections into a new PT_OPENBSD_SYSCALLS seg…
Browse files Browse the repository at this point in the history
…ment.

This will be used soon to pin system calls to designated call sites.

ok deraadt@
  • Loading branch information
kettenis committed Dec 3, 2023
1 parent 921ffa1 commit 42a61ac
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions gnu/llvm/lld/ELF/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,7 @@ unsigned ScriptParser::readPhdrType() {
.Case("PT_GNU_RELRO", PT_GNU_RELRO)
.Case("PT_OPENBSD_MUTABLE", PT_OPENBSD_MUTABLE)
.Case("PT_OPENBSD_RANDOMIZE", PT_OPENBSD_RANDOMIZE)
.Case("PT_OPENBSD_SYSCALLS", PT_OPENBSD_SYSCALLS)
.Case("PT_OPENBSD_WXNEEDED", PT_OPENBSD_WXNEEDED)
.Case("PT_OPENBSD_BOOTDATA", PT_OPENBSD_BOOTDATA)
.Default(-1);
Expand Down
5 changes: 5 additions & 0 deletions gnu/llvm/lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,11 @@ SmallVector<PhdrEntry *, 0> Writer<ELFT>::createPhdrs(Partition &part) {
if (OutputSection *cmd = findSection(".openbsd.randomdata", partNo))
addHdr(PT_OPENBSD_RANDOMIZE, cmd->getPhdrFlags())->add(cmd);

// PT_OPENBSD_SYSCALLS is an OpenBSD-specific feature. That 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
// pages for the stack non-executable. If you really want an executable
Expand Down
1 change: 1 addition & 0 deletions gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ enum {
PT_OPENBSD_RANDOMIZE = 0x65a3dbe6, // Fill with random data.
PT_OPENBSD_WXNEEDED = 0x65a3dbe7, // Program does W^X violations.
PT_OPENBSD_NOBTCFI = 0x65a3dbe8, // Do not enforce branch target CFI
PT_OPENBSD_SYSCALLS = 0x65a3dbe9, // System call sites.
PT_OPENBSD_BOOTDATA = 0x65a41be6, // Section for boot arguments.

// ARM program header types.
Expand Down
3 changes: 3 additions & 0 deletions gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ static void printProgramHeaders(const ELFFile<ELFT> &Obj, StringRef FileName) {
case ELF::PT_OPENBSD_RANDOMIZE:
outs() << "OPENBSD_RANDOMIZE ";
break;
case ELF::PT_OPENBSD_SYSCALLS:
outs() << "OPENBSD_SYSCALLS ";
break;
case ELF::PT_OPENBSD_WXNEEDED:
outs() << "OPENBSD_WXNEEDED ";
break;
Expand Down
1 change: 1 addition & 0 deletions gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ static StringRef segmentTypeToString(unsigned Arch, unsigned Type) {

LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_MUTABLE);
LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE);
LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_SYSCALLS);
LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED);
LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_NOBTCFI);
LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA);
Expand Down

0 comments on commit 42a61ac

Please sign in to comment.