From owner-freebsd-current Sun Mar 31 0:22:39 2002 Delivered-To: freebsd-current@freebsd.org Received: from avocet.prod.itd.earthlink.net (avocet.mail.pas.earthlink.net [207.217.120.50]) by hub.freebsd.org (Postfix) with ESMTP id 0ADCC37B417; Sun, 31 Mar 2002 00:22:33 -0800 (PST) Received: from pool0142.cvx22-bradley.dialup.earthlink.net ([209.179.198.142] helo=mindspring.com) by avocet.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16rabV-00021H-00; Sun, 31 Mar 2002 00:22:21 -0800 Message-ID: <3CA6C723.6318B80E@mindspring.com> Date: Sun, 31 Mar 2002 00:21:55 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Kris Kennaway , "M. Warner Losh" , current@FreeBSD.org, peter@FreeBSD.org Subject: Re: stdout changes break some ports 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 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