Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Apr 1999 09:39:41 -0700 (PDT)
From:      John Polstra <jdp@polstra.com>
To:        n@nectar.com
Cc:        hackers@freebsd.org
Subject:   Re: __attribute__ ((constructor)) functions & shared libs
Message-ID:  <199904181639.JAA20403@vashon.polstra.com>
In-Reply-To: <199904180853.DAA22110@spawn.nectar.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <199904180853.DAA22110@spawn.nectar.com>,
Jacques Vidrine  <n@nectar.com> wrote:
> 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.

Which version/date of FreeBSD?

> 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.

If it's ELF, the dynamic linker runs before crt1 gets control.  The
kernel invokes the dynamic linker directly.  After it has finished
its job, the dynamic linker transfers control to the main program's
entry point.

You are not officially "allowed" to assume that anything is already
initialized in those constructor/destructor functions.  Not even
printf is really guaranteed to work.  But perhaps we can make some
simple changes so that most things will work despite that.

John
-- 
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Self-interest is the aphrodisiac of belief."           -- James V. DeLong


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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904181639.JAA20403>