Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

Subject: Re: [OMPI devel] RFC: Add an __attribute__((destructor)) function to opal
From: Joshua Ladd (jladd.mlnx_at_[hidden])
Date: 2014-07-15 19:52:47


According to http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

*"constructor *
* destructor *
* constructor (*priority*)** destructor (priority)**The constructor
attribute causes the function to be called automatically before execution
enters main (). Similarly, the destructor attribute causes the function to
be called automatically after main () completes or exit () is called.
Functions with these attributes are useful for initializing data that is
used implicitly during the execution of the program. *

*You may provide an optional integer priority to control the order in which
constructor and destructor functions are run. A constructor with a smaller
priority number runs before a constructor with a larger priority number;
the opposite relationship holds for destructors. So, if you have a
constructor that allocates a resource and a destructor that deallocates the
same resource, both functions typically have the same priority. The
priorities for constructor and destructor functions are the same as those
specified for namespace-scope C++ objects (see C++ Attributes
<http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#C_002b_002b-Attributes>).
*

*These attributes are not currently implemented for Objective-C."*

On Tue, Jul 15, 2014 at 5:20 PM, Paul Hargrove <phhargrove_at_[hidden]> wrote:

>
> On Tue, Jul 15, 2014 at 12:49 PM, Pritchard, Howard r <howardp_at_[hidden]>
> wrote:
>
>> I don't think there's anything wrong with using ctor/dtors in shared
>> libraries,
>> but one does need to make sure that in these functions there's no
>> assumptions
>> about ordering of them wrt to other ctors/dtors.
>>
>
> The ELF specification is clear that the order of execution of DT_INIT and
> DT_FINI entries is undefined.
> The .ctors and .dtors sections typically used by the GNU toolchain are, I
> believe, not part of any formal linker specification.
> So, I agree w/ Howard that one must take care not to assume anything about
> order.
>
> -Paul
>
>
> --
> Paul H. Hargrove PHHargrove_at_[hidden]
> Future Technologies Group
> Computer and Data Sciences Department Tel: +1-510-495-2352
> Lawrence Berkeley National Laboratory Fax: +1-510-486-6900
>
> _______________________________________________
> devel mailing list
> devel_at_[hidden]
> Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/devel
> Link to this post:
> http://www.open-mpi.org/community/lists/devel/2014/07/15153.php
>