playing with .ld script

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

playing with .ld script

Post by KanedaFr » Wed Jul 22, 2015 9:04 pm

Hi,

to update my current linking script, I'm "playing" with the section stuff

There is something I couldn't find a good explanation about :

With C based code, I should code this way

1/ on file.c file

Code: Select all

void func1(void) __attribute__((section(".hack"))); 
2/ on .ld

Code: Select all

.hack 0x000FFB20:
  {
/* nothing here, if I add file.o, it won't work */
  } >rom =0xFF

while with asm based code, I should write

1/ on file.asm file

Code: Select all

.section hack
.globl func1
func1:
 ; insert code here
2/ in .ld file

Code: Select all

.hack 0x000FFB20:
  {
     file.o
/* if I omit file.o, like for c file, it won't work
  } >rom =0xFF


so
in C : __attribut__((section())) and nothing on .ld
in asm : .section and file added to section on .ld

what does the C compiler do to avoid the file.o on .ld ?!
it'd prefer to use the file.o on .ld on C too, it would avoid to declare every function and vars of a file with __attribute__((section()))


any GCC guru ? ;)

ElBarto
Very interested
Posts: 160
Joined: Wed Dec 13, 2006 10:29 am
Contact:

Re: playing with .ld script

Post by ElBarto » Fri Jul 24, 2015 6:49 am

KanedaFr wrote:

Code: Select all

.hack 0x000FFB20:
  {
/* nothing here, if I add file.o, it won't work */
  } >rom =0xFF
Should be :

Code: Select all

.hack 0x000FFB20:
  {
     *(.hack*)
  } >rom =0xFF
With eventually some align if the section before and after aren't aligned.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Sat Jul 25, 2015 2:47 pm

hooo...so it's the way to do to handle C & asm
interesting...

and could i control in which order files/func/resource will be added to this area ?
does the order given on gcc linking phase is enough ?

since it's mainly for hack, I'd like to be sure my main hack func is linked at the address I call ;)

ElBarto
Very interested
Posts: 160
Joined: Wed Dec 13, 2006 10:29 am
Contact:

Post by ElBarto » Sun Jul 26, 2015 1:40 am

You can't specify the order unless to specifically include a file in the section (but you shouldn't except for the startup code).

Why do you care about the order ?

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Aug 04, 2015 1:59 pm

because, like it's for hacking, I need to be sure my jumps table is the first data on this space
to be able to call it for anywhere

the linking order is not enough so...

in this case, perhaps I just need to use

Code: Select all

.hack 0x000FFB20: 
  { 
     jumptable.o
     *(.hack*) 
  } >rom =0xFF 
I'll test it soon

thanks anyway for the hint !

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Tue Aug 04, 2015 2:54 pm

so...

Code: Select all

.hack 0x000FFB20: 
  { 
     *(.hack*) 
  } >rom =0xFF 
is right for c code defined using
__attribute__((section(".hack")));

but it doesn't work for asm code defined using
.section hack

Post Reply