I'm currently trying to move everything to the GNU toolchain (crosscompiler). One step is to convert the assembler files from nasm- to gas-syntax. But this causes trouble because gas orders the sections in a different way than nasm.
Some background:
I have a higherhalf-kernel. Therefore I create a section ".setup" which will be called from the bootloader (GRUB in my case) at the beginning, sets up the GDT and makes a far-jump to my higherhalf-kernel. When I use nasm the resulting sections of the file containing just the section ".setup" are (readelf -S header.o):
Code: Select all
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .setup PROGBITS 00000000 000130 00003a 00 A 0 0 1
[ 2] .shstrtab STRTAB 00000000 000170 00002d 00 0 0 1
[ 3] .symtab SYMTAB 00000000 0001a0 000090 10 4 6 4
[ 4] .strtab STRTAB 00000000 000230 000051 00 0 0 1
[ 5] .rel.setup REL 00000000 000290 000018 08 3 1 4
When I use gas I get the following:
Code: Select all
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 00000000 000034 000000 00 AX 0 0 4
[ 2] .data PROGBITS 00000000 000034 000000 00 WA 0 0 4
[ 3] .bss NOBITS 00000000 000034 000000 00 WA 0 0 4
[ 4] .setup PROGBITS 00000000 000034 00003a 00 0 0 1
...
- ld puts .setup at the end of the file (I really mean the offset in the file here; not the virtual address)
- that causes GRUB to tell me that he can't load my kernel ("Selected item cannot fit into memory").
At least thats the only difference I can see. The sections in the kernel, when using gas, are:
Code: Select all
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .setup PROGBITS 00100000 02ddb8 00003a 00 0 0 1
[ 2] .text PROGBITS c0100040 001040 020990 00 AX 0 0 16
[ 3] .eh_frame PROGBITS c01209d0 0219d0 000078 00 A 0 0 4
[ 4] .iplt PROGBITS c0120a48 021a48 000000 00 AX 0 0 4
[ 5] .rel.dyn REL c0120a48 021a48 000000 08 A 0 0 4
[ 6] .data PROGBITS c0121000 022000 00bdb8 00 WA 0 0 32
[ 7] .igot.plt PROGBITS c012cdb8 02ddb8 000000 00 WA 0 0 4
[ 8] .bss NOBITS c012d000 02ddb8 1f1ae0 00 WA 0 0 4096
...
When I use nasm .setup is @ 0x1000, i.e. before .text.
So my question is: Am I doing something wrong? Or is there a way to tell gas that it should order the sections like I do it in my assembler-file? Or can I specify that in the linker-script somehow?
Please let me know if you need more information (I don't want to spam you with the linker-script, the different assembly files and so on ).
Thanks!
hrniels