Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Apr 1999 03:53:42 -0500
From:      Jacques Vidrine <n@nectar.com>
To:        hackers@freebsd.org
Subject:   __attribute__ ((constructor)) functions & shared libs
Message-ID:  <199904180853.DAA22110@spawn.nectar.com>

next in thread | raw e-mail | index | archive | help
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




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