Bona Fide OS Developer
View unanswered posts | View active topics It is currently Sat Nov 26, 2022 8:40 am

Post new topic Reply to topic  [ 2 posts ] 
 Alignment troubles with nasm and ld 
Author Message

Joined: Thu Sep 09, 2010 9:34 pm
Posts: 3
Post 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:
   .text : AT(ADDR(.text) - 0xC0000000) {
      *(.rodata *)
      . = ALIGN(4096);
   .data ALIGN(4096) : AT(ADDR(.data) - 0xC0000000) {
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...
[section .data]
align 0x1000            ;4k align the page directory
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
[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?


Sun Mar 13, 2011 12:00 am
Site Admin

Joined: Fri Jul 24, 2009 10:02 pm
Posts: 247
Location: Las Vegas, NV, US
Post 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:

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

Thu Mar 17, 2011 5:01 pm
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.