diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2017-11-09 14:14:08 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2018-01-11 05:29:05 -0800 |
commit | c11c786f0b45617bb8807ab6a57220d5ff50e414 (patch) | |
tree | d931419a07e956a67c351eaf86c4ad501b5df657 /ld/scripttempl | |
parent | 6bd0a312a4cb6803b9d6aa2f5646b610d213a1fe (diff) | |
download | gdb-c11c786f0b45617bb8807ab6a57220d5ff50e414.zip gdb-c11c786f0b45617bb8807ab6a57220d5ff50e414.tar.gz gdb-c11c786f0b45617bb8807ab6a57220d5ff50e414.tar.bz2 |
ld: Add "-z separate-code" option to ELF linker
The new "-z separate-code" option will generate separate code LOAD
segment which must be in wholly disjoint pages from any other data.
include/
PR ld/22393
* bfdlink.h (bfd_link_info): Add separate_code.
ld/
PR ld/22393
* NEWS: Mention "-z separate-code".
* emultempl/elf32.em (gld${EMULATION_NAME}_get_script): Get
builtin linker scripts and return linker scripts from disk for
"-z separate-code".
(gld${EMULATION_NAME}_handle_option): Handle "-z separate-code"
and "-z noseparate-code".
* genscripts.sh: Generate linker scripts for "-z separate-code".
(LD_FLAG): Set to *textonly for "-z separate-code".
* ld.texinfo: Document "-z separate-code".
* lexsup.c (elf_shlib_list_options): Add linker help messsages
for "-z separate-code" and "-z noseparate-code".
* scripttempl/elf.sc (SEPARATE_TEXT): New
(TEXT_SEGMENT_ALIGN): Likewise.
Use ${TEXT_SEGMENT_ALIGN} to align and pad text segment to
${MAXPAGESIZE}.
Diffstat (limited to 'ld/scripttempl')
-rw-r--r-- | ld/scripttempl/elf.sc | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 3de86b0..e7585ba 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -316,6 +316,17 @@ STACK=".stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})" SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-0})" +# Don't bother with separate code segment when there are data sections +# between .plt and .text. +if test -z "$TINY_READONLY_SECTION"; then + case "$LD_FLAG" in + *textonly*) + SEPARATE_TEXT=yes + TEXT_SEGMENT_ALIGN=". = ALIGN(${MAXPAGESIZE});" + ;; + esac +fi + if [ -z "$SEPARATE_CODE" ]; then SIZEOF_HEADERS_CODE=" + SIZEOF_HEADERS" else @@ -478,6 +489,8 @@ emit_dyn() test -n "${NON_ALLOC_DYN}${SEPARATE_CODE}" || emit_dyn cat <<EOF + ${RELOCATING+${TEXT_SEGMENT_ALIGN}} + .init ${RELOCATING-0}${RELOCATING+${INIT_ADDR}} : { ${RELOCATING+${INIT_START}} @@ -508,9 +521,10 @@ cat <<EOF ${RELOCATING+PROVIDE (__${ETEXT_NAME} = .);} ${RELOCATING+PROVIDE (_${ETEXT_NAME} = .);} ${RELOCATING+PROVIDE (${ETEXT_NAME} = .);} + ${RELOCATING+${TEXT_SEGMENT_ALIGN}} EOF -if test -n "${SEPARATE_CODE}"; then +if test -n "${SEPARATE_CODE}${SEPARATE_TEXT}"; then if test -n "${RODATA_ADDR}"; then RODATA_ADDR="\ SEGMENT_START(\"rodata-segment\", ${RODATA_ADDR}) + SIZEOF_HEADERS" @@ -532,8 +546,10 @@ SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR}) + SIZEOF_HEADERS" ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_RODATA_ADDR};}} ${CREATE_PIE+${RELOCATING+. = ${SHLIB_RODATA_ADDR};}} EOF - emit_early_ro - emit_dyn + if test -n "${SEPARATE_CODE}"; then + emit_early_ro + emit_dyn + fi fi cat <<EOF |