Re: -z preinitarray
From: Jonathan Adams (jwadams_at_gmail.com)
Date: 04/30/05
- Next message: Jonathan Adams: "Re: Why cannot truss peek inside sendmsg()"
- Previous message: Joerg Schilling: "Re: Using major/minor device numbers to determine SCSI or ATAPI CD-ROM drives"
- In reply to: Dan Koren: "Re: -z preinitarray"
- Next in thread: Dan Koren: "Re: -z preinitarray"
- Reply: Dan Koren: "Re: -z preinitarray"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 29 Apr 2005 15:45:33 -0700
In article <42728e0e@news.meer.net>, "Dan Koren" <dankoren@yahoo.com>
wrote:
> OK, thanks.
>
> Does this imply, in effect, that there is no way for an
> interposer shared library (e.g. a memory allocator) to
> arrange to always initialize itself first, before any
> other library or code in the main executable, and
> regardless of how the main executable may have
> been built?
It generally can't, anyway; relying on init sections to set everything
up is a bad idea. It's much better to set everything up in static data,
and arrange for any additional initialization to happen at the first
call to malloc/calloc/realloc/etc. With a bit of care, this can be done
without impacting the fast path.
The problem is that init section ordering is not guaranteed, especially
when cyclic dependencies happen. The classic problem is LD_BIND_NOW=1
plus C++; libCrun.so.1, libc.so.1, and libmymalloc.so form a cyclic
dependency group, the linker calls libCrun's initializer first, the C++
runtime initialization calls malloc(), but libmymalloc.so's init section
has not fired. Chaos ensues.
Summary: init sections are evil and unreliable; avoid them if you
possibly can.
Cheers,
- jonathan
- Next message: Jonathan Adams: "Re: Why cannot truss peek inside sendmsg()"
- Previous message: Joerg Schilling: "Re: Using major/minor device numbers to determine SCSI or ATAPI CD-ROM drives"
- In reply to: Dan Koren: "Re: -z preinitarray"
- Next in thread: Dan Koren: "Re: -z preinitarray"
- Reply: Dan Koren: "Re: -z preinitarray"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|