I was just spending the last few hours trying to track down a problem in devkitarm.
I was having a problem where "__data_start__" came in memory after "__data_end__", so when the crt0 code copies data into ram, it copies a negative number (big number) of bytes, and crashes.
After searching for the cause, I found that using the "--gc-sections" switch on the linker was causing problems when using EWRAM BSS variables.
I've attached a minimal example project that demonstrates the problem. The program just turns the screen red, but if it crashes in crt0 before the program starts, the screen remains white.
Using --gc-sections puts __data_end__ before __data_start__
Using --gc-sections puts __data_end__ before __data_start__
- Attachments
-
- example.zip
- Example project which illustrates the problem.
- (1.94 KiB) Downloaded 376 times
Re: Using --gc-sections puts __data_end__ before __data_star
Also, there's another problem.
In crt0, it overwrites the SBSS section with junk data, because it's copying from __ewram_start__ to __ewram_end__, which is past the end of the SBSS section. It should be copying up to __sbss_start__ instead.
In the crt0.s file, change this:
to this:
In crt0, it overwrites the SBSS section with junk data, because it's copying from __ewram_start__ to __ewram_end__, which is past the end of the SBSS section. It should be copying up to __sbss_start__ instead.
In the crt0.s file, change this:
Code: Select all
@---------------------------------------------------------------------------------
CIW0Skip:
@---------------------------------------------------------------------------------
@ Copy external work ram (ewram section) from LMA to VMA (ROM to RAM)
@---------------------------------------------------------------------------------
ldr r1, =__ewram_lma
ldr r2, =__ewram_start
ldr r4, =__ewram_end
bl CopyMemChk
Code: Select all
@---------------------------------------------------------------------------------
CIW0Skip:
@---------------------------------------------------------------------------------
@ Copy external work ram (ewram section) from LMA to VMA (ROM to RAM)
@---------------------------------------------------------------------------------
ldr r1, =__ewram_lma
ldr r2, =__ewram_start
ldr r4, =__sbss_start__
bl CopyMemChk
-
- Site Admin
- Posts: 2004
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: Using --gc-sections puts __data_end__ before __data_star
Those are both linkscript problems by the looks of things - __ewram_end shouldn't have been after the sbss section and there seems to have been some oddities in the sections which go in the data section.
I just committed some changes to gba_cart.ld and gba_mb.ld, grab them from SVN and copy to devkitARM/arm-eabi/lib
http://devkitpro.svn.sourceforge.net/vi ... abi/crtls/
These changes seem to fix your testcase, shout if you spot any more issues.
I just committed some changes to gba_cart.ld and gba_mb.ld, grab them from SVN and copy to devkitARM/arm-eabi/lib
http://devkitpro.svn.sourceforge.net/vi ... abi/crtls/
These changes seem to fix your testcase, shout if you spot any more issues.
Who is online
Users browsing this forum: No registered users and 8 guests