[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] g++ problem with archives & linking



On Thu, 2008-02-21 at 23:01 +0000, Alan Hourihane wrote:
> On Thu, 2008-02-21 at 23:03 +0100, Vincent Rivière wrote:
> > I tried your testcase with Cygwin, and like in Linux, it works fine 
> > without any trick from the user.
> > How ? The explanation is in Cygwin's file crt0.c:
> > http://cygwin.com/cgi-bin/cvsweb.cgi/~checkout~/src/winsup/cygwin/crt0.c?rev=1.4&content-type=text/plain&cvsroot=src
> > The startup code calls cygwin_crt0() (the equivalent of our MiNTLib 
> > _crtinit() with the main function as a parameter. So the startup code 
> > has a reference to main(). So the main() function provided by the user 
> > is always linked, even if it is in a library.
> > 
> > It would be easy to do get the same behavior with the MiNTLib: we just 
> > have to add a "main" parameter to _crtinit()
> > 
> > However, I don't know if such a behavior should be assumed to be a 
> > standard...
> 
> Ah, thanks for the solution Vincent. I'm going to modify my MiNTlib to
> do this.

It worked out much easier than this. Just add a reference to crt0.S such
as the attached patch.

Cygwin & Linux has references to main in their crt{0,1}.o too.

Can anyone see a problem with this ?

Alan.


Index: startup/crt0.S
===================================================================
RCS file: /mint/mintlib/startup/crt0.S,v
retrieving revision 1.3
diff -u -r1.3 crt0.S
--- startup/crt0.S	22 Jan 2008 09:55:43 -0000	1.3
+++ startup/crt0.S	21 Feb 2008 23:32:12 -0000
@@ -6,6 +6,7 @@
 	.globl	__base		| BASEPAGE *, declared in globals.c
 	.globl	__heapbase	| void *
 	.globl	__stksize	| long, declared by user or in stksiz.c
+	.globl  _main		| for references
 
 |
 | externs to pull ident strings of all used libraries into the