summaryrefslogtreecommitdiff
path: root/libexec/ld.so/amd64
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2019-05-10 13:29:22 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2019-05-10 13:29:22 +0000
commit7a997fa007d2414371c7b9fa2f4e83a0c3d406c2 (patch)
treeff8056bf55e605b407ec688972a67a4ab35dcd2b /libexec/ld.so/amd64
parentf16e61e66b2b5ec79eca82af98886596c97a38bb (diff)
ld.so boot cleanup support:
- put functions and data which are only used before calling the executable's start function into their own page-aligned segments for unmapping (only done on amd64, arm64, armv7, powerpc, and sparc64 so far) - pass .init_array and .preinit_array functions an addition argument which is a callback to get a structure which includes a function that frees the boot text and data - sometimes delay doing RELRO processing: for a shared-object marked DF_1_INITFIRST do it after the object's .init_array, for the executable do it after the .preinit_array - improve test-ld.so to link against libpthread and trigger its initialization late libc changes to use this will come later ok kettenis@
Diffstat (limited to 'libexec/ld.so/amd64')
-rw-r--r--libexec/ld.so/amd64/Makefile.inc3
-rw-r--r--libexec/ld.so/amd64/ld.script69
-rw-r--r--libexec/ld.so/amd64/ldasm.S11
3 files changed, 76 insertions, 7 deletions
diff --git a/libexec/ld.so/amd64/Makefile.inc b/libexec/ld.so/amd64/Makefile.inc
index 94a3002bc03..cfd3018d9f8 100644
--- a/libexec/ld.so/amd64/Makefile.inc
+++ b/libexec/ld.so/amd64/Makefile.inc
@@ -1,4 +1,5 @@
-# $OpenBSD: Makefile.inc,v 1.4 2018/04/27 06:49:06 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.5 2019/05/10 13:29:21 guenther Exp $
CFLAGS += -fPIC -mno-sse2 -mno-sse -mno-3dnow -mno-mmx
AFLAGS += -fpic
+LD_SCRIPT = ${.CURDIR}/${MACHINE_CPU}/ld.script
diff --git a/libexec/ld.so/amd64/ld.script b/libexec/ld.so/amd64/ld.script
new file mode 100644
index 00000000000..5629239dd52
--- /dev/null
+++ b/libexec/ld.so/amd64/ld.script
@@ -0,0 +1,69 @@
+PHDRS
+{
+ rodata PT_LOAD FILEHDR PHDRS FLAGS (4);
+ text PT_LOAD;
+ data PT_LOAD;
+ random PT_OPENBSD_RANDOMIZE;
+ relro PT_GNU_RELRO;
+ dynamic PT_DYNAMIC;
+ note PT_NOTE;
+}
+
+SECTIONS
+{
+ . = 0 + SIZEOF_HEADERS;
+ /* RODATA */
+ .gnu.hash : { *(.gnu.hash) } :rodata
+ .dynsym : { *(.dynsym) } :rodata
+ .dynstr : { *(.dynstr) } :rodata
+ .rodata : { *(.rodata .rodata.*) } :rodata
+ .eh_frame : { *(.eh_frame) } :rodata
+
+ /* TEXT */
+ . = ALIGN(0x100000) + (. & (0x100000 - 1)) + 0;
+ .boot.text :
+ {
+ boot_text_start = .;
+ *(.boot.text)
+ boot_text_end = .;
+ } :text =0xcccccccc
+ . = ALIGN(0x1000);
+ .text : { *(.text .text.*) } :text =0xcccccccc
+
+ /* RELRO DATA */
+ . = DATA_SEGMENT_ALIGN (0x100000, 0x1000);
+ .openbsd.randomdata :
+ {
+ *(.openbsd.randomdata .openbsd.randomdata.*)
+ } :data :relro :random
+ .data.rel.ro : { *(.data.rel.ro.local*) *(.data.rel.ro*) } :data :relro
+ .dynamic : { *(.dynamic) } :data :relro :dynamic
+ .got : { *(.got.plt) *(.got) } :data :relro
+ . = DATA_SEGMENT_RELRO_END (0, .);
+
+ /* BOOTDATA */
+ . = ALIGN(0x1000);
+ boot_data_start = .;
+ .rela.dyn :
+ {
+ *(.rela.text .rela.text.*)
+ *(.rela.rodata .rela.rodata.*)
+ *(.rela.data .rela.data.*)
+ *(.rela.got)
+ *(.rela.bss .rela.bss.*)
+ } :data
+/* XXX .rela.plt is unused but cannot delete: ld.bfd zeros DT_RELASZ then! */
+ .rela.plt : { *(.rela.plt) } :data
+ .note : { *(.note.openbsd.*) } :data :note
+ .hash : { *(.hash) } :data
+ .boot.data : { *(.boot.data .boot.data.*) } :data
+ boot_data_end = .;
+
+ /* DATA */
+ . = ALIGN(0x1000);
+ .data : { *(.data .data.*) } :data
+ .bss : { *(.dynbss) *(.bss .bss.*) *(COMMON) } :data
+ . = DATA_SEGMENT_END (.);
+
+ /DISCARD/ : { *(.note.GNU-stack) }
+}
diff --git a/libexec/ld.so/amd64/ldasm.S b/libexec/ld.so/amd64/ldasm.S
index 9f18b87617a..6ae3f8de1d4 100644
--- a/libexec/ld.so/amd64/ldasm.S
+++ b/libexec/ld.so/amd64/ldasm.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldasm.S,v 1.29 2017/08/28 14:12:09 deraadt Exp $ */
+/* $OpenBSD: ldasm.S,v 1.30 2019/05/10 13:29:21 guenther Exp $ */
/*
* Copyright (c) 2002,2004 Dale Rahn
@@ -32,7 +32,7 @@
#define DL_LOFF_OFFSET (7*8) /* index 7 */
#include <machine/asm.h>
- .text
+ .section .boot.text,"ax",@progbits
.align 16,0xcc
.globl _dl_start
.type _dl_start,@function
@@ -65,11 +65,9 @@ _dl_start:
leaq _dl_dtors(%rip), %rdx # %rdx = cleanup
movq %r12, %rsp
jmp *%rax
+END(_dl_start)
- .align 16,0xcc
- .global _dl_bind_start
- .type _dl_bind_start,@function
-_dl_bind_start:
+_ENTRY(_dl_bind_start)
.cfi_startproc
.cfi_adjust_cfa_offset 16
pushfq # save registers
@@ -143,3 +141,4 @@ _dl_bind_start:
.cfi_adjust_cfa_offset -8
ret
.cfi_endproc
+END(_dl_bind_start)