You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#1
gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/17 6:27
Nintendoid!
Joined 2007/12/14
169 Posts
CoderLong Time User (11 Years) App Coder
Working on my project, building in GCC 4, I have finally run into the issue shown in the attached screenshot and described in this post http://www.planetvb.com/modules/newbb ... t_id=10819#forumpost10819 . What in C is an innocent call to a function I've defined, compiles to a jump to 0x0800027c-- somewhere in VRAM, where Mednafen happily executes whatever is there. =P

I'm willing to look into it and dig into the GCC code but I haven't the first thought of where to start. Any ideas?

Attach file:



png  BPRvWMxCIAA-xUE.png (26.12 KB)
676_51e61ce887efb.png 762X445 px
Top

#2
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/23 7:23
Nintendoid!
Joined 2007/12/14
169 Posts
CoderLong Time User (11 Years) App Coder
Some more info for anyone other than me who may be looking at this:

Running 'v810-objdump -t' on the ELF file reveals that the symbol table is correct-- in fact, the bogus address highlighted in the screenshot above is nowhere to be found in the symtable. I'm inclined to believe therefore that this might be a linker issue, though the linker script I'm using works fine in gccVB 2, so this is a weak theory.

Also, for what it's worth, the difference between the bogus address and the one in the symbol table is 16766404 (FFD5C4) bytes-- almost 16M.
Top

#3
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/23 8:35
PVB Elite
Joined 2003/7/26
USA
1465 Posts
PVBCC EntryCoderContributorSpecial AchievementTop10 PosterHOTY09 EntryLong Time User (15 Years) App Coder20+ Game RatingsPVBCC 2013 Entry
I'm definitely interested in this topic (and squashing the bug), I'm just too dumb to add anything of use

...although, I don't think your "broken linker" theory is all that weak. In my experience, "what works in GCC2 should work in GCC4" is far from a valid assumption. But, again, I don't know enough about the inner workings of either to say for sure, or to help fix it if that's the problem.

Is there a certain pattern of code that triggers the bug, or is it just when a project gets to a certain size? Have you got a minimal example? Have you checked to see if anyone using another GCC4 target has encountered a similar bug?
Top

#4
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/23 8:35
PVB Elite
Joined 2011/7/1
Germany
1123 Posts
CoderContributorTop10 PosterLong Time User (8 Years) App CoderPVBCC 2013 Entry
Quote:

blitter wrote:
Some more info for anyone other than me who may be looking at this:

Running 'v810-objdump -t' on the ELF file reveals that the symbol table is correct-- in fact, the bogus address highlighted in the screenshot above is nowhere to be found in the symtable. I'm inclined to believe therefore that this might be a linker issue, though the linker script I'm using works fine in gccVB 2, so this is a weak theory.

Also, for what it's worth, the difference between the bogus address and the one in the symbol table is 16766404 (FFD5C4) bytes-- almost 16M.


I'm reading this as well. I have just no idea how to help you. I find it interesting though.
Top

#5
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/24 22:41
Nintendoid!
Joined 2012/8/5
USA
117 Posts
CoderLong Time User (7 Years) PVBCC 2013 3rd
Like RunnerPack I don't know much about the behind the scenes stuff but I'm always up for learning something new. Any chance you can post some source code or the rom so I can have something to reproduce the error? I don't have anything that produces this error (yet). I wouldn't mind poking around in my free time.
Top

#6
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/25 7:47
Nintendoid!
Joined 2007/12/14
169 Posts
CoderLong Time User (11 Years) App Coder
More progress!

I think I've found a pattern to the addresses that do get generated. Basically, jal is jumping way too far ahead-- in multiples of 0x400000-- but sometimes still landing in a mirror of the ROM, where everything seemingly works fine. However, as the code in the mirrored ROM continues to get executed, and the logic returns to that same jal instruction, it points to an address yet another 0x400000 ahead. Eventually this takes the code path somewhere beyond the 0x07xxxxxx range of the ROM, causing a crash.

I've attached a ROM of a trimmed down version of my current WIP. Start it paused in Mednafen's debugger, then look at the instruction at address 0x07001d5e, 0x07401d5e, 0x07801d5e, and so on.

Attach file:


vb Link Bug Test.vb Size: 128.00 KB; Hits: 138
Top

#7
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/25 7:55
Nintendoid!
Joined 2007/12/14
169 Posts
CoderLong Time User (11 Years) App Coder
I'm not going to post the source to my project right now, but I'll try to put together a minimal example with source code in the next few days.
Top

#8
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/26 3:39
Nintendoid!
Joined 2012/8/5
USA
117 Posts
CoderLong Time User (7 Years) PVBCC 2013 3rd
Seems really odd that the linker would come up with a jump of around 4M for a rom that's only 128k in size... I found the first odd jump at 700005ee. If I understand how the linker should work I would think the linker pointer would never calculate an address larger than the total rom size. Can you post your linker script the vb.ld?
Top

#9
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/26 4:27
Nintendoid!
Joined 2007/12/14
169 Posts
CoderLong Time User (11 Years) App Coder
Hmm, well this is a pleasant surprise...

At your suggestion I went to grab the vb.ld file to attach to this post, but figured I should first try making a minimal version of that too. What's attached is the result of that: a minimal linker script that actually seems to fix the problem for the moment-- at least, I don't see any bogus jal statements.

Hopefully I can close the book on this bug, but I'll keep my eyes open. :)

Attach file:


ld vb.ld Size: 1.46 KB; Hits: 154
Top

#10
Re: gccVB 4 and PC-relative calls/jumps
Posted on: 2013/7/26 23:57
Nintendoid!
Joined 2012/8/5
USA
117 Posts
CoderLong Time User (7 Years) PVBCC 2013 3rd
Good to hear. Hopefully that clears everything up for ya.
Top

 Top   Previous Topic   Next Topic


Register To Post