From 74dc9032e79b7950095ee5f94f5517209ef4747e Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 20 Feb 2017 13:25:13 +1030 Subject: Move .stack before debug sections PR 20199 * emulparams/elf32m32c.sh: Define STACK_ADDR and STACK_SENTINEL rather than using OTHER_SECTIONS. * emulparams/elf32mt.sh: Likewise. * emulparams/elf32rx.sh: Likewise. * emulparams/elf32rl78.sh: Likewise. Use OTHER_SYMBOLS to define __rl78_abs__. * emulparams/shelf.sh: Define STACK_ADDR and STACK_SENTINEL rather than using OTHER_SECTIONS. * emulparams/shelf32.sh: Likewise. Use OTHER_SECTIONS for .cranges. * emulparams/shelf64.sh: Unset OTHER_SECTIONS. * emulparams/shelf_nbsd.sh: Unset STACK_ADDR not OTHER_SECTIONS. * emulparams/shelf_uclinux.sh: Likewise. * emulparams/shlsymbian.sh: Unset STACK_ADDR. Use OTHER_SYMBOLS to define _stack, not OTHER_SECTIONS. * scripttempl/elf.sc: Move STACK, TINY_DATA_SECTION, and TINY_BSS_SECTION before debug sections. Add STACK_SENTINEL. * scripttempl/arclinux.sc: Likewise. * scripttempl/elf64hppa.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. * scripttempl/nds32elf.sc: Likewise. * scripttempl/armbpabi.sc: Move STACK before debug sections. * scripttempl/elf_chaos.sc: Likewise. * scripttempl/elfarc.sc: Delete STACK. * scripttempl/epiphany_4x4.sc: Delete STACK. Move TINY_DATA_SECTION, TINY_BSS_SECTION, and .stack before debug sections. --- ld/ChangeLog | 29 +++++++++++++++++++++++++++++ ld/emulparams/elf32m32c.sh | 17 ++++------------- ld/emulparams/elf32mt.sh | 17 ++++------------- ld/emulparams/elf32rl78.sh | 21 +++++++-------------- ld/emulparams/elf32rx.sh | 17 ++++------------- ld/emulparams/shelf.sh | 16 +++------------- ld/emulparams/shelf32.sh | 26 +++++--------------------- ld/emulparams/shelf64.sh | 11 +---------- ld/emulparams/shelf_nbsd.sh | 2 +- ld/emulparams/shelf_uclinux.sh | 2 +- ld/emulparams/shlsymbian.sh | 4 +++- ld/scripttempl/arclinux.sc | 11 +++++------ ld/scripttempl/armbpabi.sc | 2 +- ld/scripttempl/elf.sc | 13 ++++++------- ld/scripttempl/elf64hppa.sc | 12 ++++++------ ld/scripttempl/elf_chaos.sc | 2 +- ld/scripttempl/elfarc.sc | 1 - ld/scripttempl/elfxtensa.sc | 12 ++++++------ ld/scripttempl/epiphany_4x4.sc | 29 ++++++----------------------- ld/scripttempl/nds32elf.sc | 11 +++++------ 20 files changed, 98 insertions(+), 157 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index ce8cdb3..d02d009 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,32 @@ +2017-02-17 Alan Modra + + PR 20199 + * emulparams/elf32m32c.sh: Define STACK_ADDR and STACK_SENTINEL + rather than using OTHER_SECTIONS. + * emulparams/elf32mt.sh: Likewise. + * emulparams/elf32rx.sh: Likewise. + * emulparams/elf32rl78.sh: Likewise. Use OTHER_SYMBOLS to + define __rl78_abs__. + * emulparams/shelf.sh: Define STACK_ADDR and STACK_SENTINEL + rather than using OTHER_SECTIONS. + * emulparams/shelf32.sh: Likewise. Use OTHER_SECTIONS for .cranges. + * emulparams/shelf64.sh: Unset OTHER_SECTIONS. + * emulparams/shelf_nbsd.sh: Unset STACK_ADDR not OTHER_SECTIONS. + * emulparams/shelf_uclinux.sh: Likewise. + * emulparams/shlsymbian.sh: Unset STACK_ADDR. Use OTHER_SYMBOLS + to define _stack, not OTHER_SECTIONS. + * scripttempl/elf.sc: Move STACK, TINY_DATA_SECTION, and + TINY_BSS_SECTION before debug sections. Add STACK_SENTINEL. + * scripttempl/arclinux.sc: Likewise. + * scripttempl/elf64hppa.sc: Likewise. + * scripttempl/elfxtensa.sc: Likewise. + * scripttempl/nds32elf.sc: Likewise. + * scripttempl/armbpabi.sc: Move STACK before debug sections. + * scripttempl/elf_chaos.sc: Likewise. + * scripttempl/elfarc.sc: Delete STACK. + * scripttempl/epiphany_4x4.sc: Delete STACK. Move TINY_DATA_SECTION, + TINY_BSS_SECTION, and .stack before debug sections. + 2017-02-17 Nick Clifton PR ld/20825 diff --git a/ld/emulparams/elf32m32c.sh b/ld/emulparams/elf32m32c.sh index eaf2c4e..cd2b700 100644 --- a/ld/emulparams/elf32m32c.sh +++ b/ld/emulparams/elf32m32c.sh @@ -10,17 +10,8 @@ TEMPLATE_NAME=elf32 EXTRA_EM_FILE=needrelax ELFSIZE=32 MAXPAGESIZE=256 -# This is like setting STACK_ADDR to 0x0073FFFF0, except that the setting can -# be overridden, e.g. --defsym _stack=0x0f00, and that we put an extra -# sentinal value at the bottom. -# N.B. We can't use PROVIDE to set the default value in a symbol because -# the address is needed to place the .stack section, which in turn is needed -# to hold the sentinel value(s). -test -z "$CREATE_SHLIB" && OTHER_SECTIONS=" .stack ${RELOCATING-0}${RELOCATING+(DEFINED(__stack) ? __stack : 0x7fc)} : - { - ${RELOCATING+__stack = .;} - *(.stack) - LONG(0xdeaddead) - }" + +STACK_ADDR="(DEFINED(__stack) ? __stack : 0x7fc)" +STACK_SENTINEL="LONG(0xdeaddead)" # We do not need .stack for shared library. -test -n "$CREATE_SHLIB" && OTHER_SECTIONS="" +test -n "$CREATE_SHLIB" && unset STACK_ADDR diff --git a/ld/emulparams/elf32mt.sh b/ld/emulparams/elf32mt.sh index 04fc1ed..6880db8 100644 --- a/ld/emulparams/elf32mt.sh +++ b/ld/emulparams/elf32mt.sh @@ -10,17 +10,8 @@ ENTRY=_start EMBEDDED=yes ELFSIZE=32 MAXPAGESIZE=256 -# This is like setting STACK_ADDR to 0x0073FFFF0, except that the setting can -# be overridden, e.g. --defsym _stack=0x0f00, and that we put an extra -# sentinal value at the bottom. -# N.B. We can't use PROVIDE to set the default value in a symbol because -# the address is needed to place the .stack section, which in turn is needed -# to hold the sentinel value(s). -test -z "$CREATE_SHLIB" && OTHER_SECTIONS=" .stack ${RELOCATING-0}${RELOCATING+(DEFINED(__stack) ? __stack : 0x007FFFF0)} : - { - ${RELOCATING+__stack = .;} - *(.stack) - LONG(0xdeaddead) - }" + +STACK_ADDR="(DEFINED(__stack) ? __stack : 0x007FFFF0)" +STACK_SENTINEL="LONG(0xdeaddead)" # We do not need .stack for shared library. -test -n "$CREATE_SHLIB" && OTHER_SECTIONS="" +test -n "$CREATE_SHLIB" && unset STACK_ADDR diff --git a/ld/emulparams/elf32rl78.sh b/ld/emulparams/elf32rl78.sh index 7073efb..b782d03 100644 --- a/ld/emulparams/elf32rl78.sh +++ b/ld/emulparams/elf32rl78.sh @@ -10,18 +10,11 @@ TEMPLATE_NAME=elf32 ELFSIZE=32 # EXTRA_EM_FILE=needrelax MAXPAGESIZE=256 -# This is like setting STACK_ADDR to 0xffedc, except that the setting can -# be overridden, e.g. --defsym _stack=0x0f00, and that we put an extra -# sentinal value at the bottom. -# N.B. We can't use PROVIDE to set the default value in a symbol because -# the address is needed to place the .stack section, which in turn is needed -# to hold the sentinel value(s). -test -z "$CREATE_SHLIB" && OTHER_SECTIONS=" .stack ${RELOCATING-0}${RELOCATING+(DEFINED(__stack) ? __stack : 0xffedc)} : - { - ${RELOCATING+__stack = .;} - *(.stack) - LONG(0xdead) - } - ${RELOCATING+PROVIDE (__rl78_abs__ = 0);}" + +STACK_ADDR="(DEFINED(__stack) ? __stack : 0xffedc)" +STACK_SENTINEL="LONG(0xdead)" # We do not need .stack for shared library. -test -n "$CREATE_SHLIB" && OTHER_SECTIONS="" +test -n "$CREATE_SHLIB" && unset STACK_ADDR + +OTHER_SYMBOLS="PROVIDE (__rl78_abs__ = 0);" +test -n "$CREATE_SHLIB" && unset OTHER_SYMBOLS diff --git a/ld/emulparams/elf32rx.sh b/ld/emulparams/elf32rx.sh index 2288667..e139be7 100644 --- a/ld/emulparams/elf32rx.sh +++ b/ld/emulparams/elf32rx.sh @@ -11,20 +11,11 @@ EXTRA_EM_FILE=rxelf # EXTRA_EM_FILE=needrelax ELFSIZE=32 MAXPAGESIZE=256 -# This is like setting STACK_ADDR to 0xbffffffc, except that the setting can -# be overridden, e.g. --defsym _stack=0x0f00, and that we put an extra -# sentinal value at the bottom. -# N.B. We can't use PROVIDE to set the default value in a symbol because -# the address is needed to place the .stack section, which in turn is needed -# to hold the sentinel value(s). -test -z "$CREATE_SHLIB" && OTHER_SECTIONS=" .stack ${RELOCATING-0}${RELOCATING+(DEFINED(__stack) ? __stack : 0xbffffffc)} : - { - ${RELOCATING+__stack = .;} - *(.stack) - LONG(0xdeaddead) - }" + +STACK_ADDR="(DEFINED(__stack) ? __stack : 0xbffffffc)" +STACK_SENTINEL="LONG(0xdeaddead)" # We do not need .stack for shared library. -test -n "$CREATE_SHLIB" && OTHER_SECTIONS="" +test -n "$CREATE_SHLIB" && unset STACK_ADDR OTHER_TEXT_SECTIONS='*(P)' OTHER_READONLY_SECTIONS='C_1 : { *(C_1) } C_2 : { *(C_2) } C : { *(C) } W_1 : { *(W_1) } W_2 : { *(W_2) } W : { *(W) }' diff --git a/ld/emulparams/shelf.sh b/ld/emulparams/shelf.sh index d3f4752..8d79b8d 100644 --- a/ld/emulparams/shelf.sh +++ b/ld/emulparams/shelf.sh @@ -21,17 +21,7 @@ CTOR_START='___ctors = .;' CTOR_END='___ctors_end = .;' DTOR_START='___dtors = .;' DTOR_END='___dtors_end = .;' -# This is like setting STACK_ADDR to 0x3FFFFF00, except that the setting can -# be overridden, e.g. --defsym _stack=0x0f00, and that we put an extra -# sentinal value at the bottom. -# N.B. We can't use PROVIDE to set the default value in a symbol because -# the address is needed to place the .stack section, which in turn is needed -# to hold the sentinel value(s). -test -z "$CREATE_SHLIB" && OTHER_SECTIONS=" .stack ${RELOCATING-0}${RELOCATING+(DEFINED(_stack) ? _stack : 0x3FFFFF00)} : - { - ${RELOCATING+_stack = .;} - *(.stack) - LONG(0xdeaddead) - }" +STACK_ADDR="(DEFINED(_stack) ? _stack : 0x3FFFFF00)" +STACK_SENTINEL="LONG(0xdeaddead)" # We do not need .stack for shared library. -test -n "$CREATE_SHLIB" && OTHER_SECTIONS="" +test -n "$CREATE_SHLIB" && unset STACK_ADDR diff --git a/ld/emulparams/shelf32.sh b/ld/emulparams/shelf32.sh index bf362c5..7f46407 100644 --- a/ld/emulparams/shelf32.sh +++ b/ld/emulparams/shelf32.sh @@ -34,28 +34,12 @@ CTOR_END='___ctors_end = .;' DTOR_START='___dtors = .;' DTOR_END='___dtors_end = .;' -# Do not use the varname=${varname-'string'} construct here; there are -# problems with that on some shells (e.g. on Solaris) where there is a bug -# that trigs when $varname contains a "}". -# The effect of the .stack definition is like setting STACK_ADDR to 0x80000, -# except that the setting can be overridden, e.g. --defsym _stack=0xff000, -# and that we put an extra sentinal value at the bottom. -# N.B. We can't use PROVIDE to set the default value in a symbol because -# the address is needed to place the .stack section, which in turn is needed -# to hold the sentinel value(s). -test -z "$CREATE_SHLIB" && OTHER_SECTIONS=" - .stack ${RELOCATING-0}${RELOCATING+(DEFINED(_stack) ? _stack : ALIGN (0x40000) + 0x80000)} : - { - ${RELOCATING+_stack = .;} - *(.stack) - LONG(0xdeaddead) - } - .cranges 0 : { *(.cranges) } -" +STACK_ADDR="(DEFINED(_stack) ? _stack : ALIGN (0x40000) + 0x80000)" +STACK_SENTINEL="LONG(0xdeaddead)" # We do not need .stack for shared library. -test -n "$CREATE_SHLIB" && OTHER_SECTIONS=" - .cranges 0 : { *(.cranges) } -" +test -n "$CREATE_SHLIB" && unset STACK_ADDR + +OTHER_SECTIONS=".cranges 0 : { *(.cranges) }" # We need to adjust sizes in the .cranges section after relaxation, so # we need an after_allocation function, and it goes in this file. diff --git a/ld/emulparams/shelf64.sh b/ld/emulparams/shelf64.sh index 5037f35..5ddcc8d 100644 --- a/ld/emulparams/shelf64.sh +++ b/ld/emulparams/shelf64.sh @@ -6,13 +6,4 @@ EXTRA_EM_FILE= . ${srcdir}/emulparams/shelf32.sh # We do not need .cranges -test -z "$CREATE_SHLIB" && OTHER_SECTIONS=" - .stack ${RELOCATING-0}${RELOCATING+(DEFINED(_stack) ? _stack : ALIGN (0x40000) + 0x80000)} : - { - ${RELOCATING+_stack = .;} - *(.stack) - LONG(0xdeaddead) - } -" -# We do not need .stack for shared library. -test -n "$CREATE_SHLIB" && OTHER_SECTIONS="" +unset OTHER_SECTIONS diff --git a/ld/emulparams/shelf_nbsd.sh b/ld/emulparams/shelf_nbsd.sh index 9d331c6..b27993d 100644 --- a/ld/emulparams/shelf_nbsd.sh +++ b/ld/emulparams/shelf_nbsd.sh @@ -12,4 +12,4 @@ DATA_START_SYMBOLS='PROVIDE (__data_start = .);'; ENTRY=_start unset EMBEDDED -unset OTHER_SECTIONS +unset STACK_ADDR diff --git a/ld/emulparams/shelf_uclinux.sh b/ld/emulparams/shelf_uclinux.sh index 2af5da4..dac390e 100644 --- a/ld/emulparams/shelf_uclinux.sh +++ b/ld/emulparams/shelf_uclinux.sh @@ -1,4 +1,4 @@ . ${srcdir}/emulparams/shelf.sh # We do not want a .stack section -OTHER_SECTIONS="" +unset STACK_ADDR diff --git a/ld/emulparams/shlsymbian.sh b/ld/emulparams/shlsymbian.sh index 9c6dfba..f729bb5 100644 --- a/ld/emulparams/shlsymbian.sh +++ b/ld/emulparams/shlsymbian.sh @@ -11,7 +11,9 @@ DTOR_START='__dtors = .;' DTOR_END='__dtors_end = .;' # Suppress the .stack section. -test -z "$CREATE_SHLIB" && OTHER_SECTIONS="${RELOCATING+PROVIDE (_stack = 0x30000);}" +unset STACK_ADDR +OTHER_SYMBOLS="PROVIDE (_stack = 0x30000);" +test -n "$CREATE_SHLIB" && unset OTHER_SYMBOLS OUTPUT_FORMAT="elf32-shl-symbian" SCRIPT_NAME=elf32sh-symbian diff --git a/ld/scripttempl/arclinux.sc b/ld/scripttempl/arclinux.sc index f3668d2..e692f13 100644 --- a/ld/scripttempl/arclinux.sc +++ b/ld/scripttempl/arclinux.sc @@ -303,10 +303,11 @@ DTOR=".dtors ${CONSTRUCTING-0} : KEEP (*(.dtors)) ${CONSTRUCTING+${DTOR_END}} }" -STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : +STACK=".stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : { ${RELOCATING+${USER_LABEL_PREFIX}_stack = .;} *(.stack) + ${RELOCATING+${STACK_SENTINEL}} }" TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})" @@ -649,6 +650,9 @@ SHLIB_LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${SHLIB_LARGE_DATA_A ${RELOCATING+${OTHER_END_SYMBOLS}} ${RELOCATING+${END_SYMBOLS-${USER_LABEL_PREFIX}_end = .; PROVIDE (${USER_LABEL_PREFIX}end = .);}} ${RELOCATING+${DATA_SEGMENT_END}} + ${TINY_DATA_SECTION} + ${TINY_BSS_SECTION} + ${STACK_ADDR+${STACK}} EOF test -z "${NON_ALLOC_DYN}" || emit_dyn @@ -669,11 +673,6 @@ EOF . $srcdir/scripttempl/DWARF.sc cat <