llvm-project/lld/test/ELF/relro-openbsd.s
John Ericson d7fd8b19e5
[LLD] Extend special OpenBSD support, but scope under ELFOSABI (#97122)
- Add support for `.openbsd.mutable`

  (rebaser's note) adapted from:

bd249b5664
  New auto-coalescing sections removed

  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

- Add support for `.openbsd.syscalls`

  (rebaser's note) adapted from:

42a61acefa

  Collect .openbsd.syscalls sections into a new PT_OPENBSD_SYSCALLS
  segment. This will be used soon to pin system calls to designated call
  sites.

  ok deraadt@

- Scope OpenBSD special section handling under that ELFOSABI

  As a preexisting comment in `ELF/Writer.cpp` 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.

Co-authored-by: deraadt <deraadt@openbsd.org>
2024-07-12 14:34:17 -04:00

47 lines
1.2 KiB
ArmAsm

// 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