Using --gc-sections puts __data_end__ before __data_start__

support for the ARM toolchain
Post Reply
Dwedit
Posts: 43
Joined: Sun Jan 06, 2008 4:06 am

Using --gc-sections puts __data_end__ before __data_start__

Post by Dwedit » Wed Oct 19, 2011 7:24 pm

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.
Attachments
example.zip
Example project which illustrates the problem.
(1.94 KiB) Downloaded 331 times

Dwedit
Posts: 43
Joined: Sun Jan 06, 2008 4:06 am

Re: Using --gc-sections puts __data_end__ before __data_star

Post by Dwedit » Wed Oct 19, 2011 7:49 pm

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:

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
to 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, =__sbss_start__
	bl	CopyMemChk

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Using --gc-sections puts __data_end__ before __data_star

Post by WinterMute » Wed Oct 19, 2011 10:39 pm

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.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest