Bona Fide OS Development
http://forums.osdever.net/

Alignment troubles with nasm and ld
http://forums.osdever.net/viewtopic.php?f=5&t=959
Page 1 of 1

Author:  RyanSchuster [ Sun Mar 13, 2011 12:00 am ]
Post subject:  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.

Author:  brenden [ Thu Mar 17, 2011 5:01 pm ]
Post subject:  Re: Alignment troubles with nasm and ld

I've not run into this before, but I think the issue is the accepted number format that NASM uses.

Check out the NASM manual: http://www.nasm.us/doc/nasmdoc4.html#section-4.11.12

Doesn't that match what you're saying about 0x1000 not working and only 4096 working?

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/