aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorSriraman Tallam <tmsriram@google.com>2010-04-20 21:13:30 +0000
committerSriraman Tallam <tmsriram@google.com>2010-04-20 21:13:30 +0000
commitce97fa81e0c46d216b80b143ad8c02fff6906fef (patch)
tree539a9d93c76d2113b92da17405b144eba8fa92c5 /gold
parentec31cde5942e935e74f6ff919ffc480dfa2f1bac (diff)
downloadgdb-ce97fa81e0c46d216b80b143ad8c02fff6906fef.zip
gdb-ce97fa81e0c46d216b80b143ad8c02fff6906fef.tar.gz
gdb-ce97fa81e0c46d216b80b143ad8c02fff6906fef.tar.bz2
2010-04-18 Sriraman Tallam <tmsriram@google.com>
* icf.cc (get_section_contents): Check for preemptible functions. Ignore addend when appropriate. * symtab.cc (should_add_dynsym_entry): Add new parameter. Check for section folded. (add_from_relobj): Check for section folded. (set_dynsym_indexes): Fix call to should_add_dynsym_entry. * symtab.h (should_add_dynsym_entry): Add new parameter. * target-reloc.h (scan_relocs): Check for section folded. * x86_64.cc (Target_x86_64::Scan::possible_function_pointer_reloc): Check reloc types for function pointers in shared objects. * testsuite/Makefile.am (icf_virtual_function_folding_test): New test case. (icf_preemptible_functions_test): New test case. (icf_string_merge_test): New test case. * testsuite.Makefile.in: Regenerate. * testsuite/icf_safe_so_test.sh: Change to not fold foo_glob and bar_glob. Refactor code. * testsuite/icf_preemptible_functions_test.cc: New file. * testsuite/icf_preemptible_functions_test.sh: New file. * testsuite/icf_string_merge_test.cc: New file. * testsuite/icf_string_merge_test.sh: New file. * testsuite/icf_virtual_function_folding_test.cc: New file. * testsuite/icf_virtual_function_folding_test.sh: New file.
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog26
-rw-r--r--gold/icf.cc16
-rw-r--r--gold/symtab.cc10
-rw-r--r--gold/symtab.h2
-rw-r--r--gold/target-reloc.h4
-rw-r--r--gold/testsuite/Makefile.am27
-rw-r--r--gold/testsuite/Makefile.in24
-rw-r--r--gold/testsuite/icf_preemptible_functions_test.cc47
-rwxr-xr-xgold/testsuite/icf_preemptible_functions_test.sh35
-rwxr-xr-xgold/testsuite/icf_safe_so_test.sh18
-rw-r--r--gold/testsuite/icf_string_merge_test.cc50
-rwxr-xr-xgold/testsuite/icf_string_merge_test.sh37
-rw-r--r--gold/testsuite/icf_virtual_function_folding_test.cc74
-rwxr-xr-xgold/testsuite/icf_virtual_function_folding_test.sh35
-rw-r--r--gold/x86_64.cc11
15 files changed, 391 insertions, 25 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index d553e1b..1045328 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,29 @@
+2010-04-18 Sriraman Tallam <tmsriram@google.com>
+
+ * icf.cc (get_section_contents): Check for preemptible functions.
+ Ignore addend when appropriate.
+ * symtab.cc (should_add_dynsym_entry): Add new parameter. Check for
+ section folded.
+ (add_from_relobj): Check for section folded.
+ (set_dynsym_indexes): Fix call to should_add_dynsym_entry.
+ * symtab.h (should_add_dynsym_entry): Add new parameter.
+ * target-reloc.h (scan_relocs): Check for section folded.
+ * x86_64.cc (Target_x86_64::Scan::possible_function_pointer_reloc):
+ Check reloc types for function pointers in shared objects.
+ * testsuite/Makefile.am (icf_virtual_function_folding_test): New test
+ case.
+ (icf_preemptible_functions_test): New test case.
+ (icf_string_merge_test): New test case.
+ * testsuite.Makefile.in: Regenerate.
+ * testsuite/icf_safe_so_test.sh: Change to not fold foo_glob and
+ bar_glob. Refactor code.
+ * testsuite/icf_preemptible_functions_test.cc: New file.
+ * testsuite/icf_preemptible_functions_test.sh: New file.
+ * testsuite/icf_string_merge_test.cc: New file.
+ * testsuite/icf_string_merge_test.sh: New file.
+ * testsuite/icf_virtual_function_folding_test.cc: New file.
+ * testsuite/icf_virtual_function_folding_test.sh: New file.
+
2010-04-14 Doug Kwan <dougkwan@google.com>
* arm.cc (Arm_output_section::fix_exidx_coverage): Mark object
diff --git a/gold/icf.cc b/gold/icf.cc
index 1f955e6..5040a6e 100644
--- a/gold/icf.cc
+++ b/gold/icf.cc
@@ -304,7 +304,12 @@ get_section_contents(bool first_iteration,
symtab->icf()->section_to_int_map();
Icf::Uniq_secn_id_map::iterator section_id_map_it =
section_id_map.find(reloc_secn);
- if (section_id_map_it != section_id_map.end())
+ bool is_sym_preemptible = (*it_s != NULL
+ && !(*it_s)->is_from_dynobj()
+ && !(*it_s)->is_undefined()
+ && (*it_s)->is_preemptible());
+ if (!is_sym_preemptible
+ && section_id_map_it != section_id_map.end())
{
// This is a reloc to a section that might be folded.
if (num_tracked_relocs)
@@ -338,7 +343,14 @@ get_section_contents(bool first_iteration,
{
uint64_t entsize =
(it_v->first)->section_entsize(it_v->second);
- long long offset = it_a->first + it_a->second;
+ long long offset = it_a->first;
+
+ unsigned long long addend = it_a->second;
+ // Ignoring the addend when it is a negative value. See the
+ // comments in Merged_symbol_value::Value in object.h.
+ if (addend < 0xffffff00)
+ offset = offset + addend;
+
section_size_type secn_len;
const unsigned char* str_contents =
(it_v->first)->section_contents(it_v->second,
diff --git a/gold/symtab.cc b/gold/symtab.cc
index c2a811f..3f85f6c 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -306,7 +306,7 @@ Sized_symbol<size>::allocate_common(Output_data* od, Value_type value)
// table.
inline bool
-Symbol::should_add_dynsym_entry() const
+Symbol::should_add_dynsym_entry(Symbol_table* symtab) const
{
// If the symbol is used by a dynamic relocation, we need to add it.
if (this->needs_dynsym_entry())
@@ -324,7 +324,8 @@ Symbol::should_add_dynsym_entry() const
bool is_ordinary;
unsigned int shndx = this->shndx(&is_ordinary);
if (is_ordinary && shndx != elfcpp::SHN_UNDEF
- && !relobj->is_section_included(shndx))
+ && !relobj->is_section_included(shndx)
+ && !symtab->is_section_folded(relobj, shndx))
return false;
}
@@ -1072,7 +1073,8 @@ Symbol_table::add_from_relobj(
bool is_defined_in_discarded_section = false;
if (st_shndx != elfcpp::SHN_UNDEF
&& is_ordinary
- && !relobj->is_section_included(st_shndx))
+ && !relobj->is_section_included(st_shndx)
+ && !this->is_section_folded(relobj, st_shndx))
{
st_shndx = elfcpp::SHN_UNDEF;
is_defined_in_discarded_section = true;
@@ -2253,7 +2255,7 @@ Symbol_table::set_dynsym_indexes(unsigned int index,
// some symbols appear more than once in the symbol table, with
// and without a version.
- if (!sym->should_add_dynsym_entry())
+ if (!sym->should_add_dynsym_entry(this))
sym->set_dynsym_index(-1U);
else if (!sym->has_dynsym_index())
{
diff --git a/gold/symtab.h b/gold/symtab.h
index 1a81fd1..4a97461 100644
--- a/gold/symtab.h
+++ b/gold/symtab.h
@@ -274,7 +274,7 @@ class Symbol
// Return whether this symbol should be added to the dynamic symbol
// table.
bool
- should_add_dynsym_entry() const;
+ should_add_dynsym_entry(Symbol_table*) const;
// Return whether this symbol has been seen in a regular object.
bool
diff --git a/gold/target-reloc.h b/gold/target-reloc.h
index 510eea0..04854d2 100644
--- a/gold/target-reloc.h
+++ b/gold/target-reloc.h
@@ -83,7 +83,8 @@ scan_relocs(
shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
if (is_ordinary
&& shndx != elfcpp::SHN_UNDEF
- && !object->is_section_included(shndx))
+ && !object->is_section_included(shndx)
+ && !symtab->is_section_folded(object, shndx))
{
// RELOC is a relocation against a local symbol in a
// section we are discarding. We can ignore this
@@ -102,7 +103,6 @@ scan_relocs(
continue;
}
-
scan.local(symtab, layout, target, object, data_shndx,
output_section, reloc, r_type, lsym);
}
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 3bc0ec8..5b1c9a0 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -193,6 +193,33 @@ icf_safe_so_test_1.stdout: icf_safe_so_test
icf_safe_so_test_2.stdout: icf_safe_so_test
$(TEST_READELF) -h icf_safe_so_test > icf_safe_so_test_2.stdout
+check_SCRIPTS += icf_virtual_function_folding_test.sh
+MOSTLYCLEANFILES += icf_virtual_function_folding_test
+icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc
+ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIE -g -o $@ $<
+icf_virtual_function_folding_test: icf_virtual_function_folding_test.o gcctestdir/ld
+ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_virtual_function_folding_test.o -pie
+
+check_SCRIPTS += icf_preemptible_functions_test.sh
+check_DATA += icf_preemptible_functions_test.stdout
+MOSTLYCLEANFILES += icf_preemptible_functions_test
+icf_preemptible_functions_test.o: icf_preemptible_functions_test.cc
+ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $<
+icf_preemptible_functions_test: icf_preemptible_functions_test.o gcctestdir/ld
+ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_preemptible_functions_test.o -fPIC -shared
+icf_preemptible_functions_test.stdout: icf_preemptible_functions_test
+ $(TEST_NM) icf_preemptible_functions_test > icf_preemptible_functions_test.stdout
+
+check_SCRIPTS += icf_string_merge_test.sh
+check_DATA += icf_string_merge_test.stdout
+MOSTLYCLEANFILES += icf_string_merge_test
+icf_string_merge_test.o: icf_string_merge_test.cc
+ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $<
+icf_string_merge_test: icf_string_merge_test.o gcctestdir/ld
+ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_string_merge_test.o
+icf_string_merge_test.stdout: icf_string_merge_test
+ $(TEST_NM) icf_string_merge_test > icf_string_merge_test.stdout
+
check_PROGRAMS += basic_test
check_PROGRAMS += basic_static_test
check_PROGRAMS += basic_pic_test
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 2d4b018..5cb2eb5 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -62,6 +62,9 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.sh weak_plt.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg.sh undef_symbol.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_1.sh ver_test_2.sh \
@@ -91,6 +94,8 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test_2.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test_1.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test_2.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.dbg \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_plt_shared.so debug_msg.err \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg_so.err \
@@ -112,6 +117,9 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_orphan_section_test icf_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_keep_unique_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test icf_safe_so_test \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ two_file_shared.dbg \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/weak_undef_lib.so
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_4 = basic_test \
@@ -2554,6 +2562,22 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) icf_safe_so_test > icf_safe_so_test_1.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_safe_so_test_2.stdout: icf_safe_so_test
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -h icf_safe_so_test > icf_safe_so_test_2.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIE -g -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test: icf_virtual_function_folding_test.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_virtual_function_folding_test.o -pie
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_preemptible_functions_test.o: icf_preemptible_functions_test.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_preemptible_functions_test: icf_preemptible_functions_test.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_preemptible_functions_test.o -fPIC -shared
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_preemptible_functions_test.stdout: icf_preemptible_functions_test
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) icf_preemptible_functions_test > icf_preemptible_functions_test.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_string_merge_test.o: icf_string_merge_test.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIC -g -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_string_merge_test: icf_string_merge_test.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--icf=all icf_string_merge_test.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_string_merge_test.stdout: icf_string_merge_test
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) icf_string_merge_test > icf_string_merge_test.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@basic_test.o: basic_test.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@basic_test: basic_test.o gcctestdir/ld
diff --git a/gold/testsuite/icf_preemptible_functions_test.cc b/gold/testsuite/icf_preemptible_functions_test.cc
new file mode 100644
index 0000000..35a96bc
--- /dev/null
+++ b/gold/testsuite/icf_preemptible_functions_test.cc
@@ -0,0 +1,47 @@
+// icf_preemptible_functions_test.cc -- a test case for gold
+
+// Copyright 2010 Free Software Foundation, Inc.
+// Written by Sriraman Tallam <tmsriram@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// The goal of this program is to verify that preemptible functions are
+// correctly handled by ICF. In this program, foo and bar should not
+// be folded although they are identical as zap or zip could be preempted.
+
+int zap()
+{
+ return 0;
+}
+
+int zip()
+{
+ return 0;
+}
+
+int foo()
+{
+ zap();
+ return 0;
+}
+
+int bar()
+{
+ zip();
+ return 0;
+}
diff --git a/gold/testsuite/icf_preemptible_functions_test.sh b/gold/testsuite/icf_preemptible_functions_test.sh
new file mode 100755
index 0000000..27cf459
--- /dev/null
+++ b/gold/testsuite/icf_preemptible_functions_test.sh
@@ -0,0 +1,35 @@
+# icf_preemptible_functions_test.sh -- test --icf=all
+
+# Copyright 2010 Free Software Foundation, Inc.
+# Written by Sriraman Tallam <tmsriram@google.com>.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+
+check()
+{
+ func_addr_1=`grep $2 $1 | awk '{print $1}'`
+ func_addr_2=`grep $3 $1 | awk '{print $1}'`
+ if [ $func_addr_1 = $func_addr_2 ]
+ then
+ echo "Identical Code Folding should not fold" $2 "and" $3
+ exit 1
+ fi
+}
+
+check icf_preemptible_functions_test.stdout "_Z3foov" "_Z3barv"
diff --git a/gold/testsuite/icf_safe_so_test.sh b/gold/testsuite/icf_safe_so_test.sh
index 262daef..47ad390 100755
--- a/gold/testsuite/icf_safe_so_test.sh
+++ b/gold/testsuite/icf_safe_so_test.sh
@@ -27,8 +27,7 @@
error_if_symbol_absent()
{
- is_symbol_present $1 $2
- if [ $? != 0 ];
+ if ! is_symbol_present $1 $2;
then
echo "Symbol" $2 "not present, possibly folded."
exit 1
@@ -37,7 +36,7 @@ error_if_symbol_absent()
is_symbol_present()
{
- result=`grep $2 $1`
+ grep $2 $1 > /dev/null 2>&1
return $?
}
@@ -56,14 +55,12 @@ check_nofold()
check_fold()
{
- is_symbol_present $1 $2
- if [ $? != 0 ];
+ if ! is_symbol_present $1 $2
then
return 0
fi
- is_symbol_present $1 $3
- if [ $? != 0 ];
+ if ! is_symbol_present $1 $3
then
return 0
fi
@@ -89,13 +86,13 @@ arch_specific_safe_fold()
X86_32_specific_safe_fold()
{
- grep -q -e "Intel 80386" $1 >& /dev/null
+ grep -e "Intel 80386" $1 > /dev/null 2>&1
arch_specific_safe_fold $? $2 $3 $4
}
X86_64_specific_safe_fold()
{
- grep -q -e "Advanced Micro Devices X86-64" $1 >& /dev/null
+ grep -e "Advanced Micro Devices X86-64" $1 > /dev/null 2>&1
arch_specific_safe_fold $? $2 $3 $4
}
@@ -105,5 +102,4 @@ X86_32_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout "f
X86_32_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout "foo_hidden" "foo_internal"
X86_32_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout "foo_hidden" "foo_static"
X86_32_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout "foo_internal" "foo_static"
-X86_64_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout \
- "foo_glob" "bar_glob"
+check_nofold icf_safe_so_test_1.stdout "foo_glob" "bar_glob"
diff --git a/gold/testsuite/icf_string_merge_test.cc b/gold/testsuite/icf_string_merge_test.cc
new file mode 100644
index 0000000..b1e1191
--- /dev/null
+++ b/gold/testsuite/icf_string_merge_test.cc
@@ -0,0 +1,50 @@
+// icf_string_merge_test.cc -- a test case for gold
+
+// Copyright 2010 Free Software Foundation, Inc.
+// Written by Sriraman Tallam <tmsriram@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// The goal of this program is to verify is strings are handled correctly
+// by ICF. ICF inlines strings that can be merged. In some cases, the
+// addend of the relocation pointing to a string merge section must be
+// ignored. This program has no pair of identical functions that can be
+// folded. However, if the addend is not ignored then get2 and get3 will
+// become identical.
+
+const char* const str1 = "aaaaaaaaaastr1";
+const char* const str2 = "bbbbaaaaaastr1";
+const char* const str3 = "cccccaaaaastr1";
+
+const char* get1()
+{
+ return str1;
+}
+const char* get2()
+{
+ return str2;
+}
+
+const char* get3()
+{
+ return str3;
+}
+int main()
+{
+ return 0;
+}
diff --git a/gold/testsuite/icf_string_merge_test.sh b/gold/testsuite/icf_string_merge_test.sh
new file mode 100755
index 0000000..f22f212
--- /dev/null
+++ b/gold/testsuite/icf_string_merge_test.sh
@@ -0,0 +1,37 @@
+# icf_string_merge_test.sh -- test --icf=all
+
+# Copyright 2010 Free Software Foundation, Inc.
+# Written by Sriraman Tallam <tmsriram@google.com>.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+
+check()
+{
+ func_addr_1=`grep $2 $1 | awk '{print $1}'`
+ func_addr_2=`grep $3 $1 | awk '{print $1}'`
+ if [ $func_addr_1 = $func_addr_2 ]
+ then
+ echo "Identical Code Folding should not fold" $2 "and" $3
+ exit 1
+ fi
+}
+
+check icf_string_merge_test.stdout "get1" "get2"
+check icf_string_merge_test.stdout "get1" "get3"
+check icf_string_merge_test.stdout "get2" "get3"
diff --git a/gold/testsuite/icf_virtual_function_folding_test.cc b/gold/testsuite/icf_virtual_function_folding_test.cc
new file mode 100644
index 0000000..80f96ef
--- /dev/null
+++ b/gold/testsuite/icf_virtual_function_folding_test.cc
@@ -0,0 +1,74 @@
+// icf_virtual_function_folding_test.cc -- a test case for gold
+
+// Copyright 2010 Free Software Foundation, Inc.
+// Written by Sriraman Tallam <tmsriram@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// Foo::fn1 is folded into fn2 with ICF. Since this file is linked as a
+// position independent executable, a dynamic reloc is needed
+// for the virtual call fn1 entry in the vtable. This test makes sure
+// the call to Foo::fn1 works correctly after the folding.
+
+#include <stdio.h>
+
+int fn2(void *)
+{
+ printf("fn1==fn2\n");
+ return 0xA;
+}
+
+namespace
+{
+
+class Bar
+{
+ public:
+ virtual int fn1();
+};
+
+int Bar::fn1()
+{
+ return 123;
+}
+
+class Foo : public Bar
+{
+ virtual int fn1();
+};
+
+int Foo::fn1()
+{
+ printf("fn1==fn2\n");
+ return 0xA;
+}
+
+Bar* get()
+{
+ Bar *f = new Foo();
+ return f;
+}
+
+} // end of anonymous namespace.
+
+int main()
+{
+ Bar *f = get();
+ f->fn1();
+ return 0;
+}
diff --git a/gold/testsuite/icf_virtual_function_folding_test.sh b/gold/testsuite/icf_virtual_function_folding_test.sh
new file mode 100755
index 0000000..31c8339
--- /dev/null
+++ b/gold/testsuite/icf_virtual_function_folding_test.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+# icf_virtual_function_folding_test.sh -- test --icf
+
+# Copyright 2010 Free Software Foundation, Inc.
+# Written by Sriraman Tallam <tmsriram@google.com>.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+check()
+{
+ ./icf_virtual_function_folding_test | grep $1 > /dev/null 2>&1
+ if [ $? -gt 0 ]
+ then
+ echo "Program output incorrect after folding." $2
+ exit 1
+ fi
+}
+
+check "fn1==fn2"
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index e9dd5ae..9110278 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -1398,14 +1398,10 @@ Target_x86_64::Scan::unsupported_reloc_global(Sized_relobj<64, false>* object,
object->name().c_str(), r_type, gsym->demangled_name().c_str());
}
-// Returns true if this relocation type could be that of a function pointer
-// only if the target is not position-independent code.
+// Returns true if this relocation type could be that of a function pointer.
inline bool
Target_x86_64::Scan::possible_function_pointer_reloc(unsigned int r_type)
{
- if (parameters->options().shared())
- return false;
-
switch (r_type)
{
case elfcpp::R_X86_64_64:
@@ -1413,6 +1409,11 @@ Target_x86_64::Scan::possible_function_pointer_reloc(unsigned int r_type)
case elfcpp::R_X86_64_32S:
case elfcpp::R_X86_64_16:
case elfcpp::R_X86_64_8:
+ case elfcpp::R_X86_64_GOT64:
+ case elfcpp::R_X86_64_GOT32:
+ case elfcpp::R_X86_64_GOTPCREL64:
+ case elfcpp::R_X86_64_GOTPCREL:
+ case elfcpp::R_X86_64_GOTPLT64:
{
return true;
}