Re: __stack_start for ColdFire uClinux

Larry Baker <[email protected]>
Newsgroups gmane.linux.uclinux.devel
Message-ID <[email protected]>
Greg,

As far as my task 2) to properly detect stack overflow, I think the source of my problem is that the __stack_start symbol is not correctly defined.

I found the flthdr -k option to enable the FLAT_FLAG_KTRACE flag for printing the executable layout. 

> # toolchains/freescale-coldfire-2011.09/bin/m68k-uclinux-flthdr check-stack-overflow
> check-stack-overflow
>     Magic:        bFLT
>     Rev:          4
>     Build Date:   Wed Sep 26 16:52:43 2012
>     Entry:        0x44
>     Data Start:   0x3ca0
>     Data End:     0x4544
>     BSS End:      0x65f0
>     Stack Size:   0x1000
>     Reloc Start:  0x4544
>     Reloc Count:  0x29
>     Flags:        0x12 ( Has-PIC-GOT Kernel-Traced-Load )

When I run the program, I can see that the stack overflow checking is not preventing the stack from getting clobbered.  The stack overruns into the BSS, causing the hardware watchdog timer to trip.

> / # check-stack-overflow 
> BINFMT_FLAT: Loading file: /usr/bin/check-stack-overflow
> Mapping is 4063c000, Entry point is 44, data_start is 3ca0
> Load /usr/bin/check-stack-overflow: TEXT=4063c040-4063fca0 DATA=40608004-406088a8 BSS=406088a8-4060a954
> __stack_start = 0x406088b4
> %sp = 0x4060beec
> i = 1
> %sp = 0x4060bae0
> i = 2
> %sp = 0x4060b6d4
> i = 3
> %sp = 0x4060b2c8
> i = 4
> %sp = 0x4060aebc
> i = 5
> %sp = 0x4060aab0
> i = 6
> %sp
> 
> Watchdog Timer Reset


__stack_start (0x406088b4) is clearly wrong; it should have a value greater than the end of the BSS section (0x4060a954).

I can see __stack_start has the wrong value in the symbol table.  Here's a sorted (by section, address) list of the symbols:

> # toolchains/freescale-coldfire-2011.09/bin/m68k-uclinux-objdump -t check-stack-overflow.gdb
> 
> check-stack-overflow.gdb:     file format elf32-m68k
> 
> SYMBOL TABLE:
> 
> 
> 00000000  w      *UND*	00000000 __deregister_frame_info
> 00000000  w      *UND*	00000000 __h_errno_location
> 00000000  w      *UND*	00000000 __pthread_initialize_minimal
> 00000000  w      *UND*	00000000 __register_frame_info
> 00000000  w      *UND*	00000000 _Jv_RegisterClasses
> 00000000 l       *ABS*	00000000 EBITS
> 00000000 l       *ABS*	00000000 EQUAL
> 00000000 l       *ABS*	00000000 have_current_got
> 00000000 l       *ABS*	00000000 have_current_got
> 00000000 l       *ABS*	00000000 NIL
> 00000000 l       *ABS*	00000000 NOOP
[snip]
> ffffffff l       *ABS*	00000000 LESS
> ffffffff l       *ABS*	00000000 QUIET_NaN
> ffffffff l       *ABS*	00000000 UNKNOWN
> ffffffff l       *ABS*	00000000 UNKNOWN
> 00000000 l    df *ABS*	00000000 __C_ctype_b.c
> 00000000 l    df *ABS*	00000000 __errno_location.c
> 00000000 l    df *ABS*	00000000 __uClibc_main.c
[snip]
> 00000000 l    df *ABS*	00000000 write.c
> 00004510 g       *ABS*	00000000 _edata
> 00000000 l    d  .text	00000000 .text
> 00000004 g       .text	00000000 _stext
> 00000004 g     F .text	00000000 _start
[snip]
> 00003be0 l     F .text	00000000 __do_global_ctors_aux
> 00003c0e l     F .text	00000000 call___do_global_ctors_aux
> 00003c1c l     O .text	00000000 __JCR_END__
> 00003c1c l     O .text	00000000 __JCR_LIST__
> 00003c20 g     F .text	00000000 _init
> 00003c34 g     F .text	00000000 _fini
> 00003c60 g       .text	00000000 _etext
> 00003c60 g       .data	00000000 __data_start
> 00003c60 g       .data	00000000 _sdata
> 00003c60 g       .data	00000000 _ssro_size
> 00003c60 g       .data	00000000 _ssrw_size
> 00003c60 g       .data	00000000 data_start
> 00003c60 l     O .data	00000000 _GLOBAL_OFFSET_TABLE_
> 00003c60 l    d  .data	00000000 .data
[snip]
> 00004500 l       .data	00000000 __fini_array_end
> 00004500 l       .data	00000000 __fini_array_start
> 00004500 l       .data	00000000 __init_array_end
> 00004500 l       .data	00000000 __init_array_start
> 00004500 l       .data	00000000 __preinit_array_end
> 00004500 l       .data	00000000 __preinit_array_start
> 00004500 l     O .eh_frame	00000000 __EH_FRAME_BEGIN__
> 00004500 l     O .eh_frame	00000000 __FRAME_END__
> 00004500 l    d  .eh_frame	00000000 .eh_frame
> 00004504 g       .bss	00000000 __bss_start
> 00004504 g       .bss	00000000 _sbss
> 00004504 l     O .bss	00000001 completed.4562
> 00004504 l    d  .bss	00000000 .bss
> 00004506 l     O .bss	00000004 dtor_idx.4564
> 0000450a l     O .bss	00000018 object.4577
> 00004524 g     O .bss	00000004 _stdio_openlist_del_count
> 00004528 g     O .bss	00000004 _stdio_openlist_use_count
> 0000452c l     O .bss	00002000 _fixed_buffers
> 0000652c l     O .bss	0000000a _bss_custom_printf_spec
> 00006538 l     O .bss	00000004 __rtld_fini
> 0000653c l     O .bss	00000004 __app_fini
> 00006540 g     O .bss	00000004 __pagesize
> 00006544  w    O .bss	00000004 environ
> 00006544 g     O .bss	00000004 __environ
> 00006548 g     O .bss	00000004 __libc_stack_end
> 0000654c l     O .bss	00000004 been_there_done_that.3075
> 00006550 l     O .bss	00000004 __exit_cleanup
> 00006554  w    O .bss	00000004 _h_errno
> 00006554 g     O .bss	00000004 h_errno
> 00006558  w    O .bss	00000004 _errno
> 00006558 g     O .bss	00000004 errno
> 0000655c l     O .bss	00000028 _custom_printf_arginfo
> 00006584 g     O .bss	00000028 .hidden _custom_printf_handler
> 000065b0 g       .bss	00000000 _ebss
> 000065b0 g       .bss	00000000 _end
> 000065b0 g       .bss	00000000 end
> 00004510 g       .comment	00000000 __stack_start
> 00000000 l    d  .comment	00000000 .comment
> 00000000 l    d  .debug_abbrev	00000000 .debug_abbrev
> 00000000 l    d  .debug_aranges	00000000 .debug_aranges
> 00000000 l    d  .debug_frame	00000000 .debug_frame
> 00000000 l    d  .debug_info	00000000 .debug_info
> 00000000 l    d  .debug_line	00000000 .debug_line
> 00000000 l    d  .debug_loc	00000000 .debug_loc
> 00000000 l    d  .debug_ranges	00000000 .debug_ranges
> 00000000 l    d  .debug_str	00000000 .debug_str


I don't know the ld scripting language.  I will try to figure out how to define __start_stack to have the same value as, for example, .bss _end.

In the mean time, I'll try using _end instead of __stack_start for the stack limit symbol.

Larry Baker
US Geological Survey
650-329-5608
[email protected]

_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.