This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: gold alignment for 64-bit target in 32-bit binary
David Miller <davem@davemloft.net> writes:
> From: Ian Lance Taylor <iant@google.com>
> Date: Sat, 19 Apr 2008 15:59:33 -0700
>
>> I haven't forgotten about this, but without access to a strict
>> alignment system I'm not sure how to track it down. Can you send me a
>> backtrace from the bus error?
>>
>> There isn't supposed to be anything in gold which is based on the host
>> alignment.
>
> Sure thing. The problem seems to be ehdr_buf[] in
> gold::Read_symbols::do_read_symbols()
Ah, thanks. That code was written before the mmap support, and it is
now outdated. I committed the appended patch which should fix the
problem, and should make gold infinitesimally faster.
Ian
2008-04-23 Ian Lance Taylor <iant@google.com>
* readsyms.cc (Read_symbols::do_read_symbols): Use get_view rather
than read for file header.
* archive.cc (Archive::include_member): Likewise.
Index: archive.cc
===================================================================
RCS file: /cvs/src/src/gold/archive.cc,v
retrieving revision 1.28
diff -u -p -r1.28 archive.cc
--- archive.cc 2 Apr 2008 20:58:21 -0000 1.28
+++ archive.cc 23 Apr 2008 15:28:12 -0000
@@ -464,9 +464,6 @@ Archive::include_member(Symbol_table* sy
memoff = 0;
}
- // Read enough of the file to pick up the entire ELF header.
- unsigned char ehdr_buf[elfcpp::Elf_sizes<64>::ehdr_size];
-
off_t filesize = input_file->file().filesize();
int read_size = elfcpp::Elf_sizes<64>::ehdr_size;
if (filesize - memoff < read_size)
@@ -479,14 +476,15 @@ Archive::include_member(Symbol_table* sy
return;
}
- input_file->file().read(memoff, read_size, ehdr_buf);
+ const unsigned char* ehdr = input_file->file().get_view(memoff, 0, read_size,
+ true, false);
static unsigned char elfmagic[4] =
{
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
elfcpp::ELFMAG2, elfcpp::ELFMAG3
};
- if (memcmp(ehdr_buf, elfmagic, 4) != 0)
+ if (memcmp(ehdr, elfmagic, 4) != 0)
{
gold_error(_("%s: member at %zu is not an ELF object"),
this->name().c_str(), static_cast<size_t>(off));
@@ -495,8 +493,7 @@ Archive::include_member(Symbol_table* sy
Object* obj = make_elf_object((std::string(this->input_file_->filename())
+ "(" + n + ")"),
- input_file, memoff, ehdr_buf,
- read_size);
+ input_file, memoff, ehdr, read_size);
if (input_objects->add_object(obj))
{
Index: readsyms.cc
===================================================================
RCS file: /cvs/src/src/gold/readsyms.cc,v
retrieving revision 1.27
diff -u -p -r1.27 readsyms.cc
--- readsyms.cc 1 Apr 2008 20:57:36 -0000 1.27
+++ readsyms.cc 23 Apr 2008 15:28:12 -0000
@@ -152,13 +152,12 @@ Read_symbols::do_read_symbols(Workqueue*
return false;
}
- unsigned char ehdr_buf[elfcpp::Elf_sizes<64>::ehdr_size];
-
int read_size = elfcpp::Elf_sizes<64>::ehdr_size;
if (filesize < read_size)
read_size = filesize;
- input_file->file().read(0, read_size, ehdr_buf);
+ const unsigned char* ehdr = input_file->file().get_view(0, 0, read_size,
+ true, false);
if (read_size >= 4)
{
@@ -167,12 +166,12 @@ Read_symbols::do_read_symbols(Workqueue*
elfcpp::ELFMAG0, elfcpp::ELFMAG1,
elfcpp::ELFMAG2, elfcpp::ELFMAG3
};
- if (memcmp(ehdr_buf, elfmagic, 4) == 0)
+ if (memcmp(ehdr, elfmagic, 4) == 0)
{
// This is an ELF object.
Object* obj = make_elf_object(input_file->filename(),
- input_file, 0, ehdr_buf, read_size);
+ input_file, 0, ehdr, read_size);
if (obj == NULL)
return false;
@@ -205,9 +204,9 @@ Read_symbols::do_read_symbols(Workqueue*
if (read_size >= Archive::sarmag)
{
bool is_thin_archive
- = memcmp(ehdr_buf, Archive::armagt, Archive::sarmag) == 0;
+ = memcmp(ehdr, Archive::armagt, Archive::sarmag) == 0;
if (is_thin_archive
- || memcmp(ehdr_buf, Archive::armag, Archive::sarmag) == 0)
+ || memcmp(ehdr, Archive::armag, Archive::sarmag) == 0)
{
// This is an archive.
Archive* arch = new Archive(this->input_argument_->file().name(),