.align 3 not working gnu as spits out errors

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

.align 3 not working gnu as spits out errors

Post by ITchimp »

linux 0.01's boot.s has a assembler directive stating .align that is causing assembler to spit out error message... I can try to replace 3 with 4... the error go away... but based on the gas manual, .align 3 is a valid statement... was compiling in a vm ubuntu 64 bit machine...


thanks for the help...
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: .align 3 not working gnu as spits out errors

Post by alexfru »

Are you trying to align to a multiple of 3 instad of a multiple of 8?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: .align 3 not working gnu as spits out errors

Post by iansjack »

When using elf format, the default for gas nowadays, the argument to .align must be a power of 2. The behaviour is different when using a.out format (which that version of Linux would have used) where the argument specifies the power of 2.

So .align 3 (a.out) is equivalent to .align 8 (elf).
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

Re: .align 3 not working gnu as spits out errors

Post by ITchimp »

Is there a way to choose zmagic/amagic over elf? What switch/flag is there? there doesn't seem to have any at first glance... just curious...

also by the same token, is .align 4 in a.out equivalent to .align 16 in elf?
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: .align 3 not working gnu as spits out errors

Post by alexfru »

ITchimp wrote:Is there a way to choose zmagic/amagic over elf? What switch/flag is there? there doesn't seem to have any at first glance... just curious...
Try something like this (you'll likely need the object file, aout.o, already in a.out format, not ELF):

Code: Select all

ld -e __start --oformat=a.out-i386 --omagic aout.o -o aout.out
ld -e __start --oformat=a.out-i386 --nmagic aout.o -o aout.out
ld -e __start --oformat=a.out-i386 --qmagic aout.o -o aout.out
ITchimp wrote:also by the same token, is .align 4 in a.out equivalent to .align 16 in elf?
I'd expect so.
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: .align 3 not working gnu as spits out errors

Post by zaval »

iansjack wrote:When using elf format, the default for gas nowadays, the argument to .align must be a power of 2. The behaviour is different when using a.out format (which that version of Linux would have used) where the argument specifies the power of 2.

So .align 3 (a.out) is equivalent to .align 8 (elf).
but don't forget, as always with this mess, - this is valid only for x86.

for example on both arm, mips and ppc gccs emitting elf, .align 3 means "align on 2^3". which is sane imho.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: .align 3 not working gnu as spits out errors

Post by iansjack »

For compatible behaviour across architectures use .balign.

Of course, Linux 0.01 only supported x86 processors.
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: .align 3 not working gnu as spits out errors

Post by zaval »

iansjack wrote:For compatible behaviour across architectures use .balign.

Of course, Linux 0.01 only supported x86 processors.
I noted that just in case, for the OP, maybe he/she is going to develop not only on x86. :mrgreen:

I prefer the meaning where N in .align N means power of two. so .balign is BS. .p2align is better. of course if one wants to mess with gcc specific directives (which .balign an .p2align are).
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: .align 3 not working gnu as spits out errors

Post by zaval »

iansjack wrote:For compatible behaviour across architectures use .balign.

Of course, Linux 0.01 only supported x86 processors.
I noted that just in case, for the OP, maybe he/she is going to develop not only on x86. :mrgreen:

I prefer the meaning where N in .align N means log2(alignment), not the alignment itself. so .balign is BS. .p2align is better. of course if one wants to mess with gcc specific directives (which .balign an .p2align are).
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
Post Reply