Subject: Re: kern/13615: NetBSD current requires a .note.netbsd.ident section
To: Todd Vierling <>
From: Andrew Cagney <>
List: netbsd-bugs
Date: 09/22/2001 00:39:02
[to pick up a very old thread]

Todd Vierling wrote:
>  On Thu, 2 Aug 2001, Andrew Cagney wrote:

>  : I think you mean FSF's GCC will be changed to use the NetBSD's installed
>  : /usr/lib/crt{begin,end}.
>  This is precisely what I said.  "GCC will be changed not to use its versions
>  of... (and use only NetBSD's...).  This means FSF's GCC...."

I re-checked my notes.

As far as I can tell gcc 3.0 introduced changes that made it impossible 
for it to use NetBSD's system supplied crt{begin,end}.

>  :   If the intent is to change FSF's gcc to use either NetBSD's installed
>  : crt{begin,end} or a distributed but custom NetBSD specific
>  : crt{begin,end} then I think you're guarenteeing constant bit rot.
>  GCC doesn't even provide working crtstuff for all platforms, so we have to
>  implement it ourselves anyway.

GCC 3.0 (for the PPC and based on MRG's e-mails also x86 and sparc) rely 
on both a crt{begin,end} and a crt{i,n}.  They combine in a way that is 
very different to NetBSD's current system supplied crt{begin,end} 
leading me to the conclusion that it simply isn't possible for GCC 3.0 
to use the exising system files.

Briefly, gcc creates an executable containing the following:

	crti (ncrti for GCC on NetBSD/PPC)

	Among other iteresting things this puts
	the _init()'s function prologue in .init
	and _fini()'s function prologue in .fini.
	It also contains other useful stuff such as
	exception handling gunk.  I figure we wan't
	to leave as much of this as is so that it will
	just work.

	crt0 (I managed to get things to use the NetBSD version)

	This calls _init() and registers the call to _fini()
	with atexit().


	This appends calls to various functions to the end of
	the under construction .fini and .init sections.
	Remember, those sections
	already contain a function prelude so you can think
	of this as adding to the _init() and _fini()
	function bodies.

	your program files

	These continue the process of adding to the _init()
	and _fini() function bodies.


	crtn (or ncrtn)

	This contains the function epalogue[sp]
	for _init() and _fini() so that they return
	after being called ....

So while NetBSD puts a single simple _init() function in crtbegin(). 
GCC 3.0 constructs both _init() and _fini() from the concatenation of 
crti, bit of compilation units (including crtbegin) and finally crtn.

So back to the original problem, I guess there are several options:

	o	move that note section to crt0 (which I think
		is more likely to be linked in then crtbegin.

	o	get gcc to include a .note.netbsd.ident section
		in one of its files.  Any one got a patch?

	o	document this as a feature in the gcc 3.x release
		notes.  For the moment I think I'll go with this

	o	something else.