From: Nick Clifton Date: Wed, 27 Nov 2024 11:23:38 +0000 (+0000) Subject: Tidy up the default ELF linker script X-Git-Tag: gdb-16-branchpoint~288 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe217087a4b8aa214a221ca9f033c5fcdbcee90e;p=thirdparty%2Fbinutils-gdb.git Tidy up the default ELF linker script --- diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 84b433256a6..82d6ddb5b4c 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -115,6 +115,48 @@ # # Each of these can also have corresponding .rel.* and .rela.* sections. +# ------------------------------------------------------------------------ +# The multiple forms of conditional shell script syntax that are used in +# this file can be confusing, so here is a quick explanation of how they +# work: +# +# The following all mean "if foo is defined then do/insert ": +# +# test -z "$foo" || +# test -n "$foo" && +# if test -n "$foo"; then +# if [ -n "$foo" ]; then +# ${foo-} +# +# Whereas the following all mean "if foo is undefined then do/insert ": +# +# test -n "$foo" || +# test -z "$foo" && +# if test -z "$foo"; then +# if [ -z "$foo" ]; then +# ${foo+} +# +# If multiple symbols are tested together then they operate as an IOR for +# positive tests and a NOR for negative tests. ie, the following all do +# if either or both of and are defined: +# +# test -z "$foo$bar" || +# test -n "$foo$bar" && +# if test -n "$foo$bar"; then +# +# Whilst the following only do if neither nor are defined: +# +# test -n "$foo$bar" || +# if -z "$foo$bar"; then +# test -z "$foo$bar" && +# +# Also: +# foo=${foo-${bar-${baz}}} +# means: +# If foo is defined, leave it unchanged. Otherwise if bar is defined +# then set foo equal to bar, otherwise set foo equal to baz. +# ------------------------------------------------------------------------ + if test -n "$NOP"; then FILL="=$NOP" else @@ -136,6 +178,7 @@ test "$LD_FLAG" = "N" && DATA_ADDR=. test -z "${ETEXT_NAME}" && ETEXT_NAME=${USER_LABEL_PREFIX}etext test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }" + if test -z "$DATA_SEGMENT_ALIGN"; then test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE="" test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE="" @@ -144,7 +187,8 @@ if test -z "$DATA_SEGMENT_ALIGN"; then DATA_SEGMENT_END="" if test -n "${COMMONPAGESIZE}"; then if test "${SEGMENT_SIZE}" != "${MAXPAGESIZE}"; then - DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})" + DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); \ + . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})" else DATA_SEGMENT_ALIGN="DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})" fi @@ -152,15 +196,19 @@ if test -z "$DATA_SEGMENT_ALIGN"; then DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);" fi fi + if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then INITIAL_READONLY_SECTIONS=".interp ${RELOCATING-0} : { *(.interp) }" fi + if test -z "$PLT"; then IPLT=".iplt ${RELOCATING-0} : { *(.iplt) }" PLT=".plt ${RELOCATING-0} : { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} } ${IREL_IN_PLT-$IPLT}" fi + test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT= + if test -z "$GOT"; then if test -z "$SEPARATE_GOTPLT"; then GOT=".got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt) *(.igot.plt)} *(.got)${RELOCATING+ *(.igot)} }" @@ -233,17 +281,21 @@ if test -z "${NO_SMALL_DATA}"; then else NO_SMALL_DATA=" " fi + if test -z "${SDATA_GOT}${DATA_GOT}"; then if test -n "${NO_SMALL_DATA}"; then DATA_GOT=" " fi fi + if test -z "${SDATA_GOT}${DATA_GOT}"; then if test -z "${NO_SMALL_DATA}"; then SDATA_GOT=" " fi fi + test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" " + test "${LARGE_SECTIONS}" = "yes" && REL_LARGE=" .rel.ldata ${RELOCATING-0} : { *(.rel.ldata${RELOCATING+ .rel.ldata.* .rel.gnu.linkonce.l.*}) } .rela.ldata ${RELOCATING-0} : { *(.rela.ldata${RELOCATING+ .rela.ldata.* .rela.gnu.linkonce.l.*}) } @@ -251,23 +303,7 @@ test "${LARGE_SECTIONS}" = "yes" && REL_LARGE=" .rela.lbss ${RELOCATING-0} : { *(.rela.lbss${RELOCATING+ .rela.lbss.* .rela.gnu.linkonce.lb.*}) } .rel.lrodata ${RELOCATING-0} : { *(.rel.lrodata${RELOCATING+ .rel.lrodata.* .rel.gnu.linkonce.lr.*}) } .rela.lrodata ${RELOCATING-0} : { *(.rela.lrodata${RELOCATING+ .rela.lrodata.* .rela.gnu.linkonce.lr.*}) }" -test "${LARGE_SECTIONS}" = "yes" && LARGE_BSS=" - .lbss ${RELOCATING-0} : - { - ${RELOCATING+*(.dynlbss)} - *(.lbss${RELOCATING+ .lbss.* .gnu.linkonce.lb.*}) - ${RELOCATING+*(LARGE_COMMON)} - }" -test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS=" - .lrodata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} : - { - *(.lrodata${RELOCATING+ .lrodata.* .gnu.linkonce.lr.*}) - } - .ldata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} : - { - *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*}) - ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);} - }" + if test "${ENABLE_INITFINI_ARRAY}" = "yes"; then SORT_INIT_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))" SORT_FINI_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))" @@ -279,26 +315,6 @@ else CTORS_IN_INIT_ARRAY= DTORS_IN_FINI_ARRAY= fi -PREINIT_ARRAY=".preinit_array : - { - ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__preinit_array_start"));} - KEEP (*(.preinit_array)) - ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__preinit_array_end"));} - }" -INIT_ARRAY=".init_array : - { - ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__init_array_start"));} - ${SORT_INIT_ARRAY} - KEEP (*(.init_array ${CTORS_IN_INIT_ARRAY})) - ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__init_array_end"));} - }" -FINI_ARRAY=".fini_array : - { - ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__fini_array_start"));} - ${SORT_FINI_ARRAY} - KEEP (*(.fini_array ${DTORS_IN_FINI_ARRAY})) - ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__fini_array_end"));} - }" CTOR=".ctors ${CONSTRUCTING-0} : { ${CONSTRUCTING+${CTOR_START}} @@ -335,32 +351,6 @@ DTOR=".dtors ${CONSTRUCTING-0} : KEEP (*(.dtors)) ${CONSTRUCTING+${DTOR_END}} }" -STACK=".stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : - { - ${RELOCATING+$(def_symbol "_stack");} - *(.stack) - ${RELOCATING+${STACK_SENTINEL}} - }" -test "${HAVE_NOINIT}" = "yes" && NOINIT=" - /* This section contains data that is not initialized during load, - or during the application's initialization sequence. */ - .noinit ${RELOCATING-0} (NOLOAD) : ${RELOCATING+ALIGN(${ALIGNMENT})} - { - ${RELOCATING+PROVIDE (__noinit_start = .);} - *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*}) - ${RELOCATING+. = ALIGN(${ALIGNMENT});} - ${RELOCATING+PROVIDE (__noinit_end = .);} - }" -test "${HAVE_PERSISTENT}" = "yes" && PERSISTENT=" - /* This section contains data that is initialized during load, - but not during the application's initialization sequence. */ - .persistent ${RELOCATING-0} : ${RELOCATING+ALIGN(${ALIGNMENT})} - { - ${RELOCATING+PROVIDE (__persistent_start = .);} - *(.persistent${RELOCATING+ .persistent.* .gnu.linkonce.p.*}) - ${RELOCATING+. = ALIGN(${ALIGNMENT});} - ${RELOCATING+PROVIDE (__persistent_end = .);} - }" TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})" SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-0})" @@ -410,6 +400,20 @@ cat < ldscripts/dyntmp.$$ <> ldscripts/dyntmp.$$ <> ldscripts/dyntmp.$$ + cat >> ldscripts/dyntmp.$$ <> ldscripts/dyntmp.$$ + cat >> ldscripts/dyntmp.$$ <> ldscripts/dyntmp.$$ <