Page 1 of 1

playing with .ld script

Posted: Wed Jul 22, 2015 9:04 pm
by KanedaFr
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 ? ;)

Re: playing with .ld script

Posted: Fri Jul 24, 2015 6:49 am
by ElBarto
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.

Posted: Sat Jul 25, 2015 2:47 pm
by KanedaFr
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 ;)

Posted: Sun Jul 26, 2015 1:40 am
by ElBarto
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 ?

Posted: Tue Aug 04, 2015 1:59 pm
by KanedaFr
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 !

Posted: Tue Aug 04, 2015 2:54 pm
by KanedaFr
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