aboutsummaryrefslogtreecommitdiff
path: root/gold/gc.h
diff options
context:
space:
mode:
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())
{