This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [GOLD] Reduce size of class Symbol
- From: Alan Modra <amodra at gmail dot com>
- To: Cary Coutant <ccoutant at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Fri, 4 Aug 2017 15:30:57 +0930
- Subject: Re: [GOLD] Reduce size of class Symbol
- Authentication-results: sourceware.org; auth=none
- References: <20170801041614.GN1956@bubble.grove.modra.org> <CAJimCsGh3rPDRMUDEx97ryrcHJMi5U=ceGXpBXU4ZOSK7H=-iQ@mail.gmail.com>
On Thu, Aug 03, 2017 at 10:12:52PM -0700, Cary Coutant wrote:
> I like the goal, but the problem is that you're always accessing the
> plt_offset through the u_.from_object variant, no matter what variant
> is actually there. While you've been careful to make sure that the
> plt_offset field has the same offset in each variant, it's still both
> fragile and technically illegal.
This trick is allowed by the ISO C standard according to the
following, and I'm assuming is also valid for C++. Re accessing via
the from_object variant, yes I guess it might be better style to
create a new struct union member just containing plt_offset.
>From ISO/IEC 9899:1999 section 6.5.2.3 Structure and union members
5 One special guarantee is made in order to simplify the use of
unions: if a union contains several structures that share a common
initial sequence (see below), and if the union object currently
contains one of these structures, it is permitted to inspect the
common initial part of any of them anywhere that a declaration of
the completed type of the union is visible. Two structures share a
common initial sequence if corresponding members have compatible
types (and, for bit-fields, the same widths) for a sequence of one
or more initial members.
[snip]
8 EXAMPLE 3
The following is a valid fragment:
union {
struct {
int alltypes;
} n;
struct {
int type;
int intnode;
} ni;
struct {
int type;
double doublenode;
} nf;
} u;
u.nf.type = 1;
u.nf.doublenode = 3.14;
/* ... */
if (u.n.alltypes == 1)
if (sin(u.nf.doublenode) == 0.0)
/* ... */
--
Alan Modra
Australia Development Lab, IBM