This is the mail archive of the binutils@sources.redhat.com 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]

SH-ELF (& COFF): Setting of _stack and placement of stack sentinel value (Was: Re: [PATCH]crt1.asm- _stack symbol causes problem for SH-ELF-Pl. refer accepted patch at newlib by Jeff J.)


anitak wrote:
> 
> Hi,
> Yes, crt1.asm is used for elf port. Same problem (described in previous
> mail) occurs for ELF as well as for coff,hms.
> The symbol is already present in the default sh-elf linker script just like
> coff. So removing it from crt1.asm may not cause any problem.
> Regards,
> Anita

It's not only defining the symbol, it also provides a sentinel value, which
can be useful when you are debuginf on the simulator and return one level too
much.
OTOH, when you place the stack at the bottom of the RAM on actual hardware,
the sentinel value has no place to go.  We could arrange for it to be put
inside the stack proper (i.e. at _stack - 4), but that would waste a little
space from the not necessarily abundent RAM, and it would also require
initialization where no initialization is required otherwise.
Thus, it seem that the decision if a sentinel value is used or not should be
made by the linker script.
There is another wart in the current linker script, i.e. the bottom of the
stack is hard-wired to 0x30000, and you can't override it with --defsym.

To address these issues, I have attached a patch that makes the default
linker script respect the _stack symbol if it is predefined, and place
a sentinel value at the bottom of the stack.  Thus I can remove the symbol
and sentinel value from crt1.asm.  I have also removed the vestigial .section
directive from crt0.S .

There are four linker scripts in libgloss/sh that presumably need updating,
since they don't define _stack, but only __stack.  They do look somewhat
funny already, though, since they talk about for support for both a.out and
coff, and SGI/MIPS DWARF 2 extensions.
And the constructor / destructor scheme looks like coff, which means that
it was broken by the newlib change in December.

Is anybody actually using these scripts?
	
-- 
--------------------------
SuperH
2430 Aztec West / Almondsbury / BRISTOL / BS32 4AQ
T:+44 1454 462330
Wed Jun 19 20:44:28 2002  J"orn Rennecke <joern.rennecke@superh.com>

ld:
	* emulparams/shelf.sh (STACK_ADDR): Don't define.
	(OTHER_SECTIONS): Define.
	* emulparams/shelf_nbsd.sh ((STACK_ADDR): Don't undef.
	(OTHER_SECTIONS): Undef.
newlib:
	* libc/sys/sh/crt0.S: Remove vestigial .section directive.
gcc:
	* config/sh/crt1.asm: remove _stack label definition
	and sentinel value.

Index: ld/emulparams/shelf.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/shelf.sh,v
retrieving revision 1.3
diff -p -r1.3 shelf.sh
*** ld/emulparams/shelf.sh	8 Jan 2002 04:23:02 -0000	1.3
--- ld/emulparams/shelf.sh	19 Jun 2002 19:31:49 -0000
*************** CTOR_START='___ctors = .;'
*** 17,20 ****
  CTOR_END='___ctors_end = .;'
  DTOR_START='___dtors = .;'
  DTOR_END='___dtors_end = .;'
! STACK_ADDR=0x30000
--- 17,32 ----
  CTOR_END='___ctors_end = .;'
  DTOR_START='___dtors = .;'
  DTOR_END='___dtors_end = .;'
! # This is like setting STACK_ADDR to 0x30000, 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).
! OTHER_SECTIONS="  .stack        ${RELOCATING-0}${RELOCATING+(DEFINED(_stack) ? _stack : 0x30000)} :
!   {
!     ${RELOCATING+_stack = .;}
!     *(.stack)
!     LONG(0xdeaddead)
!   }"
! 
Index: ld/emulparams/shelf_nbsd.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/shelf_nbsd.sh,v
retrieving revision 1.1
diff -p -r1.1 shelf_nbsd.sh
*** ld/emulparams/shelf_nbsd.sh	8 Jan 2002 04:23:02 -0000	1.1
--- ld/emulparams/shelf_nbsd.sh	19 Jun 2002 19:31:49 -0000
*************** DATA_START_SYMBOLS='__data_start = . ;';
*** 12,15 ****
  ENTRY=_start
  
  unset EMBEDDED
! unset STACK_ADDR
--- 12,15 ----
  ENTRY=_start
  
  unset EMBEDDED
! unset OTHER_SECTIONS
Index: newlib/libc/sys/sh/crt0.S
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/sh/crt0.S,v
retrieving revision 1.3
diff -p -r1.3 crt0.S
*** newlib/libc/sys/sh/crt0.S	8 Feb 2002 07:11:13 -0000	1.3
--- newlib/libc/sys/sh/crt0.S	19 Jun 2002 19:31:49 -0000
*************** main_k:
*** 113,121 ****
  exit_k:
  	.long	_exit
  #endif
- 
- #ifdef __ELF__
- 	.section .stack,"aw"
- #else
- 	.section .stack
- #endif
--- 113,115 ----
Index: gcc/config/sh/crt1.asm
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sh/crt1.asm,v
retrieving revision 1.5
diff -p -r1.5 crt1.asm
*** gcc/config/sh/crt1.asm	9 Feb 2002 03:08:06 -0000	1.5
--- gcc/config/sh/crt1.asm	19 Jun 2002 19:33:25 -0000
*************** ___main:
*** 174,183 ****
  	rts
  	nop
  #endif
- 
- #ifdef __ELF__
- 	.section .stack,"aw"
- #else
- 	.section .stack
- #endif
- _stack:	.long	0xdeaddead
--- 174,176 ----

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