Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purest Way to Assemble/Compile a file With no other ELF/Object Bloat

I cannot believe how hard this seems to be. I am working from SPARC Solaris 8. and we have some kind of GNU-gcc (3.4.2) and 'as' assembler (Sun WorkShop 6 2003/12/18 Compiler Common 6.0).

Anyways, I've tried a few ways to output a pure binary file. such as

gcc -c yadda.s

or invoking solely the assembler

as yadda.s

I have also investigated the assembler man page, but I did not find much breaking news. :( AS Man page: http://pastebin.com/0FSNxhq1

So, I still get some Bloat in my resulting object file. I don't want this leading 50 bytes of ELF related * or whatever the assembler thought would help my initialization or whatever it's thinking.

What I am looking for is a pure binary output of JUST my code.

Thanks in advance :)

like image 545
bazz Avatar asked Oct 30 '12 03:10

bazz


1 Answers

The assembler does not output executable code, it outputs an object file. To make it executable, you need to link it using ld. This command allows you to specify the output format, which can be binary (if your build supports it).

as yadda.s -o yadda.o
ld yadda.o -o yadda --oformat=binary

You should be able to do this in one line using gcc:

gcc yadda.s -o yadda -Xlinker --oformat=binary
like image 112
ughoavgfhw Avatar answered Nov 15 '22 10:11

ughoavgfhw