OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 10:31 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Problems with Cygwin ld/G++
PostPosted: Thu Dec 20, 2001 12:00 am 
To compile an os kernel, I am using Cygwin's win32
port of GCC and LD. However, everytime I try to link
the kernel, I get a warning that says:
cannot find entry symbol _mainCRTStartup
defaulting to 00401000

When I try to load the kernel to 0x2000
and then call jmp 0x2000:0x0000, I get strange output.

I am wondering if I simply need to change that default,
or if something is really wrong with my code.


Top
  
 
 Post subject: RE:Problems with Cygwin ld/G++
PostPosted: Thu Dec 20, 2001 12:00 am 
>On 2001-12-20 22:12:20, os_dev wrote:
>cannot find entry symbol _mainCRTStartup
>defaulting to 00401000

It sounds like CygWin is trying to link in the
default startup code. Trying linking with
"ld -nostdlib ..."

I don't know about CygWin, but with MinGW32 I also
had to put a dummy function in my code like this:

#ifdef __WIN32__
int __main(void) { return 0; }
#endif

Lastly, CygWin and MinGW32 do not work with NASM.
The CygWin people already know about this bug,
and have it fixed in the CVS version.


Top
  
 
 Post subject: RE:Problems with Cygwin ld/G++
PostPosted: Fri Dec 21, 2001 12:00 am 
>On 2001-12-20 22:12:20, os_dev wrote:
>To compile an os kernel, I am using Cygwin's win32
>port of GCC and LD. However, everytime I try to link
>the kernel, I get a warning that says:
>cannot find entry symbol _mainCRTStartup
>defaulting to 00401000
>
>When I try to load the kernel to 0x2000
>and then call jmp 0x2000:0x0000, I get strange output.
>
>I am wondering if I simply need to change that default,
>or if something is really wrong with my code.

Chris' got your answer in another message... that
should work, I'm just curious as to why you're using
cygwin? 'cuz if djgpp will work, I think that'd be
easier for OS development.

It'll work with nasm, and... well, I think most
people on this list are using it, so it might be
easier to get help with it.

Just my two cents, of course :) Not tryin' to preach
or anything... I've used cygwin myself, and like it
a lot.

Oh, btw... since you are using cygwin... where can
I grab the latest copy? Last I checked, I could
only find commercial versions through red hat. It'll
work under NT/XP as well, right?

Jeff


Top
  
 
 Post subject: Other problems?
PostPosted: Fri Dec 21, 2001 12:00 am 
Jeff, I am getting it from www.cygwin.com.

They have an automatic installer there you can download,
setup.exe. It also serves as an updater.

But, in response to your suggestion, I downloaded
and tried it with DJGPP, and got a similar error
with their linker, the only difference being
entry start not found instead of _mainCRTStartup.

When I retried using Cygwin, I found using the -nostdlib
did not do anything unless you also added the --entry tag.
I am not familiar with that, but can I define an
entry symbol in my code? And then just call to it?

Btw, if it helps, here is the simple kernel I wrote to test it:


#ifndef __WIN32__
int __main() { return 0; }
#endif

void start();
extern void _main(void);
extern void _exit(void);

void start()
{
_main();
_exit();
}

Now, I get _main() from main.o and _exit() from
exit.o.

I added that statement at the top to see if it would work.

So, basically, I guess, is there anything missing?

Or can I simply tell it to have the entry at 0x0000?

Thanks,
os_dev


Top
  
 
 Post subject: Found the problem?
PostPosted: Sat Dec 22, 2001 12:00 am 
I read somewhere that you can't use binary files
c++ code because they don't have an entry point?

Well, if not that file type, then what linked output
is best? I have both Cygwin and DJGPP now.

Also, what are the G++ and LD commands to create such
files?

Thanks again,
os_dev


Top
  
 
 Post subject: RE:Found the problem?
PostPosted: Sat Dec 22, 2001 12:00 am 
>On 2001-12-22 00:57:51, os_dev wrote:
>I read somewhere that you can't use binary files
>c++ code because they don't have an entry point?

Yep, that's true. That's what I was gonna say
in your previous message. You can't just
jump to 0x0 of a binary image created by C/C++
because you, essentially, have no idea what that
compiler has put at 0x0... it probably really
isn't your entry point.

>Well, if not that file type, then what linked output
>is best? I have both Cygwin and DJGPP now.

Uhm... myself, I'm using DJGPP, and so I output
my objects to the COFF object file format (which
is the default).

In order to make a kernel entry point at the
beginning of your kernel, you'll have to do some asm.
I use NASM (again, outputting to COFF) with something
simple like:

extern _start
jmp _start

And as long as your asm file is first on the linking
command line, that you'll be able to jump to 0x0
of the kernel to run it.

>Also, what are the G++ and LD commands to create such
>files?

DJGPP will output coff files automatically,
nasm probably requires something like -f coff (it's
been a while, I don't totally remember), and
when your linking,
ld -oformat binary nasmfile.o cfile.o

And you should be all set.

jeff


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 228 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group