Page 1 of 1
.align 3 not working gnu as spits out errors
Posted: Sat Aug 18, 2018 8:48 pm
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...
Re: .align 3 not working gnu as spits out errors
Posted: Sat Aug 18, 2018 9:09 pm
by alexfru
Are you trying to align to a multiple of 3 instad of a multiple of 8?
Re: .align 3 not working gnu as spits out errors
Posted: Sat Aug 18, 2018 11:54 pm
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).
Re: .align 3 not working gnu as spits out errors
Posted: Sun Aug 19, 2018 1:13 am
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?
Re: .align 3 not working gnu as spits out errors
Posted: Sun Aug 19, 2018 2:02 am
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.
Re: .align 3 not working gnu as spits out errors
Posted: Sun Aug 19, 2018 7:31 am
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.
Re: .align 3 not working gnu as spits out errors
Posted: Sun Aug 19, 2018 7:54 am
by iansjack
For compatible behaviour across architectures use .balign.
Of course, Linux 0.01 only supported x86 processors.
Re: .align 3 not working gnu as spits out errors
Posted: Sun Aug 19, 2018 8:06 am
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.
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).
Re: .align 3 not working gnu as spits out errors
Posted: Sun Aug 19, 2018 8:09 am
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.
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).