gas section alignment less than 4 bytes

Nick Clifton nickc@redhat.com
Tue Jul 4 11:08:08 GMT 2023


Hi Vincent,

> I wonder if there is a way for gas to generate an object with section alignment less than 4.

If you do not mind the section having a name other than .text, then sure:

   $ cat fred.s
   .section foo, "ax"
   nop

   $ m68k-elf-as fred.s -o fred.o
   $ m68k-elf-objdump -h fred.o
   [...]
   3 foo           00000002  00000000  00000000  00000034  2**0
                   CONTENTS, ALLOC, LOAD, READONLY, CODE


> I would like to get Algn = 2**1 for all sections.
> Is it possible to achieve that? How?

If you want to change the alignment of all of the sections, then
you cannot do it using gas, but you can using objcopy:

   $ echo nop | m68k-elf-as -o a.o
   $ mk68k-elf-objcopy --set-section-alignment=\*=2 a.o b.o
   $ m68k-elf-objdump -h b.o
   [...]
   0 .text         00000002  00000000  00000000  00000034  2**1
                   CONTENTS, ALLOC, LOAD, READONLY, CODE
   1 .data         00000000  00000000  00000000  00000036  2**1
                   CONTENTS, ALLOC, LOAD, DATA
   2 .bss          00000000  00000000  00000000  00000036  2**1
                   ALLOC

Cheers
   Nick



More information about the Binutils mailing list