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

Binary and ELF in cygwin

Post by srg »

Hi

How do I create binary files and ELF executables in cygwin?

Thanks
DarylD

Re:Binary and ELF in cygwin

Post by DarylD »

The way I did it is this:

Download the latest binutils/gcc.

Extract binutils (note: you will need bunzip2)
./configure --target=i386-elf
make
make install

Then do similar for gcc-core/gcc.

Then you use the i386-elf prefix on the executables. I.e. to run elf gcc use i386-elf-gcc.

Works an absolute dream.
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 »

i built it with targets all, and just replaced ld.exe with the new one, same for the objcopy/objdump/as/ld etc that get built by binutils.

then i just do ld --oformat = elf_i386
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

I get this error when building it:

make[1]: *** No rule to make target `../libiberty/libiberty.a', needed by `size.
exe'. Stop.
make[1]: Leaving directory `/binutils-2.9/binutils'
make: *** [install-binutils] Error 2

I have put the binutils folder in my cygwin folder, what have I done wrong?
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 »

i unzipped it into my home dir

export BISON="/bin/bison.exe"
export YACC="/bin/bison.exe -y"

(not sure if i did an export for flex as lex or something? mmm i dont rmemeber....)

./configure --enable-targets=all --with-gnu-as --with-gnu-ld --with-stabs
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

done that

what next
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 »

'make'

then

make install
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

done that (it took a long time)
copied the files to my bin dir replacing the old ones.

When I try this:

gcc main.c -o sgoskrnl.exe

I get this:

/usr/lib/gcc-lib/i686-pc-cygwin/3.2/../../../../i686-pc-cygwin/bin/ld: cannot fi
nd -luser32
collect2: ld returned 1 exit status

If I try this:

gcc -c main.c
ld main.o -o sgoskrnl.exe -m elf_i386

I get this:

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'

What am I doing wrong?
Whatever5k

Re:Binary and ELF in cygwin

Post by Whatever5k »

The last ouput means that the linker cannot find the functions...
Did you include the appropriate headers?
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 need to make install not just copy them into the bin directory!!

make install puts them in the correct place anyway. if you just copy them you miss the important BFD files ld needs...
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

make install doesn't make the slightest bit of difference

I'm going to reinstall cygwin
srg

Re:Binary and ELF in cygwin

Post by srg »

right, I now have ld running ok

my trouble is that my gcc only supports pe

I have downloaded gcc 3.2.1 but how would ou recommend that I install it?

Thanks
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 »

well rebuild and make install your binutils again.

then when you link, to get elf you can do

ld --oformat=elf_i386 -mi386bsd blah.o -o blah.elf
-- Stu --
srg

Re:Binary and ELF in cygwin

Post by srg »

The problem is not with binutils, it's with cygwin's gcc, it only supports pe
srg

Re:Binary and ELF in cygwin

Post by srg »

I'm having troubles building a new version of gcc with all targets enabled.

What lines should I use?
Post Reply