Alternative to gcc/DJGPP?

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
GrimRipper

Alternative to gcc/DJGPP?

Post by GrimRipper »

Would it be possible to use an alternative to gcc to produce flat/binary files for use in OS-development?

What would be the requirements of such a compiler?
Does it have to add special sections to the object file?

Is it possible to, for example, (without putting in too much effort of course ;) ), compile the .c-source, using tools from Micro$oft, Borland or Metrowerks, and then link the object file with the standard GNU ld.exe, possibly trasforming it before linking with a tool like GNU objcopy(i think that's the name of it) to produce a binary with the equivalent format as gcc + ld would have?

Know of any good links to reading on the subject? don't hesitate to let me know. ;D

regards
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Alternative to gcc/DJGPP?

Post by Pype.Clicker »

if this is possible, and if the file format is recognized by the tool, then OBJCOPY is probably what you need to remove sections you do not want before passing the file to LD.
Tim

Re:Alternative to gcc/DJGPP?

Post by Tim »

-oformat binary is your friend.

Unless you're using Cygwin, where you must link to PE and use objcopy (binary is broken in Cygwin).
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Alternative to gcc/DJGPP?

Post by Solar »

Tim Robinson wrote: Unless you're using Cygwin, where you must link to PE and use objcopy (binary is broken in Cygwin).
Or build a ELF-target cross compiler - http://www.pro-pos.org/wiki/HowToCrossCompile.

GrimRipper, other compilers / formats might put symbols into sections where you wouldn't expect them. That can e.g. mean you need a different linker script.

The problem with that is twofold:

1) virtually all tutorials I found assume a GNU environment;

2) anyone willing to join in to your project would have to use the same format / tools.

Point 1) will probably bite you right now, but don't be mistaken - 2) will become the major show-stopper if you ever go "public". (And don't tell me you wouldn't, Linus wrote the Linux kernel to be an i386-only toy for CS students...)
Every good solution is obvious once you've found it.
Schol-R-LEA

Re:Alternative to gcc/DJGPP?

Post by Schol-R-LEA »

Perhaps if we knew why you wanted a different toolset, it might help us solve the problem.

This is not a matter of trying to judge you - "I don't like DJGPP" is a perfectly acceptable answer - but rather is an attempt to find the best solution to the problem, which may not be the solution you had in mind. While there are other C compilers and toolkits out there that would be suitable, without knowing the what it is you found lacking in DJGPP, we could end up recommending one that has the exact same problem, or a worse one.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Alternative to gcc/DJGPP?

Post by Pype.Clicker »

i suppose that, as most of others, he dislike AT&T syntax (and ignores the existence of ".syntax" trick) or find it easier to install commercial tools ...
Curufir

Re:Alternative to gcc/DJGPP?

Post by Curufir »

Well you could try LCC, this has the nice advantage that it can output an NASM syntax file instead of a binary/object file, then you can use NASM to put it into object format/tweak the assembly.

http://www.cs.virginia.edu/~lcc-win32/
Chris Giese

Re:Alternative to gcc/DJGPP?

Post by Chris Giese »

I've tried using Borland C 5.5 for osdev. The compiler is fast! Much better than GCC. But there are problems with the compiler and especially the linker (ILINK32):
  • The free docs are very poor. -H is a useful compiler option (pre-compiled headers!), but who knew about it?
  • Adding special sections to the object file is very useful, but I have no idea how you'd do this with Borland C 5.5.
  • Can't make Multiboot-compatible kernel (a problem for me): http://my.execpc.com/~geezer/osd/gotchas/index.htm#ilink32_multiboot
  • Can't make binary kernel (a problem for you)
  • Object files are OMF, not Win32 PE COFF. You can't use Microsoft or GNU tools on them.
  • Can't seem to align the BSS on a page boundary
  • ILINK32 quietly builds an empty, 2048-byte .EXE file unless you use a valid .DEF file. I thought this nastiness died with Win16.
I'm sure there were other problems, mercifully forgotten.
I also made a less ambitious attempt to use Watcom C to compile a kernel. Result: more problems.

Then I tried installing LCC. The install program was apparently written in Eiffel. It started swapping like crazy, and eventually my computer become unresponsive. Why does a mere install program require so much virtual memory? Something's f*cked.

Executive summary: if you want to use a compiler other than GCC to make an OS, you're in for a lot of misery.
beyond infinity lazy

Re:Alternative to gcc/DJGPP?

Post by beyond infinity lazy »

best is to stick with gcc and ld and nasm (for those who don't like or don't want to learn at&t syntax) running on linux. you can configure it to your needs and no witty OS comes along and tries to propose 'better' things.
Schol-R-LEA

Re:Alternative to gcc/DJGPP?

Post by Schol-R-LEA »

Still no replies from GrimRipper on these suggestions... hopefully, he's found a solution already, then. If not:

If the problem is with the DJGPP version of gcc rather than the compiler per se (e.g., you want to use ELF object files instead of COFF), or with the DOS/Windows Console environment, then you might consider either the Cygwin or the MingW ports instead. Both integrate into Windows much better than DJGPP (which could be good or bad, depending on your point of view). Cygwin provides a fairly complete bash-workalike shell, while if you prefer an IDE environment, there is Dev-C++, which uses the MingW port.

Let us know if any of this advice helps; feedback is pretty important in a forum like this.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Alternative to gcc/DJGPP?

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:15 pm, edited 1 time in total.
GrimRipper

Re:Alternative to gcc/DJGPP?

Post by GrimRipper »

Hi all, thanks for all of your replies ;D (and sorry about me beeing so darn slow about things). :'(

I've tried some of the compilers out there combined with John Fine's jLoc since my only interest has been in producing binary flat output.

LCC
Seems nice, I had some problems though. Adding _asm("mov %eax, 0xF") to the .c source gave me an internal compiler error. Could be my syntax is wrong or something, didn't find much in the docs or on the net about it though. Know what I'm doing wrong? ???

Codewarrior command line tools (mwcc)
This compiler produces object files in some crazy COFF format I think. It adds multiply .text sections, one for each function it seems. I think this is why jLoc and ld produces errorous function call code. I'm not sure about this, any help would be highly appretiated! :-*

Code: Select all

mwcc -c -r -w on -RTTI off -nodefaultlibs -Cpp_exceptions off -codegen -opt full main.c -o main.o

void putChar();
int main() {
    putChar();
    for(;;) { }
return 0;
}

void putChar() {
    __asm {
        mov eax, 0x0b8000
        mov [eax], 'A'
        mov [eax + 1], 0x0F
}
produces this object file

-EDIT- I'm not sure I'm allowed to publish results from the compiler so I'll clean it up a bit. -EDIT-

Code: Select all

coff-go32

It adds one .text for each function, one for main and one for putchar in this case. Each function gets the offset of zero  (relative to it's section).

00000000 <_main>:
   0:   e8 00 00 00 00          call   5 <_main+0x5>
    - some other code -
Disassembly of section .text:

00000000 <_putChar>:
   0:   code
   5:   code
   8:   code
   c:   return
The .obj-file is supposed to be in some format compatible with Microsofts compiler. Maybe that's why it looks strage ;D

after linking it with jLoc, using the control file

Code: Select all

ALL:
   main.o
KERNEL: 0 1000 0
   *
the calls are made to wrong positions in the code.
Sometimes the call is even "out of bounds" so to speak.

BCC32
This is a very nice compiler which is free (not Debian-free).

Chris Giese earlier stated that you can't make a binary kernel with it. But I suppose that's only true if you're
trying to link it with ilink32 and not jLoc, right?

This far the only toubble I've had using bcc is the syntax of the _asm statement.

Code: Select all

_asm( mov byte [eax], 'A' )
tasm transforms the code into (after complaining about argument needing type override)

Code: Select all

 mov dword [eax+0x1],0x41 
a dword move? with an offset of one? Can anyone more familiar with the TASM syntax explain that to me? ???

Microsoft .NET
I didn't have the courage to download and install the entire .NET SDK. (It contains the command line version of the Visual .Net compiler and is available for download on MSDN).
Might do it later, should be interesting to see if one can use it as well. It's supposed to be quite a high quality compiler, or so I've heard.

Two other cool compilers are the Intel and Codplay ones. Demos and free non-commercial(Intel linux) versions can be downloaded from their sites.

Please correct any blunders I've made in this post.
Since I'm more or less a total newbe when it comes to Os programming, there's probably quite a few of them in here :-[


There seems to be alot of problems
Post Reply