+ typedef typename Reloc_types<sh_type, size, big_endian>::Reloc Reltype;
+ const int reloc_size = Reloc_types<sh_type, size, big_endian>::reloc_size;
+
+ size_t local_count = this->local_symbol_count();
+
+ std::vector<section_offset_type> non_split_refs;
+
+ const unsigned char* pr = prelocs;
+ for (size_t i = 0; i < reloc_count; ++i, pr += reloc_size)
+ {
+ // Some supported targets have a non-standard r_info field.
+ // If this call is too slow, we can move this routine to
+ // target-reloc.h and templatize it on Classify_reloc.
+ unsigned int r_sym = target->get_r_sym(pr);
+ if (r_sym < local_count)
+ continue;
+
+ const Symbol* gsym = this->global_symbol(r_sym);
+ gold_assert(gsym != NULL);
+ if (gsym->is_forwarder())
+ gsym = symtab->resolve_forwards(gsym);
+
+ // See if this relocation refers to a function defined in an
+ // object compiled without -fsplit-stack. Note that we don't
+ // care about the type of relocation--this means that in some
+ // cases we will ask for a large stack unnecessarily, but this
+ // is not fatal. FIXME: Some targets have symbols which are
+ // functions but are not type STT_FUNC, e.g., STT_ARM_TFUNC.
+ if (!gsym->is_undefined()
+ && gsym->source() == Symbol::FROM_OBJECT
+ && !gsym->object()->uses_split_stack())
+ {
+ if (parameters->target().is_call_to_non_split(gsym, pr, view,
+ view_size))
+ {
+ Reltype reloc(pr);
+ section_offset_type offset =
+ convert_to_section_size_type(reloc.get_r_offset());
+ non_split_refs.push_back(offset);
+ }
+ }
+ }
+
+ if (non_split_refs.empty())
+ return;
+
+ // At this point, every entry in NON_SPLIT_REFS indicates a
+ // relocation which refers to a function in an object compiled
+ // without -fsplit-stack. We now have to convert that list into a
+ // set of offsets to functions. First, we find all the functions.
+
+ Function_offsets function_offsets;
+ this->find_functions(pshdrs, shndx, &function_offsets);
+ if (function_offsets.empty())
+ return;
+
+ // Now get a list of the function with references to non split-stack
+ // code.
+
+ Function_offsets calls_non_split;
+ for (std::vector<section_offset_type>::const_iterator p
+ = non_split_refs.begin();
+ p != non_split_refs.end();
+ ++p)
+ {
+ Function_offsets::const_iterator low = function_offsets.lower_bound(*p);
+ if (low == function_offsets.end())
+ --low;
+ else if (low->first == *p)
+ ;
+ else if (low == function_offsets.begin())
+ continue;
+ else
+ --low;
+
+ calls_non_split.insert(*low);
+ }
+ if (calls_non_split.empty())
+ return;
+
+ // Now we have a set of functions to adjust. The adjustments are
+ // target specific. Besides changing the output section view
+ // however, it likes, the target may request a relocation change
+ // from one global symbol name to another.
+
+ for (Function_offsets::const_iterator p = calls_non_split.begin();
+ p != calls_non_split.end();
+ ++p)
+ {
+ std::string from;
+ std::string to;
+ parameters->target().calls_non_split(this, shndx, p->first, p->second,
+ prelocs, reloc_count,
+ view, view_size, &from, &to);
+ if (!from.empty())
+ {
+ gold_assert(!to.empty());
+ Symbol* tosym = NULL;
+
+ // Find relocations in the relevant function which are for
+ // FROM.
+ pr = prelocs;
+ for (size_t i = 0; i < reloc_count; ++i, pr += reloc_size)
+ {
+ Reltype reloc(pr);
+
+ unsigned int r_sym = target->get_r_sym(pr);
+ if (r_sym < local_count)
+ continue;
+
+ section_offset_type offset =
+ convert_to_section_size_type(reloc.get_r_offset());
+ if (offset < p->first
+ || (offset
+ >= (p->first
+ + static_cast<section_offset_type>(p->second))))
+ continue;
+
+ const Symbol* gsym = this->global_symbol(r_sym);
+ if (from == gsym->name())
+ {
+ if (tosym == NULL)
+ {
+ tosym = symtab->lookup(to.c_str());
+ if (tosym == NULL)
+ {
+ this->error(_("could not convert call "
+ "to '%s' to '%s'"),
+ from.c_str(), to.c_str());
+ break;
+ }
+ }
+
+ if (*reloc_map == NULL)
+ *reloc_map = new Reloc_symbol_changes(reloc_count);
+ (*reloc_map)->set(i, tosym);
+ }
+ }
+ }
+ }