[Patch] arm crt0.S: call _init and _fini
Nick Clifton
nickc@cambridge.redhat.com
Fri Sep 14 03:28:00 GMT 2001
Hi Guys,
I have applied this patch to the arm's crt0.S file to allow it to
call the _init and _fini functions to build C++ constructors and
destructors.
Cheers
Nick
2001-09-14 Nick Clifton <nickc@cambridge.redhat.com>
* libc/sys/arm/crt0.S: Add calls to _init and _fini (via atexit)
for new style arm/elf ctor/dtor handling.
Minor formatting tidy up.
Index: newlib/libc/sys/arm/crt0.S
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/arm/crt0.S,v
retrieving revision 1.2
diff -p -r1.2 crt0.S
*** crt0.S 2000/06/28 18:14:14 1.2
--- crt0.S 2001/09/14 10:23:27
*************** __change_mode:
*** 181,192 ****
#endif
#endif
bl FUNCTION (main)
! bl FUNCTION (exit) /* Should not return */
#ifdef __thumb__
! /* Come out of Thumb mode... This code should be redundant... */
mov a4, pc
bx a4
--- 181,202 ----
#endif
#endif
+
+ #ifdef __USES_INITFINI__
+ /* Some arm/elf targets use the .init and .fini sections
+ to create constructors and destructors, and for these
+ targets we need to call the _init function and arrange
+ for _fini to be called at program exit. */
+ ldr r0, .Lfini
+ bl FUNCTION (atexit)
+ bl FUNCTION (_init)
+ #endif
bl FUNCTION (main)
! bl FUNCTION (exit) /* Should not return. */
#ifdef __thumb__
! /* Come out of Thumb mode. This code should be redundant. */
mov a4, pc
bx a4
*************** change_back:
*** 223,241 ****
.word __bss_start__
.LC2:
.word __bss_end__
!
#ifdef ARM_RDI_MONITOR
! .LC30: .word CommandLine
.word 255
! /* Workspace for Angel calls. */
.data
! /* Data returned by monitor SWI */
HeapBase: .word 0
HeapLimit: .word 0
StackBase: .word 0
StackLimit: .word 0
! CommandLine: .space 256,0 /* Maximum length of 255 chars handled */
#endif
#ifdef __pe__
--- 231,253 ----
.word __bss_start__
.LC2:
.word __bss_end__
! #ifdef __USES_INITFINI__
! .Lfini:
! .word FUNCTION(_fini)
! #endif
#ifdef ARM_RDI_MONITOR
! .LC30:
! .word CommandLine
.word 255
! /* Workspace for Angel calls. */
.data
! /* Data returned by monitor SWI. */
HeapBase: .word 0
HeapLimit: .word 0
StackBase: .word 0
StackLimit: .word 0
! CommandLine: .space 256,0 /* Maximum length of 255 chars handled. */
#endif
#ifdef __pe__
More information about the Newlib
mailing list