aboutsummaryrefslogtreecommitdiff
path: root/gold/merge.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-10-18 17:46:23 +0000
committerIan Lance Taylor <iant@google.com>2007-10-18 17:46:23 +0000
commit87f9577614a90f155dcdf59864d21dbc3f106469 (patch)
treef8c50dbd3e92c4a509c500608e9510e666cc0904 /gold/merge.cc
parentba32f9896b4b1e79f36ae03ac383869127a461e0 (diff)
downloadgdb-87f9577614a90f155dcdf59864d21dbc3f106469.zip
gdb-87f9577614a90f155dcdf59864d21dbc3f106469.tar.gz
gdb-87f9577614a90f155dcdf59864d21dbc3f106469.tar.bz2
Correctly handle alignment in merge sections.
Diffstat (limited to 'gold/merge.cc')
-rw-r--r--gold/merge.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/gold/merge.cc b/gold/merge.cc
index f31b44e..b5c836f 100644
--- a/gold/merge.cc
+++ b/gold/merge.cc
@@ -23,6 +23,7 @@
#include "gold.h"
#include <cstdlib>
+#include <algorithm>
#include "merge.h"
@@ -161,10 +162,11 @@ void
Output_merge_data::add_constant(const unsigned char* p)
{
uint64_t entsize = this->entsize();
- if (this->len_ + entsize > this->alc_)
+ uint64_t addsize = std::max(entsize, this->addralign());
+ if (this->len_ + addsize > this->alc_)
{
if (this->alc_ == 0)
- this->alc_ = 128 * entsize;
+ this->alc_ = 128 * addsize;
else
this->alc_ *= 2;
this->p_ = static_cast<unsigned char*>(realloc(this->p_, this->alc_));
@@ -173,7 +175,9 @@ Output_merge_data::add_constant(const unsigned char* p)
}
memcpy(this->p_ + this->len_, p, entsize);
- this->len_ += entsize;
+ if (addsize > entsize)
+ memset(this->p_ + this->len_ + entsize, 0, addsize - entsize);
+ this->len_ += addsize;
}
// Add the input section SHNDX in OBJECT to a merged output section