Binary and ELF in cygwin

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Binary and ELF in cygwin

Post by df »

you dont needx to build gcc, just binutils.
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

df wrote: you dont needx to build gcc, just binutils.
hmm well I am still getting this error message:

main.o(.text+0x23):main.c: undefined reference to `__alloca'
main.o(.text+0x28):main.c: undefined reference to `___main'
main.o(.text+0x34):main.c: undefined reference to `_printf'

I'm assuming it's because their object files meant to be linked to pe, as elf doesn't like symbols with an underscore.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Binary and ELF in cygwin

Post by df »

yeah elf has this underscore thing going on, pe does not.
ld: warning: cannot find entry symbol _start; defaulting to 08048080
main.o(.text+0x23):main.c: undefined reference to `__alloca'
main.o(.text+0x28):main.c: undefined reference to `___main'
main.o(.text+0x34):main.c: undefined reference to `_printf'
my guess is your are trying to link against the libc with an os kernel, which is a no-no.

1st error about enrtry point is easy fixed with -E option in ld.
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

removed anything to do with libc and used the -E switch, I still get this:

main.o(.text+0x23):main.c: undefined reference to `__alloca'
main.o(.text+0x28):main.c: undefined reference to `___main'
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Binary and ELF in cygwin

Post by df »

coz you still compiled it like a standard program ::) you need to compile it standalone...

you need tyo compile with

gcc -nostdlib -nostdinc++ -nostdinc -fno-builtin -fsigned-char -ffreestanding
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

no change

BTW This is the first time I have ever tried to use gcc. So am very new to this.
nullify

Re:Binary and ELF in cygwin

Post by nullify »

Are _alloca and __main symbols defined in the code you are compiling (meaning its not looking for something in an external library) ?
Tim

Re:Binary and ELF in cygwin

Post by Tim »

_alloca is in libgcc. This is necessary in gcc 3.x, but luckily it doesn't contain any OS-specific calls. You might have to provide your own empty __main.
Post Reply