How to config GAS to generate 'clean' objects?

clainst@fastmail.cn clainst@fastmail.cn
Fri Jan 20 06:53:00 GMT 2006


Hi, list.
I find the GAS always adds .text, .data and .bss sections to its output
file, without considering the fact whether these sections are present or
not in the source files.

================================================================
$ cat test.s
.text
	pushl	%ebp
	movl	%esp, %ebp

$ as test.s -o test.o
$ objdump -h test.o

test.o:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000003  00000000  00000000  00000034  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000038  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000038  2**2
                  ALLOC
$ wc -c test.o
     445 test.o
$ strip -R.data -R.bss test.o
$ wc -c test.o
     192 test.o

================================================================

Although the 'unwanted' sections have the zero size, they do occupy a lot
of room. I just wonder if there is a way to change this default
behavior.

My next question is:
How to make GAS generate plain binary file like other assemblers such as
nasm or fasm. Currently I have to generate object file first, and then
use objcopy to fetch the code binary out, which is not that convenient.

Thanks




More information about the Binutils mailing list