Linker scripts [solved]

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
paulbarker

Linker scripts [solved]

Post by paulbarker »

Heres an bit of my linker script, used for code & data which can be discarded once initialization has finished.

Code: Select all

    PROVIDE(init_start = .);

    /* Code and data which can be discarded after initialization. */
    .idata ALIGN(0x1000) : {
        *(.mbheader)        /* Must be at the start of the resulting image. */
        *(.idata)
    }
    .icode ALIGN(0x1000) : {
        *(.icode)
    }

    PROVIDE(init_end = .);
Now here's a bit from what readelf thinks of the resulting image.

Code: Select all

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 1] .idata            PROGBITS        00100000 001000 000020 00  WA  0   0 32
  [ 2] .icode            PROGBITS        00101000 004000 000040 00      0   0  1
  [ 3] .text             PROGBITS        00102000 002000 000115 00  AX  0   0  8
  [ 4] .rodata           PROGBITS        00103000 003000 00000f 00   A  0   0  1
  [ 5] .data             PROGBITS        00104000 004000 000000 00  WA  0   0  4
  [ 6] .bss              NOBITS          00104000 004000 005000 00  WA  0   0 32
(That looks better with a monospaced font)

Now, the issue here is that .idata should have the flags WA (alloc & writable) and .icode should have AX (alloc & executable). I've looked through the documentation for ld but I've found nothing about how to setup section flags. Does anyone know?

My kernel still works without this I just like things to be correct.

Cheers,
Paul Barker

EDIT: Putting a function written in c in .icode solves this. The assembler doesn't set the propper flags but gcc does.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Linker scripts [solved]

Post by Pype.Clicker »

another trick i used (as i have only ASM bits in those "init" section) was to let the assembler produce .text and .data sections (which it knows what type to give), but then rename the sections into .icode and .idata (or whatever) using objcopy, which will preserve their attributes.
Post Reply