GP2X Changing Start Address Of Linux Executable


Squidge

Certified Guru
Joined
Nov 16, 2003
Messages
8,493
Location
UK
Website
Visit site
It seems that an executable in Linux always starts at virtual address 0x8000. Is there any way of changing this? I don't mind hacking the ELF or the compiler, I just want it to start at a different address, as it's screwing up my exceedingly cunning plan... :(
 
Can you put a JMP to the location you want, to replace the 0x8000 one?

My friend says ld may have some way to do what you want. Not sure.
 
It seems that an executable in Linux always starts at virtual address 0x8000. Is there any way of changing this? I don't mind hacking the ELF or the compiler, I just want it to start at a different address, as it's screwing up my exceedingly cunning plan... :(
Link with 'ld'. You can do just about anything you'd like. It's not quite clear to me what you want to do exactly (and I'd guess it would give away your secret cunning plan to tell), but you can move the text segment where you'd like with "-Ttext 0xADDRESS".
 
Last edited by a moderator:
Thanks for the replies - I can't use a branch as I need the compiler to ensure the code is built to run at the new address.

I'll try what DZZ suggests and see if it works. Ideally, I'd like to relocate the text segment to something like 0x10000000 instead of 0x00008000.
 
Thanks for the replies - I can't use a branch as I need the compiler to ensure the code is built to run at the new address.

I'll try what DZZ suggests and see if it works. Ideally, I'd like to relocate the text segment to something like 0x10000000 instead of 0x00008000.

HH trampoline?
 
Last edited by a moderator:
Thanks for the replies - I can't use a branch as I need the compiler to ensure the code is built to run at the new address.

I'll try what DZZ suggests and see if it works. Ideally, I'd like to relocate the text segment to something like 0x10000000 instead of 0x00008000.

HH trampoline?

Nope! The program still runs needs to be able to run under Linux after the entry point modification has taken place.

I just need to reserve a large portion of the lower memory for something :ph34r:
 
Last edited by a moderator:
Link with 'ld'. You can do just about anything you'd like. It's not quite clear to me what you want to do exactly (and I'd guess it would give away your secret cunning plan to tell), but you can move the text segment where you'd like with "-Ttext 0xADDRESS".

Ok, -Ttext 0xADDRESS didn't work too well. ld completely ignored me :(

Try with "--section-start" as well, but the same result :(

However, feeding ld a linkerscript with:

PROVIDE (__executable_start = 0x10000000); . = 0x10000000 + SIZEOF_HEADERS;

Seems to work just fine :)

Now... next job is to patch into the Linux SWI handler :D
 
Last edited by a moderator:
Link with 'ld'. You can do just about anything you'd like. It's not quite clear to me what you want to do exactly (and I'd guess it would give away your secret cunning plan to tell), but you can move the text segment where you'd like with "-Ttext 0xADDRESS".

Ok, -Ttext 0xADDRESS didn't work too well. ld completely ignored me :(

Try with "--section-start" as well, but the same result :(

However, feeding ld a linkerscript with:

PROVIDE (__executable_start = 0x10000000); . = 0x10000000 + SIZEOF_HEADERS;

Seems to work just fine :)

Now... next job is to patch into the Linux SWI handler :D
Glad you got it working! I had done a quick test using ld with the -Ttext and objdump indicated that it was putting stuff where I told it to, but that was a pretty simple application.

Now that you've mastered linker scripts you are truly a god.
 
Last edited by a moderator:
Thanks for the replies - I can't use a branch as I need the compiler to ensure the code is built to run at the new address.

I'll try what DZZ suggests and see if it works. Ideally, I'd like to relocate the text segment to something like 0x10000000 instead of 0x00008000.

HH trampoline?

Nope! The program still runs needs to be able to run under Linux after the entry point modification has taken place.

I just need to reserve a large portion of the lower memory for something :ph34r:

binary compressor? With a de-compressing animation? I always wanted Spiv to add that to b2fxec... b2gpec my guess...
 
Last edited by a moderator:
Last edited by a moderator:
Ok, I'll come clean.

It was originally for a GBA emulator.

However, I'm thinking GP32 is better to test my core "technology" and get that working without worrying about the GBA stuff. Once everything works as it should, I can then move on to GBA emulation. The basic foundation will support both systems quite nicely I think.
 
Back
Top