flat assembler
Message board for the users of flat assembler.

Index > Heap > gcc output format

Author
Thread Post new topic Reply to topic
tejuwala



Joined: 14 May 2008
Posts: 9
Location: Sunnyvale
tejuwala
Hello,

I'm trying to get hexcode from a C program. Is it possible for GCC to create output file in binary format? without any ELF headers?

Thanks,
/tejas
Post 14 May 2008, 18:35
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Is it possible for GCC to create output file in binary format?

errrm... part of Gnu compiler collection is linker utility. For that, you can creat so-called linker script which allows you to create custom layout of produced binary file.
Post 14 May 2008, 20:06
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Not sure, but try looking up the following:

-nostdlib, -nostdinc, -nostartfiles, -nodefaultlibs

EDIT: A real-world example (maybe?) is Gujin:

Quote:

Gujin is written almost entirely in C with GCC, and it fully executes in real mode to be as compatible as possible.
Post 24 May 2008, 21:43
View user's profile Send private message Visit poster's website Reply with quote
tejuwala



Joined: 14 May 2008
Posts: 9
Location: Sunnyvale
tejuwala
vid wrote:
Quote:
Is it possible for GCC to create output file in binary format?

errrm... part of Gnu compiler collection is linker utility. For that, you can creat so-called linker script which allows you to create custom layout of produced binary file.


This is what you do in Linking step, when, using the linker script you describe memory regions where you want various sections of your ELF code to be put. I want to create binary output directly from gcc. The same way as nasm does when not supplied "-f" option.

e.g. "nasm input.s" will create input.o which is a binary file.

/tejas
Post 27 May 2008, 22:00
View user's profile Send private message Yahoo Messenger Reply with quote
tejuwala



Joined: 14 May 2008
Posts: 9
Location: Sunnyvale
tejuwala
Not sure, but try looking up the following:

rugxulo wrote:
-nostdlib, -nostdinc, -nostartfiles, -nodefaultlibs


You do this when you don't want to use glibc and any include files. Like linux, it doesn't use glibc to compile itself.

Quote:

Gujin is written almost entirely in C with GCC, and it fully executes in real mode to be as compatible as possible.


I've not looked at the code but my guess is the way this thing is compiled is that all C files are compiled to be ELF32, so are ASM files and then they are linked together using a linker script to be a binary file. But thats not what I want. I am looking for GCC options (even if I have to recompile gcc for that matter) that will allow me to produce binary file directly as result of compilation. (see my earlier post)

Thanks,
/tejas
Post 27 May 2008, 22:10
View user's profile Send private message Yahoo Messenger Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade
I cant think of any way to do that.. usually GCC is made to compile code for a certain platform, and I havent found any way to deviate from those available platforms..

Could you not just generate a normal (ELF) binary, then disassemble it and look for your code? You can also look at the elf header for where the "start address" is, and go there.
Post 28 May 2008, 09:25
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
I'm trying to get hexcode from a C program. Is it possible for GCC to create output file in binary format? without any ELF headers?


It can create COFF also instead of ELF Confused

Your C code doesn't use any external calls (printf, malloc, ...) ?

But what about creating ASM instead ? IIRC GCC by default creates GAS/ATT code Image - anyone tested the "masm=intel" hack ? Can GCC create code compilable by FASM without too much rewrite ?

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 01 Jun 2008, 21:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.