This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[GOLD] Reduce size of class Symbol
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Cc: Cary Coutant <ccoutant at gmail dot com>
- Date: Tue, 1 Aug 2017 13:46:14 +0930
- Subject: [GOLD] Reduce size of class Symbol
- Authentication-results: sourceware.org; auth=none
On 64-bit targets there is a 32-bit hole in symbol->u_, and another
due to symbol flags exceeding 32 bits. By moving plt_offset into the
union hole, the total size of the class reduces by one 64-bit word.
How much does this save? Well, most targets create symbols as a
Sized_symbol. The patch reduces the size of a 64-bit Sized_symbol on
a 64-bit host from 88 bytes to 80 bytes, and a 32-bit Sized_symbol
from 80 bytes to 72 bytes. On a typical 32-bit host, sizes are
unchanged.
OK, or should I not worry about memory on a C++ project? ;)
* symtab.h (Symbol): Move plt_offset_ to union u_ structs.
Rearrange fields of u_ structs.
(Symbol::has_plt_offset, plt_offset, set_plt_offset): Adjust
to suit.
* symtab.cc (Symbol::init_fields): Adjust to suit.
diff --git a/gold/symtab.cc b/gold/symtab.cc
index 7e0a3f8..8108e4a 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -60,7 +60,7 @@ Symbol::init_fields(const char* name, const char* version,
this->symtab_index_ = 0;
this->dynsym_index_ = 0;
this->got_offsets_.init();
- this->plt_offset_ = -1U;
+ this->u_.from_object.plt_offset = -1U;
this->type_ = type;
this->binding_ = binding;
this->visibility_ = visibility;
diff --git a/gold/symtab.h b/gold/symtab.h
index d881026..95d2892 100644
--- a/gold/symtab.h
+++ b/gold/symtab.h
@@ -448,14 +448,14 @@ class Symbol
// Return whether this symbol has an entry in the PLT section.
bool
has_plt_offset() const
- { return this->plt_offset_ != -1U; }
+ { return this->u_.from_object.plt_offset != -1U; }
// Return the offset into the PLT section of this symbol.
unsigned int
plt_offset() const
{
gold_assert(this->has_plt_offset());
- return this->plt_offset_;
+ return this->u_.from_object.plt_offset;
}
// Set the PLT offset of this symbol.
@@ -463,7 +463,7 @@ class Symbol
set_plt_offset(unsigned int plt_offset)
{
gold_assert(plt_offset != -1U);
- this->plt_offset_ = plt_offset;
+ this->u_.from_object.plt_offset = plt_offset;
}
// Return whether this dynamic symbol needs a special value in the
@@ -988,33 +988,41 @@ class Symbol
// This struct is used if SOURCE_ == FROM_OBJECT.
struct
{
+ // If this symbol has an entry in the PLT section, then this is the
+ // offset from the start of the PLT section. This is -1U if there
+ // is no PLT entry.
+ unsigned int plt_offset;
+ // Section number in object in which symbol is defined.
+ unsigned int shndx;
// Object in which symbol is defined, or in which it was first
// seen.
Object* object;
- // Section number in object_ in which symbol is defined.
- unsigned int shndx;
} from_object;
// This struct is used if SOURCE_ == IN_OUTPUT_DATA.
struct
{
+ // This field is common to all variants of this union
+ unsigned int plt_offset;
+ // True if the offset is from the end, false if the offset is
+ // from the beginning.
+ bool offset_is_from_end;
// Output_data in which symbol is defined. Before
// Layout::finalize the symbol's value is an offset within the
// Output_data.
Output_data* output_data;
- // True if the offset is from the end, false if the offset is
- // from the beginning.
- bool offset_is_from_end;
} in_output_data;
// This struct is used if SOURCE_ == IN_OUTPUT_SEGMENT.
struct
{
+ // This field is common to all variants of this union
+ unsigned int plt_offset;
+ // The base to use for the offset before Layout::finalize.
+ Segment_offset_base offset_base;
// Output_segment in which the symbol is defined. Before
// Layout::finalize the symbol's value is an offset.
Output_segment* output_segment;
- // The base to use for the offset before Layout::finalize.
- Segment_offset_base offset_base;
} in_output_segment;
} u_;
@@ -1035,11 +1043,6 @@ class Symbol
// different TLS models), but will usually have at most one.
Got_offset_list got_offsets_;
- // If this symbol has an entry in the PLT section, then this is the
- // offset from the start of the PLT section. This is -1U if there
- // is no PLT entry.
- unsigned int plt_offset_;
-
// Symbol type (bits 0 to 3).
elfcpp::STT type_ : 4;
// Symbol binding (bits 4 to 7).
--
Alan Modra
Australia Development Lab, IBM