[PATCH][GOLD] Avoid generating unused dynamic relocation for __exidx_{start,end}
Doug Kwan (關振德)
dougkwan@google.com
Tue Mar 13 23:19:00 GMT 2012
[resend a previously sent e-mail to include binutils]
Hi Ian,
This patch fixes a problem in which unnecessary dynamic relocations
are generated for __exidx_{start,end}. These symbols are special and
references to them should use the local definition. Currently we
define these symbols in the ARM backend too late. The patch adds a
new target hook to generate target-specific symbols.
2012-03-13 Doug Kwan <dougkwan@google.com>
* arm.cc (Target_arm::do_define_standard_symbols): New method.
(Target_arm::do_finalize_sections): Remove code which defines
__exidx_start and __exidx_end. Make symbol table parameter
anonymous as it is not used.
* gold.cc (queue_middle_tasks): Call target hook to define any
target-specific symbols.
* target.h (Target::define_standard_symbols): New method.
(Target::do_define_standard_symbols): Same.
* testsuite/Makefile.am (arm_exidx_test): Dump relocations also.
* testsuite/Makefile.in: Regenerate.
* testsuite/arm_exidx.s: Generate data relocations for __exidx_start
and __exidx_end.
* testsuite/arm_exidx_test.sh: Check that no unused dynamic
relocations are generated for __exidx_start and __exidx_end.
-Doug
-------------- next part --------------
Index: gold/arm.cc
===================================================================
RCS file: /cvs/src/src/gold/arm.cc,v
retrieving revision 1.146
diff -u -u -p -r1.146 arm.cc
--- gold/arm.cc 3 Feb 2012 20:01:01 -0000 1.146
+++ gold/arm.cc 13 Mar 2012 21:05:50 -0000
@@ -2515,6 +2515,9 @@ class Target_arm : public Sized_target<3
&& Target::do_section_may_have_icf_unsafe_pointers(section_name));
}
+ virtual void
+ do_define_standard_symbols(Symbol_table*, Layout*);
+
private:
// The class which scans relocations.
class Scan
@@ -8522,7 +8525,7 @@ void
Target_arm<big_endian>::do_finalize_sections(
Layout* layout,
const Input_objects* input_objects,
- Symbol_table* symtab)
+ Symbol_table*)
{
bool merged_any_attributes = false;
// Merge processor-specific flags.
@@ -8609,18 +8612,6 @@ Target_arm<big_endian>::do_finalize_sect
if (exidx_section != NULL
&& exidx_section->type() == elfcpp::SHT_ARM_EXIDX)
{
- // Create __exidx_start and __exidx_end symbols.
- symtab->define_in_output_data("__exidx_start", NULL,
- Symbol_table::PREDEFINED,
- exidx_section, 0, 0, elfcpp::STT_OBJECT,
- elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN,
- 0, false, true);
- symtab->define_in_output_data("__exidx_end", NULL,
- Symbol_table::PREDEFINED,
- exidx_section, 0, 0, elfcpp::STT_OBJECT,
- elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN,
- 0, true, true);
-
// For the ARM target, we need to add a PT_ARM_EXIDX segment for
// the .ARM.exidx section.
if (!layout->script_options()->saw_phdrs_clause())
@@ -8634,19 +8625,6 @@ Target_arm<big_endian>::do_finalize_sect
elfcpp::PF_R);
}
}
- else
- {
- symtab->define_as_constant("__exidx_start", NULL,
- Symbol_table::PREDEFINED,
- 0, 0, elfcpp::STT_OBJECT,
- elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
- true, false);
- symtab->define_as_constant("__exidx_end", NULL,
- Symbol_table::PREDEFINED,
- 0, 0, elfcpp::STT_OBJECT,
- elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
- true, false);
- }
}
// Create an .ARM.attributes section if we have merged any attributes
@@ -11934,6 +11912,61 @@ Target_arm<big_endian>::fix_exidx_covera
merge_exidx_entries(), task);
}
+template<bool big_endian>
+void
+Target_arm<big_endian>::do_define_standard_symbols(
+ Symbol_table* symtab,
+ Layout* layout)
+{
+ // Handle the .ARM.exidx section.
+ Output_section* exidx_section = layout->find_output_section(".ARM.exidx");
+
+ if (exidx_section != NULL)
+ {
+ // Create __exidx_start and __exidx_end symbols.
+ symtab->define_in_output_data("__exidx_start",
+ NULL, // version
+ Symbol_table::PREDEFINED,
+ exidx_section,
+ 0, // value
+ 0, // symsize
+ elfcpp::STT_NOTYPE,
+ elfcpp::STB_GLOBAL,
+ elfcpp::STV_HIDDEN,
+ 0, // nonvis
+ false, // offset_is_from_end
+ true); // only_if_ref
+
+ symtab->define_in_output_data("__exidx_end",
+ NULL, // version
+ Symbol_table::PREDEFINED,
+ exidx_section,
+ 0, // value
+ 0, // symsize
+ elfcpp::STT_NOTYPE,
+ elfcpp::STB_GLOBAL,
+ elfcpp::STV_HIDDEN,
+ 0, // nonvis
+ true, // offset_is_from_end
+ true); // only_if_ref
+ }
+ else
+ {
+ // Define __exidx_start and __exidx_end even when .ARM.exidx
+ // section is missing to match ld's behaviour.
+ symtab->define_as_constant("__exidx_start", NULL,
+ Symbol_table::PREDEFINED,
+ 0, 0, elfcpp::STT_OBJECT,
+ elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
+ true, false);
+ symtab->define_as_constant("__exidx_end", NULL,
+ Symbol_table::PREDEFINED,
+ 0, 0, elfcpp::STT_OBJECT,
+ elfcpp::STB_GLOBAL, elfcpp::STV_HIDDEN, 0,
+ true, false);
+ }
+}
+
Target_selector_arm<false> target_selector_arm;
Target_selector_arm<true> target_selector_armbe;
Index: gold/gold.cc
===================================================================
RCS file: /cvs/src/src/gold/gold.cc,v
retrieving revision 1.97
diff -u -u -p -r1.97 gold.cc
--- gold/gold.cc 18 Oct 2011 00:06:09 -0000 1.97
+++ gold/gold.cc 13 Mar 2012 21:05:50 -0000
@@ -679,6 +679,8 @@ queue_middle_tasks(const General_options
// Attach sections to segments.
layout->attach_sections_to_segments();
+ // TODO(csilvers): figure out a more principled way to get the target
+ Target* target = const_cast<Target*>(¶meters->target());
if (!parameters->options().relocatable())
{
// Predefine standard symbols.
@@ -687,6 +689,9 @@ queue_middle_tasks(const General_options
// Define __start and __stop symbols for output sections where
// appropriate.
layout->define_section_symbols(symtab);
+
+ // Define target-specific symbols.
+ target->define_standard_symbols(symtab, layout);
}
// Make sure we have symbols for any required group signatures.
@@ -768,8 +773,6 @@ queue_middle_tasks(const General_options
// When all those tasks are complete, we can start laying out the
// output file.
- // TODO(csilvers): figure out a more principled way to get the target
- Target* target = const_cast<Target*>(¶meters->target());
workqueue->queue(new Task_function(new Layout_task_runner(options,
input_objects,
symtab,
Index: gold/target.h
===================================================================
RCS file: /cvs/src/src/gold/target.h,v
retrieving revision 1.63
diff -u -u -p -r1.63 target.h
--- gold/target.h 4 Jan 2012 00:18:23 -0000 1.63
+++ gold/target.h 13 Mar 2012 21:05:50 -0000
@@ -396,6 +396,11 @@ class Target
set_osabi(elfcpp::ELFOSABI osabi)
{ this->osabi_ = osabi; }
+ // Define target-specific standard symbols.
+ void
+ define_standard_symbols(Symbol_table* symtab, Layout* layout)
+ { this->do_define_standard_symbols(symtab, layout); }
+
protected:
// This struct holds the constant information for a child class. We
// use a struct to avoid the overhead of virtual function calls for
@@ -629,6 +634,11 @@ class Target
do_select_as_default_target()
{ }
+ // This may be overridden by the child class.
+ virtual void
+ do_define_standard_symbols(Symbol_table*, Layout*)
+ { }
+
private:
// The implementations of the four do_make_elf_object virtual functions are
// almost identical except for their sizes and endianness. We use a template.
Index: gold/testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.188
diff -u -u -p -r1.188 Makefile.am
--- gold/testsuite/Makefile.am 16 Feb 2012 19:37:33 -0000 1.188
+++ gold/testsuite/Makefile.am 13 Mar 2012 21:05:50 -0000
@@ -2500,7 +2500,7 @@ check_SCRIPTS += arm_exidx_test.sh
check_DATA += arm_exidx_test.stdout
arm_exidx_test.stdout: arm_exidx_test.so
- $(TEST_READELF) -S $< > $@
+ $(TEST_READELF) -Sr $< > $@
arm_exidx_test.so: arm_exidx_test.o ../ld-new
../ld-new -shared -o $@ $<
Index: gold/testsuite/arm_exidx_test.s
===================================================================
RCS file: /cvs/src/src/gold/testsuite/arm_exidx_test.s,v
retrieving revision 1.2
diff -u -u -p -r1.2 arm_exidx_test.s
--- gold/testsuite/arm_exidx_test.s 24 Jun 2011 16:40:34 -0000 1.2
+++ gold/testsuite/arm_exidx_test.s 13 Mar 2012 21:05:50 -0000
@@ -23,3 +23,9 @@ empty:
.fnend
.size empty, .-empty
+# Check that no dynamic relocations for __exidx_start and __exidx_stop
+# generated.
+ .data
+ .align 12
+ .word __exidx_start(got)
+ .word __exidx_end(got)
Index: gold/testsuite/arm_exidx_test.sh
===================================================================
RCS file: /cvs/src/src/gold/testsuite/arm_exidx_test.sh,v
retrieving revision 1.1
diff -u -u -p -r1.1 arm_exidx_test.sh
--- gold/testsuite/arm_exidx_test.sh 22 Apr 2011 21:50:03 -0000 1.1
+++ gold/testsuite/arm_exidx_test.sh 13 Mar 2012 21:05:50 -0000
@@ -29,10 +29,23 @@ check()
{
if ! grep -q "$2" "$1"
then
- echo "Did not find section header in $1:"
+ echo "Did not find expected output in $1:"
echo " $2"
echo ""
- echo "Actual headers below:"
+ echo "Actual output below:"
+ cat "$1"
+ exit 1
+ fi
+}
+
+check_not()
+{
+ if grep -q "$2" "$1"
+ then
+ echo "Found unexpected output in $1:"
+ echo " $2"
+ echo ""
+ echo "Actual output below:"
cat "$1"
exit 1
fi
@@ -41,5 +54,7 @@ check()
# Check that SHF_LINK_ORDER is set.
check arm_exidx_test.stdout ".* .ARM.exidx .* ARM_EXIDX .* AL .*"
check arm_exidx_test.stdout ".* .ARM.extab .* PROGBITS .* A .*"
+check_not arm_exidx_test.stdout ".* .* R_ARM_GLOB_DAT .* __exidx_start"
+check_not arm_exidx_test.stdout ".* .* R_ARM_GLOB_DAT .* __exidx_end"
exit 0
More information about the Binutils
mailing list