From owner-freebsd-hackers Sun Apr 18 1:57:38 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from cerebus.nectar.com (nectar-gw.nectar.com [204.0.249.101]) by hub.freebsd.org (Postfix) with ESMTP id 624CC14F86 for ; Sun, 18 Apr 1999 01:57:35 -0700 (PDT) (envelope-from nectar@nectar.com) Received: (from smap@localhost) by cerebus.nectar.com (8.9.1/8.9.1) id DAA61035 for ; Sun, 18 Apr 1999 03:55:11 -0500 (CDT) (envelope-from nectar@nectar.com) Received: from spawn.nectar.com(10.0.0.101) by cerebus.nectar.com via smap (V2.1) id xma061033; Sun, 18 Apr 99 03:55:04 -0500 Received: from spawn.nectar.com (localhost [127.0.0.1]) by spawn.nectar.com (8.9.3/8.9.1) with ESMTP id DAA22110 for ; Sun, 18 Apr 1999 03:53:42 -0500 (CDT) (envelope-from nectar@spawn.nectar.com) Message-Id: <199904180853.DAA22110@spawn.nectar.com> X-Mailer: exmh version 2.0.2 2/24/98 X-Exmh-Isig-CompType: unknown X-Exmh-Isig-Folder: mlist/freebsd/hackers X-PGP-RSAfprint: 00 F9 E6 A2 C5 4D 0A 76 26 8B 8B 57 73 D0 DE EE X-PGP-RSAkey: http://www.nectar.com/nectar-rsa.txt X-PGP-DSSfprint: AB2F 8D71 A4F4 467D 352E 8A41 5D79 22E4 71A2 8C73 X-PGP-DHfprint: 2D50 12E5 AB38 60BA AF4B 0778 7242 4460 1C32 F6B1 X-PGP-DH-DSSkey: http://www.nectar.com/nectar-dh-dss.txt From: Jacques Vidrine Subject: __attribute__ ((constructor)) functions & shared libs Mime-Version: 1.0 Content-Type: text/plain To: hackers@freebsd.org Date: Sun, 18 Apr 1999 03:53:42 -0500 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi all, I'm porting an application that uses ``__attribute__ ((constructor))'' to give shared libraries initialization functions. Unfortunately, it seems that environ is not yet initialized when these functions are called. A brief example: libfoo.so has init function ``libfoo_init'' which looks like this: extern char **environ; void libfoo_init(void) __attribute__ ((constructor)); void libfoo_init(void) { fprintf(stderr, "getenv(\"HOME\") = \"%s\"\n", getenv("HOME")); fprintf(stderr, "environ = %p\n", environ); } An application linked with this library will display: getenv("HOME") = "(null)" environ = 0x0 even though HOME is, of course, set in the environment. What might I be missing? Looking at src/lib/csu/i386-elf/crt1.c, it seems as if environ is set before invoking the run time linker. Jacques Vidrine / n@nectar.com / nectar@FreeBSD.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message