Page 1 of 1

Linker scripts [solved]

Posted: Fri Mar 31, 2006 8:58 am
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.

Re:Linker scripts [solved]

Posted: Mon Apr 03, 2006 7:02 am
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.