HELP! With 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.
Post Reply
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

HELP! With cygwin

Post by t0xic »

Hey everyone,

I been using djgpp to link/build my kernel, but I recently decided to switch over to cygwin. I get to it compile but it wants to link with a __main and _alloca. I know there is a switch to turn this off, but for the life of me I can't remember it. Also, linking with the cygwin ld tells me I can't link a.out files, and my kernel is now 20kb bigger, and I haven't added any code. <what a run on sentence>. I would appreciate any help

thanks

-t0xic
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Sounds like a FAQ question to me:
OSDev Wiki wrote:Creating a dedicated (cross-) compiler for your OS development work can save you many headaches. If...

* ...your system compiler drags in references to alloca() or other OS-dependent things,
( GCC Cross-Compiler )

as for the switch, my first guess would be reading the manpages
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

The switches I use are

Code: Select all

-fno-builtin -nostdlib -ffreestanding
for my c files and

Code: Select all

-fno-builtin -nostdlib -fno-exceptions -fno-rtti
for my c++ files.

EDIT: You will really want to build a cross compiler, so that should be the first thing that you do. Unless you like PE files. :wink:
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

I got djgpp working fine with the switches frank has mentioned, although I have now switched to Cygwin and a cross compiler. I would definitely recommend the latter.

Cheers,
Adam
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

I use those switches too. Two questions...

- Why can't I use --no-leading-underscores?
- What did you guys use as your target machine for yuor cross compiler. When ever I try i386-pc-none or i486-linux, the makefile freaks out. If I am not trying to use elf, what exe format should I use, and how do I put it in the switch? ?i386-coff?

Any help would be appreciated.

Thanks
--t0xic
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Well, For one isn't it -fno-leading-underscores ? :wink:

BTW The target for ELF is clearly defined in the Wiki article GCC Cross-Compiler.

Most people use the target i486-elf or i586-elf.. But I'm guessing i386/i686 are valid as well.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

I meant I don't want to use elf. I'm not really sure which format I'm using lol. I've been using coff I think, as thats the default format for djgpp. I had tried -fno-leading-underscores but my cygwin is obviously screwed up.

--t0xic
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Well I do believe that cygwin defaults to no leading underscores. As for the target i686-pc-elf or i586-pc-elf is usually the one people use. Objdump says it supports
elf32-i386 coff-i386 elf32-little elf32-big srec symbolsrec tekhex binary ihex
However I think that i586-pc-msdosdjgpp is also a valid target. I can't tell you what it supports though.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

t0xic wrote:I meant I don't want to use elf. I'm not really sure which format I'm using lol.
I think djgpp uses coff (Microsoft style) as the object file for output from gcc/gas, and pe as the executable format that ld produces. Typically, to specify an executable format, you pass the --oformat TARGET option to ld, where TARGET is one of the targets produced by the output to ld --help.

In particular, my Cygwin ld produces:

Code: Select all

ld: supported targets: pe-i386 pei-i386 elf32-i386 elf32-little elf32-big srec symbolsrec tekhex binary ihex
ld: supported emulations: i386pe
although you actually can't use some of them like the elf ones from Cygwin (it expects PE output, as evidenced by the supported emulations list).

On the other hand, a cross compiled binutils will give:

Code: Select all

i586-elf-ld: supported targets: elf32-i386 coff-i386 elf32-little elf32-big srec symbolsrec tekhex binary ihex
i586-elf-ld: supported emulations: elf_i386
which can produce elf executables.

The 'target' which people are discussing here, like 'i586-elf' etc is actually a machine name for the target that you want your code to run on, and is passed to gcc through use of the '-b <machine>' options. All this does is run the particular version of gcc that you have requested, e.g. running 'gcc -b i586-elf' will actually just pass all your options on to i586-elf-gcc. Now each particular version of gcc you have installed will have default values for certain options, e.g. the default executable version for i586-elf is elf. Its default architecture is to generate x86 code for an i586 or above, and it doesn't add any os specific code (like i586-linux-elf would).

I would suggest you cross compile a new version of gcc and binutils under cygwin, by following the instructions in GCC_Cross-Compiler.

Regards,
John.
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

Thanks everyone;

Ok, I got i586-elf to work, and I'm in the process of compiling the binutils, but when I try to make ld, make tells me that it has already configures ./ld, even though I delete the folder. IS this a common bug or am I doing something wrong?

Thanks

--t0xic
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Well does it complete the build process and that is just some useless little info message or does it appear to fail after telling you that?
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

@frank

Make stops what it's doing and gives me the fail on error message

--t0xic
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

First off are you following the wiki instructions and are building in a separate directory? If you are try deleting everything in build-binutils and running configure and make again.

Also when you first installed cygwin did you pick the Unix/binary option for file mode? If you picked text mode then that could be a problem.

Finally do you have a the necessary packages for building binutils. I can't remember all of them but I know you need flex and bison.
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

I believe I found the problem. I was reading the error too literally (or maybe not enough). Make told me to run make distclean in the source directory, not the build-binutils/ld directory. Make is running fine now, hopefully no more errors =)

Thanks

--t0xic
Post Reply