This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[gold patch] do not allocate common symbols within the discarded output sections
- From: Viktor Kutuzov <vkutuzov at accesssoftek dot com>
- To: Cary Coutant <ccoutant at google dot com>, Ian Lance Taylor <iant at google dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Tue, 27 Sep 2011 15:28:57 -0700
- Subject: [gold patch] do not allocate common symbols within the discarded output sections
- Reply-to: <vkutuzov at accesssoftek dot com>
Gold gets an internal error on computing of the final values for the
common symbols which were allocated within the discarded output
sections. An appropriate output section could be discarded by the linker
script.
Please find attached patch which prevents allocating of the common
symbols if its target output section has been discarded by any reason.
The command line below reproduces the problem. I tested it on CentOS
5.x/i386, but it should be reproducible on the different systems also.
vkutuzov@:/opt/build/binutils/src/gold/testsuite$ ../ld-new \
-m elf_i386 --eh-frame-hdr --hash-style=gnu \
-L/usr/lib -L/usr/lib/gcc/i386-redhat-linux/4.1.1 \
-l:crt1.o -l:crti.o -l:crtbegin.o \
-nostartfiles -nostdlib -T memory_test.t memory_test.o \
-o memory_test -lc -l:crtend.o -l:crtn.o
../ld-new: internal error in address, at output.h:72
The memory_test.t script is a linker script from the current gold
testsuite set.
Would you review this patch?
Thanks.
Viktor
* common.cc (Symbol_table::do_allocate_commons_list): prevent
allocation of the common symbols within the discarded output
sections.
Index: common.cc
===================================================================
RCS file: /cvs/src/src/gold/common.cc,v
retrieving revision 1.28
diff -u -r1.28 common.cc
--- common.cc 8 Jun 2011 04:43:28 -0000 1.28
+++ common.cc 27 Sep 2011 22:11:53 -0000
@@ -253,10 +253,6 @@
if (!any)
return;
- // Sort the common symbols.
- std::sort(commons->begin(), commons->end(),
- Sort_commons<size>(this, sort_order));
-
// Place them in a newly allocated BSS section.
elfcpp::Elf_Xword flags = elfcpp::SHF_WRITE | elfcpp::SHF_ALLOC;
const char* name;
@@ -303,14 +299,23 @@
os = layout->find_output_section(name);
}
- if (os != NULL)
+ // Do not allocate the common symbols if the output section has been
+ // discarded.
+ if (os == NULL)
{
- if (commons_section_type == COMMONS_SMALL)
- os->set_is_small_section();
- else if (commons_section_type == COMMONS_LARGE)
- os->set_is_large_section();
+ commons->clear();
+ return;
}
+ if (commons_section_type == COMMONS_SMALL)
+ os->set_is_small_section();
+ else if (commons_section_type == COMMONS_LARGE)
+ os->set_is_large_section();
+
+ // Sort the common symbols.
+ std::sort(commons->begin(), commons->end(),
+ Sort_commons<size>(this, sort_order));
+
// Allocate them all.
off_t off = 0;