question about the alignment of the .text section

Is there a reason why the alignment of the .text section should be 4 when we are optimizing for size (-Os or –Oz)? Note that when are optimizing for size, the symbols inside .text section don’t have any alignment constraints. Alignment=4 for .text with the unaligned symbols inside this section prevent our linker from de-duplicating functions. Could the alignment of the .text section be changed to 1? Could it cause any potential problems (correctness/performance)?

clang -c -Os test.cpp -o test.o

readelf -S test.o

[ 1] .text PROGBITS 0000000000000000 00000040

0000000000000052 0000000000000000 AX 0 0 4

Thanks!

Katya.

Which target architecture?

Joerg

Joerg Sonnenberger <joerg <at> britannica.bec.de> writes:

> Is there a reason why the alignment of the .text section should be 4
> when we are optimizing for size (-Os or -Oz)?

Which target architecture?

Joerg

Hi Joerg,

x86_64 Linux. I see 4 byte alignment for .text section when the compiler is
optimizing for size.

Thanks!
Katya.

Katya Romanova <katya_romanova <at> playstation.sony.com> writes:

Joerg Sonnenberger <joerg <at> britannica.bec.de> writes:

>
> > Is there a reason why the alignment of the .text section should be 4
> > when we are optimizing for size (-Os or -Oz)?
>
> Which target architecture?
>
> Joerg

Hi Joerg,

x86_64 Linux. I see 4 byte alignment for .text section when the compiler is
optimizing for size.

Thanks!
Katya.

Hi,
I was wondering if someone in the community knows the answer to the question
about the alignment of the .text section?

Thanks in advance,
Katya.

The C++ ABI for method pointers on x86 requires that function pointers are
at least 2 byte aligned. ARM's C++ ABI doesn't have the same requirement
(because Thumb function addresses have the bottom bit set). See
UseARMMethodPtrABI in Clang's ItaniumCXXABI.cpp, if you're interested.

Other than that, I don't know of any requirements for function addresses to
be aligned on x86.

Cheers,
Mark