How to config GAS to generate 'clean' objects?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to config GAS to generate 'clean' objects?

Dasn-2

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


Reply | Threaded
Open this post in threaded view
|

Re: How to config GAS to generate 'clean' objects?

jiez
On 1/20/06, [hidden email] <[hidden email]> wrote:
> 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.
>
Not convenient? I think it well embodies UNIX philosophy. You can
combine them in Makefile or something similar.

Jie
Reply | Threaded
Open this post in threaded view
|

Re: How to config GAS to generate 'clean' objects?

Dasn-2
On Fri, Jan 20, 2006 at 06:07:13PM +0800, Jie Zhang wrote:
> > 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.
> >
> Not convenient? I think it well embodies UNIX philosophy. You can
> combine them in Makefile or something similar.
>
> Jie

I'm trying to change my viewpoint from other assemblers, which may need
some time.
Reply | Threaded
Open this post in threaded view
|

Re: How to config GAS to generate 'clean' objects?

Nick Clifton
In reply to this post by Dasn-2
Hi Clainst,

>   1 .data         00000000  00000000  00000000  00000038  2**2
>   2 .bss          00000000  00000000  00000000  00000038  2**2

> 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.

Not without modifying the sources of the assembler no.  But of course
you do have access to these sources so you can always do this.

> My next question is:
> How to make GAS generate plain binary file like other assemblers such as
> nasm or fasm.

They do ?  This seems odd to me.  What use is a plain binary file ?  You
cannot link it with other files, it has lost too much information.  I
can understand your wanting the linker to generate a plain binary file
rather than say an ELF or PE format executable, but I do not understand
why you want the assembler to produce plain binary object files.

> Currently I have to generate object file first, and then
> use objcopy to fetch the code binary out, which is not that convenient.

Sorry - this is the way that these tools are designed to work.  You can
always automate the process of assembling and then converting into the
binary format though - a simple script or makefile will do this for you.

Cheers
   Nick

Reply | Threaded
Open this post in threaded view
|

Re: How to config GAS to generate 'clean' objects?

Dasn-2
On Sat, Jan 21, 2006 at 09:44:49AM +0000, Nick Clifton wrote:
> Hi Clainst,
Hi, Nick.
Sorry, I forgot to tag my name last time.
 
> Not without modifying the sources of the assembler no.  But of course
> you do have access to these sources so you can always do this.

Yes, you're right. If I had time, I'll do it. No wonder the strip -R
would save me some time :)

> >My next question is:
> >How to make GAS generate plain binary file like other assemblers such as
> >nasm or fasm.
>
> They do ?  This seems odd to me.  What use is a plain binary file ?  You
> cannot link it with other files, it has lost too much information.  I
> can understand your wanting the linker to generate a plain binary file
> rather than say an ELF or PE format executable, but I do not understand
> why you want the assembler to produce plain binary object files.

Yes, they do. AFAIK, nasm has an '-f bin' option and fasm has 'format
binary' directive, which could help their users generate binary files.

I often use this kind of feature of assemblers to produce executables
directly, not for _object_ files to be linked. IMHO, the problem of this
feature is how to generate plain binary for multi-section code. Nasm
simply concentrates its assembled sections, while fasm will report an
error of conflict between 'binary' and 'section' directives. Hmm..
considering this, gas has more flexibility.