Alignment of .sections

Doug Evans dje@transmeta.com
Mon Jul 30 14:15:00 GMT 2001


Frank Klemm writes:
 > Hi,
 > 
 > I need to explicitely align sections in GNU assembler sources.
 > The problem is that the minimum alignment for GNU assembler seems to be 4
 > (2^2), but I need no alignment (1 = 2^0). How to specify this in a GNU
 > assembler source? It is not a restriction of the ELF format. NASM
 > can generate such ELF objects without any problem.
 > 
 > Examples of other assemblers:
 > 
 > TASM:
 > MASM:
 > 	_TEXT	segment 'CODE' align=1
 > 		db	'Hallo', 0
 > 
 > 
 > NASM:
 > 		segment .code align=1
 > 		db 	'Hallo', 0
 > 
 > 
 > GAS:
 > 		???

You'll need to elaborate.  It works just fine.

casey:~$ cat foo.S

	.section "aligned_to_1_v1"
foo1v1:	.byte 1,2,3
	.section "aligned_to_1_v2"
foo1v2:	.byte 1,2,3
casey:~$ gcc -nostdlib foo.S -o foo.exe
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 08048074
casey:~$ objdump -h foo.exe

foo.exe:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  08048074  08048074  00000074  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  08049074  08049074  00000074  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  08049074  08049074  00000074  2**2
                  ALLOC
  3 aligned_to_1_v1 00000003  08049074  08049074  00000074  2**0
                  CONTENTS, READONLY
  4 aligned_to_1_v2 00000003  08049077  08049077  00000077  2**0
                  CONTENTS, READONLY
casey:~$ 



More information about the Binutils mailing list