Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 Mar 2002 00:21:55 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Kris Kennaway <kris@obsecurity.org>, "M. Warner Losh" <imp@village.org>, current@FreeBSD.org, peter@FreeBSD.org
Subject:   Re: stdout changes break some ports
Message-ID:  <3CA6C723.6318B80E@mindspring.com>
References:  <20020324173513.A75429@xor.obsecurity.org> <20020324.184313.30925676.imp@village.org> <20020324175436.A75804@xor.obsecurity.org> <20020330224648.A93819@xor.obsecurity.org> <3CA6C280.F41FBB55@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert wrote:
> Kris Kennaway wrote:
> > How does one fix this in a library?  I've been moving the
> > initialization to main() for applications.
> 
> Use assembly glue to put it in a linker set that gets pulled
> in by the .init code.
> 
> This will only work for user space code, since it depends in
> the crt0 treating it like a C++ binary (linker sets are a C++
> feature which FreeBSD uses all over anyway).

Realizing that I think this is the wrong way to fix this problem,
add the following to your library:

foo.c:
	#include <sys/linker_set.h>

	static void
	run_before_main(void)
	{
		...	/* my crap */
	}
	TEXT_SET(__CTOR_LIST__, run_before_main);

If you want something run on rundown, use:

	TEXT_SET(__DTOR_LIST__, run_after_main);

(or just use atexit(3), if you can live with the registration
polluting your source code).

Doing the code this way will guarantee that your code will
work on any FreeBSD supported platform where C++ works.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3CA6C723.6318B80E>