user4182981
user4182981

Reputation:

Will global variables be aligned to a 4 bytes boundary?

I am reading about data alignment. And I know that when an x86 program starts executing, its stack will be aligned to a 4 bytes boundary. But will the .data and .bss sections also be aligned to a 4 bytes boundary? For example if I have the following:

section .data
    number1 DW 1234

When a program with this code executes, will number1 always be on an address that is divisible by 4?

Upvotes: 0

Views: 349

Answers (1)

Jester
Jester

Reputation: 58762

Yes. See the nasm manual:

The defaults assumed by NASM if you do not specify the above qualifiers are:

section .data progbits alloc noexec write align=4

section .bss nobits alloc noexec write align=4

Notice it says align=4. This is for ELF output. You have forgotten to specify what you use.

For the win32 format, the relevant part is section 7.5.1:

The defaults assumed by NASM if you do not specify the above qualifiers are:

section .data data align=4

section .bss bss align=4

Upvotes: 3

Related Questions