- /* Only create stubs for final objects. */
- if (link_info.relocateable == false)
- {
- lang_input_statement_type *statement;
-
- /* Look at all the statements. */
- for (statement = (lang_input_statement_type *)file_chain.head;
- statement != NULL;
- statement = (lang_input_statement_type *)statement->next)
- {
- asection *section;
- bfd *abfd = statement->the_bfd;
-
- /* Look at all the sections attached to the bfd associated with
- the current statement. */
- for (section = abfd->sections;
- section != (asection *)NULL;
- section = section ->next)
- {
- int new_sym_cnt = 0;
- int i,j;
- asymbol *syms;
-
- /* Do the dirty work; an array of symbols for each new stub
- will be returned. */
- syms = hppa_look_for_stubs_in_section (stub_file->the_bfd,
- abfd,
- output_bfd,
- section,
- &new_sym_cnt,
- &link_info);
-
- if (new_sym_cnt > 0 && syms)
- {
- struct symbol_cache_entry **old_asymbols;
-
- old_asymbols = stub_file->asymbols;
-
- /* Allocate space for the updated symbols */
- stub_file->asymbols
- = xmalloc ((stub_file->symbol_count + new_sym_cnt)
- * sizeof(asymbol *));
- if (stub_file->asymbols == NULL)
- abort ();
-
- /* Copy the old symbols.
-
- FIXME. Shouldn't we free the space used by the old
- symbols here? Might there be dangling references
- made within hppa_look_for_stubs_in_section? */
- for (j = 0; j < stub_file->symbol_count; j++)
- stub_file->asymbols[j] = old_asymbols[j];
-
- /* Copy in the new symbols. */
- for (j = 0, i = stub_file->symbol_count;
- j < new_sym_cnt;
- j++, i++)
- stub_file->asymbols[i] = &syms[j];
-
- /* Finally, adjust the symbol count. */
- stub_file->symbol_count += new_sym_cnt;
- }
- }
- }
-
- /* Add a statement to get the linker stubs included in the output. */
- lang_add_wild (".hppa_linker_stubs",NULL);
-
- /* If stubs were added, then remove all the (now invalid) padding
- statements. */
- hppaelf_search_for_padding_statements (stat_ptr->head,
- &stat_ptr->head);
- }
-
- /* Size up the sections again. */
- lang_size_sections (stat_ptr->head, abs_output_section,
- &stat_ptr->head, 0, (bfd_vma) 0, false);
-
- /* FIXME: Do we need to redo the "assignments" too? */
+static asection *
+hppaelf_add_stub_section (const char *stub_sec_name, asection *input_section)
+{
+ asection *stub_sec;
+ flagword flags;
+ asection *output_section;
+ lang_output_section_statement_type *os;
+ struct hook_stub_info info;
+
+ flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
+ | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP);
+ stub_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
+ stub_sec_name, flags);
+ if (stub_sec == NULL)
+ goto err_ret;
+
+ output_section = input_section->output_section;
+ os = lang_output_section_get (output_section);
+
+ info.input_section = input_section;
+ lang_list_init (&info.add);
+ lang_add_section (&info.add, stub_sec, NULL, os);
+
+ if (info.add.head == NULL)
+ goto err_ret;
+
+ if (hook_in_stub (&info, &os->children.head))
+ return stub_sec;
+
+ err_ret:
+ einfo (_("%X%P: can not make stub section: %E\n"));
+ return NULL;