aboutsummaryrefslogtreecommitdiff
path: root/gold/gc.h
diff options
context:
space:
mode:
authorSriraman Tallam <tmsriram@google.com>2010-02-13 02:04:21 +0000
committerSriraman Tallam <tmsriram@google.com>2010-02-13 02:04:21 +0000
commit21bb3914d64c5fb946423572fe895d2a08531030 (patch)
treee54ee31d83ccdcab0f5d392c6e1d1a683809b98d /gold/gc.h
parent6076632b700e20fbb180fd582ed892ed3d0c2d91 (diff)
downloadfsf-binutils-gdb-21bb3914d64c5fb946423572fe895d2a08531030.zip
fsf-binutils-gdb-21bb3914d64c5fb946423572fe895d2a08531030.tar.gz
fsf-binutils-gdb-21bb3914d64c5fb946423572fe895d2a08531030.tar.bz2
2010-02-12 Sriraman Tallam <tmsriram@google.com>
* arm.cc (Scan::local_reloc_may_be_function_pointer): New function. (Scan::global_reloc_may_be_function_pointer): New function. * sparc.cc (Scan::local_reloc_may_be_function_pointer): New function. (Scan::global_reloc_may_be_function_pointer): New function. * powerpc.cc (Scan::local_reloc_may_be_function_pointer): New function. (Scan::global_reloc_may_be_function_pointer): New function. * i386.cc (Scan::local_reloc_may_be_function_pointer): New function. (Scan::global_reloc_may_be_function_pointer): New function. * x86_64.cc (Scan::local_reloc_may_be_function_pointer): New function. (Scan::global_reloc_may_be_function_pointer): New function. (Scan::possible_function_pointer_reloc): New function. (Target_x86_64::can_check_for_function_pointers): New function. * gc.h (gc_process_relocs): Scan relocation types to determine if function pointers were taken for targets that support it. * icf.cc (Icf::find_identical_sections): Include functions for folding in safe ICF whose pointer is not taken. * icf.h (Secn_fptr_taken_set): New typedef. (fptr_section_id_): New member. (section_has_function_pointers): New function. (set_section_has_function_pointers): New function. (check_section_for_function_pointers): New function. * options.h: Fix comment for safe ICF option. * target.h (can_check_for_function_pointers): New function. * testsuite/Makefile.am: Add icf_safe_so_test test case. Modify icf_safe_test for X86-64. * testsuite/Makefile.in: Regenerate. * testsuite/icf_safe_so_test.cc: New file. * testsuite/icf_safe_so_test.sh: New file. * testsuite/icf_safe_test.cc (kept_func_3): New function. (main): Change to take pointer to function kept_func_3. * testsuite/icf_safe_test.sh (arch_specific_safe_fold): Check if safe folding is done correctly for X86-64.
Diffstat (limited to 'gold/gc.h')
-rw-r--r--gold/gc.h46
1 files changed, 41 insertions, 5 deletions
diff --git a/gold/gc.h b/gold/gc.h
index 1ffb590..d4fd02e 100644
--- a/gold/gc.h
+++ b/gold/gc.h
@@ -163,18 +163,19 @@ inline void
gc_process_relocs(
Symbol_table* symtab,
Layout*,
- Target_type* ,
+ Target_type* target,
Sized_relobj<size, big_endian>* src_obj,
unsigned int src_indx,
const unsigned char* prelocs,
size_t reloc_count,
Output_section*,
- bool ,
+ bool,
size_t local_count,
const unsigned char* plocal_syms)
{
Object *dst_obj;
unsigned int dst_indx;
+ Scan scan;
typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
@@ -186,8 +187,14 @@ gc_process_relocs(
bool is_icf_tracked = false;
const char* cident_section_name = NULL;
+ std::string src_section_name = (parameters->options().icf_enabled()
+ ? src_obj->section_name(src_indx)
+ : "");
+
+ bool check_section_for_function_pointers = false;
+
if (parameters->options().icf_enabled()
- && is_section_foldable_candidate(src_obj->section_name(src_indx).c_str()))
+ && is_section_foldable_candidate(src_section_name.c_str()))
{
is_icf_tracked = true;
Section_id src_id(src_obj, src_indx);
@@ -196,11 +203,16 @@ gc_process_relocs(
addendvec = &symtab->icf()->addend_reloc_list()[src_id];
}
+ check_section_for_function_pointers =
+ symtab->icf()->check_section_for_function_pointers(src_section_name,
+ target);
+
for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
{
Reltype reloc(prelocs);
typename elfcpp::Elf_types<size>::Elf_WXword r_info = reloc.get_r_info();
unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
+ unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
typename elfcpp::Elf_types<size>::Elf_Swxword addend =
Reloc_types<sh_type, size, big_endian>::get_reloc_addend_noerror(&reloc);
@@ -225,6 +237,18 @@ gc_process_relocs(
(*addendvec).push_back(std::make_pair(symvalue,
static_cast<long long>(addend)));
}
+
+ // When doing safe folding, check to see if this relocation is that
+ // of a function pointer being taken.
+ if (check_section_for_function_pointers
+ && lsym.get_st_type() != elfcpp::STT_OBJECT
+ && scan.local_reloc_may_be_function_pointer(symtab, NULL, NULL,
+ src_obj, src_indx,
+ NULL, reloc, r_type,
+ lsym))
+ symtab->icf()->set_section_has_function_pointers(
+ src_obj, lsym.get_st_shndx());
+
if (shndx == src_indx)
continue;
}
@@ -239,9 +263,21 @@ gc_process_relocs(
bool is_ordinary;
dst_obj = gsym->object();
dst_indx = gsym->shndx(&is_ordinary);
+ Section_id dst_id(dst_obj, dst_indx);
+
+ // When doing safe folding, check to see if this relocation is that
+ // of a function pointer being taken.
+ if (check_section_for_function_pointers
+ && gsym->type() != elfcpp::STT_OBJECT
+ && (!is_ordinary
+ || scan.global_reloc_may_be_function_pointer(
+ symtab, NULL, NULL, src_obj, src_indx, NULL, reloc,
+ r_type, gsym)))
+ symtab->icf()->set_section_has_function_pointers(dst_obj, dst_indx);
+
if (!is_ordinary)
continue;
- Section_id dst_id(dst_obj, dst_indx);
+
// If the symbol name matches '__start_XXX' then the section with
// the C identifier like name 'XXX' should not be garbage collected.
// A similar treatment to symbols with the name '__stop_XXX'.
@@ -265,7 +301,7 @@ gc_process_relocs(
static_cast<long long>(sized_gsym->value());
(*addendvec).push_back(std::make_pair(symvalue,
static_cast<long long>(addend)));
- }
+ }
}
if (parameters->options().gc_sections())
{