From 12dd90a1344c5a9766ec320087c6288822bb4866 Mon Sep 17 00:00:00 2001 From: deraadt Date: Sat, 1 Jul 2017 18:00:01 +0000 Subject: [PATCH] provide both TRAP and NOP values for our architectures, then change elf.sc to FILL .text segment with TRAP. .init/.fini remain NOP FILL. It is possible that some of these TRAP values aren't perfect yet, but they can be changed. When doing so also change the ld.script and gap.o TRAP value. discussions with mortimer, ok kettenis --- gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh | 2 ++ gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmip.sh | 2 ++ .../binutils-2.17/ld/emulparams/elf32bmipn32-defs.sh | 2 ++ gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc.sh | 1 + gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh | 1 + gnu/usr.bin/binutils-2.17/ld/emulparams/elf64_sparc_obsd.sh | 1 + gnu/usr.bin/binutils-2.17/ld/emulparams/elf64alpha.sh | 6 +++--- gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh | 2 ++ gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh | 2 ++ gnu/usr.bin/binutils-2.17/ld/emulparams/elf_i386_obsd.sh | 2 ++ gnu/usr.bin/binutils-2.17/ld/emulparams/elf_x86_64_obsd.sh | 3 ++- gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh | 1 + gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh | 1 + gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc | 4 +++- 14 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh index 13a9239f8f7..dfcd1b83b43 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh @@ -4,6 +4,8 @@ MAXPAGESIZE=0x8000 COMMONPAGESIZE=0x1000 TEXT_START_ADDR=0x00008000 TARGET2_TYPE=got-rel +NOP=0x00000000 +TRAP=0xffffffff unset EMBEDDED diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmip.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmip.sh index 614856573fa..675d6f6b46d 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmip.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmip.sh @@ -48,3 +48,5 @@ MACHINE= TEMPLATE_NAME=elf32 GENERATE_SHLIB_SCRIPT=yes GENERATE_PIE_SCRIPT=yes +NOP=0x00000000 +TRAP=0xefefefef diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmipn32-defs.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmipn32-defs.sh index b81ac49ec30..da466fbd0ea 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmipn32-defs.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32bmipn32-defs.sh @@ -9,6 +9,8 @@ ARCH=mips OUTPUT_FORMAT="elf32-bigmips" BIG_OUTPUT_FORMAT="elf32-bigmips" LITTLE_OUTPUT_FORMAT="elf32-littlemips" +NOP=0x00000000 +TRAP=0xefefefef TEMPLATE_NAME=elf32 diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc.sh index 587b8d3aca0..a09d8d4365c 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc.sh @@ -13,3 +13,4 @@ PLT=".plt ${RELOCATING-0} : SPECIAL { *(.plt) }" GOTPLT="${PLT}" OTHER_TEXT_SECTIONS="*(.glink)" EXTRA_EM_FILE=ppc32elf +NOP=0x60000000 diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh index 4620a7ac1df..ee06fdc0717 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh @@ -1,5 +1,6 @@ . ${srcdir}/emulparams/elf32ppc.sh . ${srcdir}/emulparams/elf_obsd.sh +TRAP=0x00000000 # gauranteed always illegal # override these to put the padding *in* the output section sdata_GOT=".got ${RELOCATING-0} : SPECIAL { diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64_sparc_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64_sparc_obsd.sh index 465f473ad99..c182cf292a1 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64_sparc_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64_sparc_obsd.sh @@ -1,2 +1,3 @@ . ${srcdir}/emulparams/elf64_sparc.sh . ${srcdir}/emulparams/elf_obsd.sh +TRAP=0x00000000 diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64alpha.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64alpha.sh index 47a0bb009c7..f38835aebfb 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64alpha.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64alpha.sh @@ -19,9 +19,9 @@ PLT=".plt ${RELOCATING-0} : SPECIAL { *(.plt) }" DATA_PLT=yes TEXT_PLT=yes -# Note that the number is always big-endian, thus we have to -# reverse the digit string. -NOP=0x0000fe2f1f04ff47 # unop; nop +#NOP=0x0000fe2f 1f04ff47 # unop; nop +NOP=0x0000fe2f # unop +TRAP=0x00000000 # illegal? OTHER_READONLY_SECTIONS=" .reginfo ${RELOCATING-0} : { *(.reginfo) }" diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh index ab5bca3fa45..38173ed3f4e 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh @@ -5,3 +5,5 @@ TEXT_START_ADDR="0x10000000" . ${srcdir}/emulparams/elf_obsd.sh # XXX causes GOT oflows NO_PAD_CDTOR=y +NOP=0x00000000 +TRAP=0xefefefef diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh index e88dcf66815..147ecdbd2ac 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh @@ -5,3 +5,5 @@ TEXT_START_ADDR="0x10000000" . ${srcdir}/emulparams/elf_obsd.sh # XXX causes GOT oflows NO_PAD_CDTOR=y +NOP=0x00000000 +TRAP=0xefefefef diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_i386_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_i386_obsd.sh index ae7ba0e3d29..d0060a0ba82 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_i386_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_i386_obsd.sh @@ -1,5 +1,7 @@ . ${srcdir}/emulparams/elf_i386.sh . ${srcdir}/emulparams/elf_obsd.sh +NOP=0x90909090 +TRAP=0xcccccccc if test "${LD_FLAG#"${LD_FLAG%pie}"}" = "pie"; then TEXT_START_ADDR=0x0 diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_x86_64_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_x86_64_obsd.sh index 88be7b99810..9ee7192e068 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_x86_64_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf_x86_64_obsd.sh @@ -1,3 +1,4 @@ . ${srcdir}/emulparams/elf_x86_64.sh . ${srcdir}/emulparams/elf_obsd.sh -NOP=0xcccccccc +NOP=0x090909090 +TRAP=0xcccccccc diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh index 32ac7ca268c..cc60f10c6d8 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh @@ -14,6 +14,7 @@ OTHER_READONLY_SECTIONS=".PARISC.unwind ${RELOCATING-0} : { *(.PARISC.unwind) }" DATA_NONEXEC_PLT= PLT_BEFORE_GOT= GENERATE_SHLIB_SCRIPT=yes +TRAP=0x00000000 . ${srcdir}/emulparams/elf_obsd.sh diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh index 262fe529ef7..bcf00542d94 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh @@ -7,6 +7,7 @@ OUTPUT_FORMAT="elf32-sh-obsd" TEXT_START_ADDR=0x400000 MAXPAGESIZE=0x10000 COMMONPAGESIZE=0x1000 +TRAP=0xc3c3c3c3 DATA_START_SYMBOLS='__data_start = . ;'; diff --git a/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc b/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc index 4d0946eb914..bb4e52405a0 100644 --- a/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc +++ b/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc @@ -1,6 +1,7 @@ # # Unusual variables checked by this code: # NOP - four byte opcode for no-op (defaults to 0) +# TRAP - four byte opcode for death (defaults to $NOP) # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not # empty. # SMALL_DATA_CTOR - .ctors contains small data. @@ -83,6 +84,7 @@ # # Each of these can also have corresponding .rel.* and .rela.* sections. +test -z "$TRAP" && TRAP=$NOP test -z "$ENTRY" && ENTRY=_start test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT} test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT} @@ -284,7 +286,7 @@ SECTIONS /* .gnu.warning sections are handled specially by elf32.em. */ *(.gnu.warning) ${RELOCATING+${OTHER_TEXT_SECTIONS}} - } =${NOP-0} + } =${TRAP-0} .fini ${RELOCATING-0} : { ${RELOCATING+${FINI_START}} -- 2.20.1