Alignment troubles with nasm and ld
i'm sort-of following the "higher half bare bones" page on the wiki for my toy os, and nasm and ld are giving me a world of hurt when it comes to aligning my kernel sections (specifically my data section.) i've found a solution to my problem, but i won't be happy until i know what's really going on, so here i am.
i'm assembling into elf format with nasm 0.98.40 (came with my mac) and linking into elf format with the GNU ld 2.19.
So my linker script looks something like this:
Code:
.
.
.text : AT(ADDR(.text) - 0xC0000000) {
*(.text)
*(.rodata *)
. = ALIGN(4096);
}
.data ALIGN(4096) : AT(ADDR(.data) - 0xC0000000) {
*(.text)
}
.
.
i've tried with either and both of the ALIGNs in there, and neither of them will cause my data section to actually be aligned on a 4K boundary.
Meanwhile, in my source...
Code:
[section .data]
align 0x1000 ;4k align the page directory
pagedirectory:
.
.
Won't align it either. i don't think this is actually a problem though, since i figure the "align" only aligns with respect to the beginning of the section (some other tests i've done seem to confirm that.)
However, if i do
Code:
[section .data align=4096]
then it
will align. Yay! But if i change that to hex: "align=0x1000" it will stop working without nasm even giving a warning about the value being invalid. Is this something a newer version of nasm would fix?
i'm fine with putting the "align=4096" into my code, but i'd really like to know why the linker won't align things for me. i'm guessing it's a problem with my linker script. Anyone know?
Thanks.