// icf.cc -- Identical Code Folding.
//
-// Copyright 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Sriraman Tallam <tmsriram@google.com>.
// This file is part of gold.
for (; it_v != v.end(); ++it_v, ++it_s, ++it_a, ++it_o, ++it_addend_size)
{
+ if (first_iteration
+ && it_v->first != NULL)
+ {
+ Symbol_location loc;
+ loc.object = it_v->first;
+ loc.shndx = it_v->second;
+ loc.offset = convert_types<off_t, long long>(it_a->first
+ + it_a->second);
+ // Look through function descriptors
+ parameters->target().function_location(&loc);
+ if (loc.shndx != it_v->second)
+ {
+ it_v->second = loc.shndx;
+ // Modify symvalue/addend to the code entry.
+ it_a->first = loc.offset;
+ it_a->second = 0;
+ }
+ }
+
// ADDEND_STR stores the symbol value and addend and offset,
// each at most 16 hex digits long. it_a points to a pair
// where first is the symbol value and second is the
// This reloc points to a merge section. Hash the
// contents of this section.
if ((secn_flags & elfcpp::SHF_MERGE) != 0
- && parameters->target().can_icf_inline_merge_sections ())
+ && parameters->target().can_icf_inline_merge_sections())
{
uint64_t entsize =
(it_v->first)->section_entsize(it_v->second);
}
// During safe icf (--icf=safe), only fold functions that are ctors or dtors.
-// This function returns true if the mangled function name is a ctor or a
-// dtor.
+// This function returns true if the section name is that of a ctor or a dtor.
static bool
-is_function_ctor_or_dtor(const char* mangled_func_name)
+is_function_ctor_or_dtor(const std::string& section_name)
{
- if ((is_prefix_of("_ZN", mangled_func_name)
- || is_prefix_of("_ZZ", mangled_func_name))
- && (is_gnu_v3_mangled_ctor(mangled_func_name)
- || is_gnu_v3_mangled_dtor(mangled_func_name)))
+ const char* mangled_func_name = strrchr(section_name.c_str(), '.');
+ gold_assert(mangled_func_name != NULL);
+ if ((is_prefix_of("._ZN", mangled_func_name)
+ || is_prefix_of("._ZZ", mangled_func_name))
+ && (is_gnu_v3_mangled_ctor(mangled_func_name + 1)
+ || is_gnu_v3_mangled_dtor(mangled_func_name + 1)))
{
return true;
}
for (unsigned int i = 0;i < (*p)->shnum(); ++i)
{
- const char* section_name = (*p)->section_name(i).c_str();
+ const std::string section_name = (*p)->section_name(i);
if (!is_section_foldable_candidate(section_name))
continue;
if (!(*p)->is_section_included(i))
if (parameters->options().gc_sections()
&& symtab->gc()->is_section_garbage(*p, i))
continue;
- const char* mangled_func_name = strrchr(section_name, '.');
- gold_assert(mangled_func_name != NULL);
// With --icf=safe, check if the mangled function name is a ctor
// or a dtor. The mangled function name can be obtained from the
// section name by stripping the section prefix.
if (parameters->options().icf_safe_folding()
- && !is_function_ctor_or_dtor(mangled_func_name + 1)
+ && !is_function_ctor_or_dtor(section_name)
&& (!target.can_check_for_function_pointers()
|| section_has_function_pointers(*p, i)))
{