This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Move .stack before debug sections


If strip removes debug sections, then any dynamic _stack symbol
section index becomes invalid, due to it being defined in .stack.  So,
move .stack earlier.  I'm sure there are other sections that should be
moved too, but that can wait until they prove troublesome.

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  <amodra@gmail.com>
+
+	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  <nickc@redhat.com>
 
 	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 <<EOF
-
-  ${TINY_DATA_SECTION}
-  ${TINY_BSS_SECTION}
-
-  ${STACK_ADDR+${STACK}}
   ${ATTRS_SECTIONS}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}
diff --git a/ld/scripttempl/armbpabi.sc b/ld/scripttempl/armbpabi.sc
index 0657aa9..dee1028 100644
--- a/ld/scripttempl/armbpabi.sc
+++ b/ld/scripttempl/armbpabi.sc
@@ -317,6 +317,7 @@ cat <<EOF
   ${RELOCATING+_end = .;}
   ${RELOCATING+PROVIDE (end = .);}
   ${RELOCATING+${DATA_SEGMENT_END}}
+  ${STACK_ADDR+${STACK}}
 
   /* These sections are not mapped under the BPABI.  */
   .dynamic      0 : { *(.dynamic) }
@@ -342,7 +343,6 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-  ${STACK_ADDR+${STACK}}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}
   ${RELOCATING+${DISCARDED}}
diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
index e65f9a3..d9138bc 100644
--- a/ld/scripttempl/elf.sc
+++ b/ld/scripttempl/elf.sc
@@ -305,10 +305,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})"
@@ -641,7 +642,7 @@ EOF
 LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${LARGE_DATA_ADDR-.});"
 SHLIB_LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${SHLIB_LARGE_DATA_ADDR-.});"
 
-  cat <<EOF
+cat <<EOF
   ${RELOCATING+${CREATE_SHLIB-${CREATE_PIE-${LARGE_DATA_ADDR}}}}
   ${RELOCATING+${CREATE_SHLIB+${SHLIB_LARGE_DATA_ADDR}}}
   ${RELOCATING+${CREATE_PIE+${SHLIB_LARGE_DATA_ADDR}}}
@@ -651,6 +652,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
@@ -671,11 +675,6 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-
-  ${TINY_DATA_SECTION}
-  ${TINY_BSS_SECTION}
-
-  ${STACK_ADDR+${STACK}}
   ${ATTRS_SECTIONS}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}
diff --git a/ld/scripttempl/elf64hppa.sc b/ld/scripttempl/elf64hppa.sc
index b741f88..dec42b5 100644
--- a/ld/scripttempl/elf64hppa.sc
+++ b/ld/scripttempl/elf64hppa.sc
@@ -255,10 +255,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+_stack = .;}
+    ${RELOCATING+${USER_LABEL_PREFIX}_stack = .;}
     *(.stack)
+    ${RELOCATING+${STACK_SENTINEL}}
   }"
 
 TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})"
@@ -513,6 +514,9 @@ cat <<EOF
   ${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
 
 if test -n "${NON_ALLOC_DYN}"; then
@@ -545,10 +549,6 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-  ${TINY_DATA_SECTION}
-  ${TINY_BSS_SECTION}
-
-  ${STACK_ADDR+${STACK}}
   ${ATTRS_SECTIONS}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}
diff --git a/ld/scripttempl/elf_chaos.sc b/ld/scripttempl/elf_chaos.sc
index b6d5956..8fe15b4 100644
--- a/ld/scripttempl/elf_chaos.sc
+++ b/ld/scripttempl/elf_chaos.sc
@@ -317,6 +317,7 @@ cat <<EOF
   ${RELOCATING+${OTHER_END_SYMBOLS}}
   ${RELOCATING+_end = .;}
   ${RELOCATING+PROVIDE (end = .);}
+  ${STACK_ADDR+${STACK}}
 
   /* Stabs debugging sections.  */
   . = ALIGN(0x1000);
@@ -335,7 +336,6 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-  ${STACK_ADDR+${STACK}}
   ${ATTRS_SECTIONS}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}
diff --git a/ld/scripttempl/elfarc.sc b/ld/scripttempl/elfarc.sc
index 9d1e139..6754c02 100644
--- a/ld/scripttempl/elfarc.sc
+++ b/ld/scripttempl/elfarc.sc
@@ -433,7 +433,6 @@ cat <<EOF
   /* ARC Extension Sections */
   .arcextmap	  0 : { *(.gnu.linkonce.arcextmap.*) }
 
-  ${STACK_ADDR+${STACK}}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_END_SYMBOLS}}
   ${RELOCATING+${STACKNOTE}}
diff --git a/ld/scripttempl/elfxtensa.sc b/ld/scripttempl/elfxtensa.sc
index 6eb9d33..769168e 100644
--- a/ld/scripttempl/elfxtensa.sc
+++ b/ld/scripttempl/elfxtensa.sc
@@ -272,10 +272,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+_stack = .;}
+    ${RELOCATING+${USER_LABEL_PREFIX}_stack = .;}
     *(.stack)
+    ${RELOCATING+${STACK_SENTINEL}}
   }"
 
 # If this is for an embedded system, don't add SIZEOF_HEADERS.
@@ -523,6 +524,9 @@ cat <<EOF
   ${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
 
 if test -n "${NON_ALLOC_DYN}"; then
@@ -555,10 +559,6 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-  ${TINY_DATA_SECTION}
-  ${TINY_BSS_SECTION}
-
-  ${STACK_ADDR+${STACK}}
   ${ATTRS_SECTIONS}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}
diff --git a/ld/scripttempl/epiphany_4x4.sc b/ld/scripttempl/epiphany_4x4.sc
index 10d3d23..b661fc2 100644
--- a/ld/scripttempl/epiphany_4x4.sc
+++ b/ld/scripttempl/epiphany_4x4.sc
@@ -54,7 +54,6 @@
 # 	combination of .init sections.
 #	FINI_START, FINI_END - statements just before and just after
 # 	combination of .fini sections.
-#	STACK_ADDR - start of a .stack section.
 #	OTHER_SYMBOLS - symbols to place right at the end of the script.
 #	ETEXT_NAME - name of a symbol for the end of the text section,
 #		normally etext.
@@ -242,11 +241,6 @@ DTOR=".dtors     ADDR(.ctors) + SIZEOF(.ctors)    ${CONSTRUCTING-0} :
     KEEP (*(.dtors))
     ${CONSTRUCTING+${DTOR_END}}
   }   /*> INTERNAL_RAM*/ "
-STACK="  .stack        ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
-  {
-    ${RELOCATING+___stack = .;}
-    *(.stack)
-  }"
 
 # If this is for an embedded system, don't add SIZEOF_HEADERS.
 if [ -z "$EMBEDDED" ]; then
@@ -608,6 +602,12 @@ cat <<EOF
   ${RELOCATING+${OTHER_END_SYMBOLS}}
   ${RELOCATING+${END_SYMBOLS-${USER_LABEL_PREFIX}_end = .; PROVIDE (${USER_LABEL_PREFIX}end = .);}}
   ${RELOCATING+${DATA_SEGMENT_END}}
+
+  PROVIDE ( __stack_start_ = ORIGIN(EXTERNAL_DRAM_0) + __PROG_SIZE_FOR_CORE__ * __CORE_NUM_ + __PROG_SIZE_FOR_CORE__  - 0x10) ;
+  .stack ${RELOCATING+__stack_start_} :  {    ${RELOCATING+___stack = .;}    *(.stack)  }
+
+  PROVIDE (  ___heap_start = ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_ );
+  PROVIDE (  ___heap_end =   ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_  + __HEAP_SIZE_FOR_CORE__ - 4 );
 EOF
 
 if test -n "${NON_ALLOC_DYN}"; then
@@ -640,23 +640,6 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-  ${TINY_DATA_SECTION}
-  ${TINY_BSS_SECTION}
-
-  /*${STACK_ADDR+${STACK}}*/
-  
-  PROVIDE ( __stack_start_ = ORIGIN(EXTERNAL_DRAM_0) + __PROG_SIZE_FOR_CORE__ * __CORE_NUM_ + __PROG_SIZE_FOR_CORE__  - 0x10) ;
-  .stack ${RELOCATING+__stack_start_} :  {    ___stack = .;    *(.stack)  }
-
-  PROVIDE (  ___heap_start = ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_ );
-  /*.heap_start      __heap_start_    :  {    _heap_start_ = .;    *(.heap_start)  }*/
-
-  PROVIDE (  ___heap_end =   ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_  + __HEAP_SIZE_FOR_CORE__ - 4 );
-  
-  
- /* .heap_end      __heap_end_    :  {    _heap_end_ = .;    *(.heap_end)  }*/
-
-
   ${ATTRS_SECTIONS}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}
diff --git a/ld/scripttempl/nds32elf.sc b/ld/scripttempl/nds32elf.sc
index de2b28b..db4bf57 100644
--- a/ld/scripttempl/nds32elf.sc
+++ b/ld/scripttempl/nds32elf.sc
@@ -246,10 +246,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})"
@@ -594,6 +595,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
@@ -614,11 +618,6 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-
-  ${TINY_DATA_SECTION}
-  ${TINY_BSS_SECTION}
-
-  ${STACK_ADDR+${STACK}}
   ${ATTRS_SECTIONS}
   ${OTHER_SECTIONS}
   ${RELOCATING+${OTHER_SYMBOLS}}

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]