[PATCH][GOLD] Make relocation stub order independent of Unordered_map implementation.
Doug Kwan (關振德)
dougkwan@google.com
Wed Mar 17 23:02:00 GMT 2010
Hi,
This patch changes the way relocations stub offsets are assigned
so that the offsets are independent of the implementation of
Unordered_map. It also move code to initialize
Stringpool_template::offset_ to make
Stringpool_template::new_key_offset() doing less work. This was
tested on both x86_64 and ARM Linux.
-Doug
2010-03-17 Doug Kwan <dougkwan@google.com>
* arm.cc (Stub_table::Stub_table): Initialize new data members
Stub_table::reloc_stubs_size_ and Stub_table::reloc_stubs_addralign_.
(Stub_table::add_reloc_stub): Assign stub offset and update
Stub_table::reloc_stubs_size_ and Stub_table::reloc_stubs_addralign_.
(Stub_table::reloc_stubs_size_, Stub_table::reloc_stubs_addralign_):
New data members.
(Stub_table::update_data_size_and_addralign): Use
Stub_table::reloc_stubs_size_ and Stub_table::reloc_stubs_addralign_
instead of going over all reloc stubs.
(Stub_table::finalize_stubs): Do not assign reloc stub offsets.
* stringpool.cc (Stringpool_template::Stringpool_template): Initialize
Stringpool_template::offset_ depending on
Stringpool_template::zero_null_.
(Stringpool_template::new_key_offset): Remove code to initialize
Stringpool_template::offset_.
* stringpool.h (Stringpool_template::set_no_zero_null): Set
Stringpool_template::offset_ to zero.
-------------- next part --------------
Index: gold/arm.cc
===================================================================
RCS file: /cvs/src/src/gold/arm.cc,v
retrieving revision 1.92
diff -u -u -p -r1.92 arm.cc
--- gold/arm.cc 8 Mar 2010 22:15:16 -0000 1.92
+++ gold/arm.cc 17 Mar 2010 21:14:37 -0000
@@ -868,8 +868,9 @@ class Stub_table : public Output_data
{
public:
Stub_table(Arm_input_section<big_endian>* owner)
- : Output_data(), owner_(owner), reloc_stubs_(), cortex_a8_stubs_(),
- arm_v4bx_stubs_(0xf), prev_data_size_(0), prev_addralign_(1)
+ : Output_data(), owner_(owner), reloc_stubs_(), reloc_stubs_size_(0),
+ reloc_stubs_addralign_(1), cortex_a8_stubs_(), arm_v4bx_stubs_(0xf),
+ prev_data_size_(0), prev_addralign_(1)
{ }
~Stub_table()
@@ -902,6 +903,15 @@ class Stub_table : public Output_data
const Stub_template* stub_template = stub->stub_template();
gold_assert(stub_template->type() == key.stub_type());
this->reloc_stubs_[key] = stub;
+
+ // Assign stub offset early. We can do this because we never remove
+ // reloc stubs and they are in the beginning of the stub table.
+ uint64_t align = stub_template->alignment();
+ this->reloc_stubs_size_ = align_address(this->reloc_stubs_size_, align);
+ stub->set_offset(this->reloc_stubs_size_);
+ this->reloc_stubs_size_ += stub_template->size();
+ this->reloc_stubs_addralign_ =
+ std::max(this->reloc_stubs_addralign_, align);
}
// Add a Cortex-A8 STUB that fixes up a THUMB branch at ADDRESS.
@@ -1010,6 +1020,10 @@ class Stub_table : public Output_data
Arm_input_section<big_endian>* owner_;
// The relocation stubs.
Reloc_stub_map reloc_stubs_;
+ // Size of reloc stubs.
+ off_t reloc_stubs_size_;
+ // Maximum address alignment of reloc stubs.
+ uint64_t reloc_stubs_addralign_;
// The cortex_a8_stubs.
Cortex_a8_stub_list cortex_a8_stubs_;
// The Arm V4BX relocation stubs.
@@ -4720,20 +4734,9 @@ template<bool big_endian>
bool
Stub_table<big_endian>::update_data_size_and_addralign()
{
- off_t size = 0;
- unsigned addralign = 1;
-
// Go over all stubs in table to compute data size and address alignment.
-
- for (typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.begin();
- p != this->reloc_stubs_.end();
- ++p)
- {
- const Stub_template* stub_template = p->second->stub_template();
- addralign = std::max(addralign, stub_template->alignment());
- size = (align_address(size, stub_template->alignment())
- + stub_template->size());
- }
+ off_t size = this->reloc_stubs_size_;
+ unsigned addralign = this->reloc_stubs_addralign_;
for (Cortex_a8_stub_list::const_iterator p = this->cortex_a8_stubs_.begin();
p != this->cortex_a8_stubs_.end();
@@ -4778,19 +4781,7 @@ template<bool big_endian>
void
Stub_table<big_endian>::finalize_stubs()
{
- off_t off = 0;
- for (typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.begin();
- p != this->reloc_stubs_.end();
- ++p)
- {
- Reloc_stub* stub = p->second;
- const Stub_template* stub_template = stub->stub_template();
- uint64_t stub_addralign = stub_template->alignment();
- off = align_address(off, stub_addralign);
- stub->set_offset(off);
- off += stub_template->size();
- }
-
+ off_t off = this->reloc_stubs_size_;
for (Cortex_a8_stub_list::const_iterator p = this->cortex_a8_stubs_.begin();
p != this->cortex_a8_stubs_.end();
++p)
Index: gold/stringpool.cc
===================================================================
RCS file: /cvs/src/src/gold/stringpool.cc,v
retrieving revision 1.31
diff -u -u -p -r1.31 stringpool.cc
--- gold/stringpool.cc 16 Mar 2010 01:26:15 -0000 1.31
+++ gold/stringpool.cc 17 Mar 2010 21:14:37 -0000
@@ -36,7 +36,8 @@ namespace gold
template<typename Stringpool_char>
Stringpool_template<Stringpool_char>::Stringpool_template()
: string_set_(), key_to_offset_(), strings_(), strtab_size_(0),
- zero_null_(true), optimize_(false), offset_(0)
+ zero_null_(true), optimize_(false),
+ offset_(this->zero_null_ ? sizeof(Stringpool_char) : 0)
{
if (parameters->options_valid() && parameters->options().optimize() >= 2)
this->optimize_ = true;
@@ -238,9 +239,6 @@ template<typename Stringpool_char>
void
Stringpool_template<Stringpool_char>::new_key_offset(size_t length)
{
- if (this->key_to_offset_.size() == 0)
- this->offset_ = this->zero_null_ ? sizeof(Stringpool_char) : 0;
-
section_offset_type offset;
if (this->zero_null_ && length == 0)
offset = 0;
Index: gold/stringpool.h
===================================================================
RCS file: /cvs/src/src/gold/stringpool.h,v
retrieving revision 1.24
diff -u -u -p -r1.24 stringpool.h
--- gold/stringpool.h 16 Mar 2010 01:26:15 -0000 1.24
+++ gold/stringpool.h 17 Mar 2010 21:14:37 -0000
@@ -180,6 +180,7 @@ class Stringpool_template
{
gold_assert(this->string_set_.empty());
this->zero_null_ = false;
+ this->offset_ = 0;
}
// Indicate that this string pool should be optimized, even if not
More information about the Binutils
mailing list