2002-01-16 06:52:38 +01:00
|
|
|
# This shell script emits a C file. -*- C -*-
|
2005-03-03 12:52:12 +01:00
|
|
|
# Copyright 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
2002-01-16 06:52:38 +01:00
|
|
|
#
|
|
|
|
# This file is part of GLD, the Gnu Linker.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2005-05-12 09:32:09 +02:00
|
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-01-16 06:52:38 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
# This file is sourced from elf32.em, and defines extra powerpc64-elf
|
|
|
|
# specific routines.
|
|
|
|
#
|
|
|
|
cat >>e${EMULATION_NAME}.c <<EOF
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
#include "ldctor.h"
|
2002-05-02 11:48:15 +02:00
|
|
|
#include "libbfd.h"
|
2004-01-09 06:36:30 +01:00
|
|
|
#include "elf-bfd.h"
|
2002-01-16 06:52:38 +01:00
|
|
|
#include "elf64-ppc.h"
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
/* Fake input file for stubs. */
|
|
|
|
static lang_input_statement_type *stub_file;
|
2003-07-10 02:38:19 +02:00
|
|
|
static int stub_added = 0;
|
2002-05-01 04:34:54 +02:00
|
|
|
|
2005-03-29 13:07:38 +02:00
|
|
|
/* Whether we need to call ppc_layout_sections_again. */
|
|
|
|
static int need_laying_out = 0;
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
/* Maximum size of a group of input sections that can be handled by
|
|
|
|
one stub section. A value of +/-1 indicates the bfd back-end
|
|
|
|
should use a suitable default size. */
|
|
|
|
static bfd_signed_vma group_size = 1;
|
|
|
|
|
2002-05-22 11:04:48 +02:00
|
|
|
/* Whether to add ".foo" entries for each "foo" in a version script. */
|
|
|
|
static int dotsyms = 1;
|
|
|
|
|
2003-02-09 05:36:44 +01:00
|
|
|
/* Whether to run tls optimization. */
|
2004-11-04 12:55:13 +01:00
|
|
|
static int no_tls_opt = 0;
|
|
|
|
|
|
|
|
/* Whether to run opd optimization. */
|
|
|
|
static int no_opd_opt = 0;
|
|
|
|
|
|
|
|
/* Whether to run toc optimization. */
|
|
|
|
static int no_toc_opt = 0;
|
2003-02-09 05:36:44 +01:00
|
|
|
|
2005-01-06 10:03:56 +01:00
|
|
|
/* Whether to allow multiple toc sections. */
|
|
|
|
static int no_multi_toc = 0;
|
|
|
|
|
2003-06-08 16:07:34 +02:00
|
|
|
/* Whether to emit symbols for stubs. */
|
|
|
|
static int emit_stub_syms = 0;
|
|
|
|
|
|
|
|
static asection *toc_section = 0;
|
|
|
|
|
2004-08-19 09:47:25 +02:00
|
|
|
/* Whether to canonicalize .opd so that there are no overlapping
|
|
|
|
.opd entries. */
|
|
|
|
static int non_overlapping_opd = 0;
|
2002-05-01 04:34:54 +02:00
|
|
|
|
|
|
|
/* This is called before the input files are opened. We create a new
|
|
|
|
fake input file to hold the stub sections. */
|
|
|
|
|
|
|
|
static void
|
2003-06-20 07:33:26 +02:00
|
|
|
ppc_create_output_section_statements (void)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
2003-02-17 23:49:24 +01:00
|
|
|
extern const bfd_target bfd_elf64_powerpc_vec;
|
|
|
|
extern const bfd_target bfd_elf64_powerpcle_vec;
|
|
|
|
|
|
|
|
if (link_info.hash->creator != &bfd_elf64_powerpc_vec
|
|
|
|
&& link_info.hash->creator != &bfd_elf64_powerpcle_vec)
|
|
|
|
return;
|
|
|
|
|
2004-03-22 23:58:04 +01:00
|
|
|
link_info.wrap_char = '.';
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
stub_file = lang_add_input_file ("linker stubs",
|
|
|
|
lang_input_file_is_fake_enum,
|
|
|
|
NULL);
|
|
|
|
stub_file->the_bfd = bfd_create ("linker stubs", output_bfd);
|
|
|
|
if (stub_file->the_bfd == NULL
|
|
|
|
|| !bfd_set_arch_mach (stub_file->the_bfd,
|
|
|
|
bfd_get_arch (output_bfd),
|
|
|
|
bfd_get_mach (output_bfd)))
|
|
|
|
{
|
2005-02-16 03:20:13 +01:00
|
|
|
einfo ("%F%P: can not create BFD %E\n");
|
2002-05-01 04:34:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-10 10:15:08 +01:00
|
|
|
stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
|
2002-05-01 04:34:54 +02:00
|
|
|
ldlang_add_file (stub_file);
|
2003-07-10 02:38:19 +02:00
|
|
|
ppc64_elf_init_stub_bfd (stub_file->the_bfd, &link_info);
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
|
|
|
|
2002-11-12 08:56:38 +01:00
|
|
|
static void
|
2003-06-20 07:33:26 +02:00
|
|
|
ppc_before_allocation (void)
|
2002-11-12 08:56:38 +01:00
|
|
|
{
|
2003-02-17 23:49:24 +01:00
|
|
|
if (stub_file != NULL)
|
2003-02-04 15:51:35 +01:00
|
|
|
{
|
2005-06-06 14:59:59 +02:00
|
|
|
if (!ppc64_elf_edit_opd (output_bfd, &link_info, no_opd_opt,
|
|
|
|
non_overlapping_opd))
|
2005-02-16 03:20:13 +01:00
|
|
|
einfo ("%X%P: can not edit %s %E\n", "opd");
|
2003-02-09 05:36:44 +01:00
|
|
|
|
2004-11-04 12:55:13 +01:00
|
|
|
if (ppc64_elf_tls_setup (output_bfd, &link_info) && !no_tls_opt)
|
2003-02-17 23:49:24 +01:00
|
|
|
{
|
|
|
|
/* Size the sections. This is premature, but we want to know the
|
|
|
|
TLS segment layout so that certain optimizations can be done. */
|
* ld.h (lang_phase_type): Move to..
* ldexp.h: ..here. Add lang_mark_phase_enum.
(node_type): Remove etree_undef and etree_unspec.
(exp_data_seg): Delete.
(struct ldexp_control, expld): New.
(invalid, exp_mark_used_section): Delete.
(exp_fold_tree, exp_get_vma, exp_get_value_int, exp_get_fill,
exp_get_abs_int): Update prototypes.
* ldexp.c (assigning_to_dot): Delete.
(expld): Define.
(make_abs): Operate directly on expld.result. Update all callers.
(new_abs): Likewise. Return void.
(new_rel_from_abs): Rename from new_rel_from_section.
(new_rel, new_rel_from_abs): Operate on expld.result and return void.
Update all callers.
(fold_unary): Operate on expld.result and return void. Remove
"current_section", "allocation_done", "dot", "dotp" and "mark_used"
params. Update all callers.
(fold_binary, fold_trinary, fold_name, exp_fold_tree_1): Likewise.
(fold_unary <ALIGN_K>): Ensure alignment is absolute.
(fold_unary <ABSOLUTE>): Use make_abs.
(fold_unary <DATA_SEGMENT_END>): Evaluate mark_phase as for
allocating_phase.
(fold_binary <DATA_SEGMENT_ALIGN, DATA_SEGMENT_RELRO_END, >): Ditto.
(fold_binary <'%','/'>): Don't error if marking.
(fold_name <SIZEOF_HEADERS>): Don't call bfd_sizeof_headers when
marking.
(fold_name <NAME>): Remove FIXME; -R is handled correctly. Don't
error when marking.
(fold_name <ADDR, LOADADDR, SIZEOF>): Don't set SEC_KEEP.
(exp_fold_tree_1): Don't error when marking.
(exp_fold_tree_1 <etree_rel>): Evaluate in all phases except first.
(exp_fold_tree_1 <etree_assign to dot>): Don't check for NULL
current section, instead check for NULL dotp.
(exp_fold_tree_1 <etree_provide>): Don't evaluate the assignment
source unless the symbol is referenced and undefined.
(exp_fold_tree): Remove "allocation_done" and "dot" params. Save
params to expld.
(exp_fold_tree_no_dot): Remove "current_section", "allocation_done
and "mark_used" params. Save params to expld. Update all callers.
(exp_assop): Do without temp var.
(exp_print_tree <etree_undef>): Delete code.
(exp_get_vma): Remove "allocation_done" param. Correct error return.
(exp_get_fill, exp_get_abs_int): Likewise.
(exp_get_value_int): Remove "allocation_done" param.
(exp_mark_used_section): Delete.
* ldgram.y (fill_exp): Update exp_get_fill call.
(origin_spec, length_spec): Update exp_get_vma call.
* ldlang.c (lang_init): Don't bother clearing lang_statement_iteration.
(lang_mark_used_section_1, lang_mark_used_section): Delete.
(strip_excluded_output_sections): Call one_lang_size_sections_pass in
marking mode. Merge old lang_mark_used_section code. Correct handling
of output sections with excluded input sections and data statements.
Don't drop non-zero sized sections. Don't zap os->bfd_section.
Do set SEC_EXCLUDE when appropriate.
(print_output_section_statement): Update for changed ldexp.c
interface.
(print_assignment, lang_size_sections_1): Likewise.
(lang_do_assignments_1, lang_enter_output_section_statement): Likewise.
(lang_new_phdr, lang_record_phdrs): Likewise.
(lang_size_sections): Likewise.
(insert_pad): Use following statement if it is a pad, rather than
creating a new one.
(lang_size_sections_1 <lang_output_section_statement_enum>): Do
process ignored output section to set vma and lma, but don't
update dot for these sections. Don't error if marking.
(lang_size_sections_1 <lang_assignment_statement_enum>): Don't
update dot for ignored sections.
(lang_size_sections_1 <lang_data_statement_enum>): Don't mark absolute
section with SEC_ALLOC.
(one_lang_size_sections_pass): New function.
(lang_size_sections): Remove first five params. Set expld.phase on
entry and exit. Use one_lang_size_sections_pass.
(lang_do_assignments): Remove all params. Update all callers.
(lang_reset_memory_regions): Clear os->processed for all output
section statements.
* ldlang.h (lang_do_assignments): Update prototype.
(lang_size_sections): Likewise.
(one_lang_size_sections_pass): Declare.
* pe-dll.c (pe_dll_fill_sections, pe_exe_fill_sections): Update
lang_size_sections and lang_do_assignments calls.
* emultempl/elf32.em (layout_sections_again): Likewise.
* emultempl/ppc64elf.em (ppc_before_allocation): Use
one_lang_size_sections_pass.
2005-06-09 04:05:47 +02:00
|
|
|
expld.phase = lang_mark_phase_enum;
|
|
|
|
expld.dataseg.phase = exp_dataseg_none;
|
|
|
|
one_lang_size_sections_pass (NULL, TRUE);
|
2003-02-17 23:49:24 +01:00
|
|
|
|
|
|
|
if (!ppc64_elf_tls_optimize (output_bfd, &link_info))
|
2005-02-16 03:20:13 +01:00
|
|
|
einfo ("%X%P: TLS problem %E\n");
|
2003-02-17 23:49:24 +01:00
|
|
|
|
2004-01-09 06:36:30 +01:00
|
|
|
/* We must not cache anything from the preliminary sizing. */
|
2003-02-17 23:49:24 +01:00
|
|
|
lang_reset_memory_regions ();
|
|
|
|
}
|
2004-11-04 12:55:13 +01:00
|
|
|
|
|
|
|
if (!no_toc_opt
|
|
|
|
&& !link_info.relocatable
|
|
|
|
&& !ppc64_elf_edit_toc (output_bfd, &link_info))
|
2005-02-16 03:20:13 +01:00
|
|
|
einfo ("%X%P: can not edit %s %E\n", "toc");
|
2003-02-04 15:51:35 +01:00
|
|
|
}
|
|
|
|
|
2002-11-12 08:56:38 +01:00
|
|
|
gld${EMULATION_NAME}_before_allocation ();
|
|
|
|
}
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
struct hook_stub_info
|
|
|
|
{
|
|
|
|
lang_statement_list_type add;
|
|
|
|
asection *input_section;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Traverse the linker tree to find the spot where the stub goes. */
|
|
|
|
|
2002-11-30 09:39:46 +01:00
|
|
|
static bfd_boolean
|
2003-06-20 07:33:26 +02:00
|
|
|
hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
|
|
|
lang_statement_union_type *l;
|
2002-11-30 09:39:46 +01:00
|
|
|
bfd_boolean ret;
|
2002-05-01 04:34:54 +02:00
|
|
|
|
|
|
|
for (; (l = *lp) != NULL; lp = &l->header.next)
|
|
|
|
{
|
|
|
|
switch (l->header.type)
|
|
|
|
{
|
|
|
|
case lang_constructors_statement_enum:
|
|
|
|
ret = hook_in_stub (info, &constructor_list.head);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lang_output_section_statement_enum:
|
|
|
|
ret = hook_in_stub (info,
|
|
|
|
&l->output_section_statement.children.head);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lang_wild_statement_enum:
|
|
|
|
ret = hook_in_stub (info, &l->wild_statement.children.head);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lang_group_statement_enum:
|
|
|
|
ret = hook_in_stub (info, &l->group_statement.children.head);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lang_input_section_enum:
|
|
|
|
if (l->input_section.section == info->input_section)
|
|
|
|
{
|
|
|
|
/* We've found our section. Insert the stub immediately
|
|
|
|
before its associated input section. */
|
|
|
|
*lp = info->add.head;
|
|
|
|
*(info->add.tail) = l;
|
2002-11-30 09:39:46 +01:00
|
|
|
return TRUE;
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lang_data_statement_enum:
|
|
|
|
case lang_reloc_statement_enum:
|
|
|
|
case lang_object_symbols_statement_enum:
|
|
|
|
case lang_output_statement_enum:
|
|
|
|
case lang_target_statement_enum:
|
|
|
|
case lang_input_statement_enum:
|
|
|
|
case lang_assignment_statement_enum:
|
|
|
|
case lang_padding_statement_enum:
|
|
|
|
case lang_address_statement_enum:
|
|
|
|
case lang_fill_statement_enum:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FAIL ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-11-30 09:39:46 +01:00
|
|
|
return FALSE;
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Call-back for ppc64_elf_size_stubs. */
|
|
|
|
|
|
|
|
/* Create a new stub section, and arrange for it to be linked
|
|
|
|
immediately before INPUT_SECTION. */
|
|
|
|
|
|
|
|
static asection *
|
2003-06-20 07:33:26 +02:00
|
|
|
ppc_add_stub_section (const char *stub_sec_name, asection *input_section)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
|
|
|
asection *stub_sec;
|
|
|
|
flagword flags;
|
|
|
|
asection *output_section;
|
|
|
|
const char *secname;
|
|
|
|
lang_output_section_statement_type *os;
|
|
|
|
struct hook_stub_info info;
|
|
|
|
|
|
|
|
stub_sec = bfd_make_section_anyway (stub_file->the_bfd, stub_sec_name);
|
|
|
|
if (stub_sec == NULL)
|
|
|
|
goto err_ret;
|
|
|
|
|
|
|
|
flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
|
2007-02-13 02:53:03 +01:00
|
|
|
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_KEEP);
|
2002-05-01 04:34:54 +02:00
|
|
|
if (!bfd_set_section_flags (stub_file->the_bfd, stub_sec, flags))
|
|
|
|
goto err_ret;
|
|
|
|
|
|
|
|
output_section = input_section->output_section;
|
|
|
|
secname = bfd_get_section_name (output_section->owner, output_section);
|
|
|
|
os = lang_output_section_find (secname);
|
|
|
|
|
|
|
|
info.input_section = input_section;
|
|
|
|
lang_list_init (&info.add);
|
2005-11-17 01:10:05 +01:00
|
|
|
lang_add_section (&info.add, stub_sec, os);
|
2002-05-01 04:34:54 +02:00
|
|
|
|
|
|
|
if (info.add.head == NULL)
|
|
|
|
goto err_ret;
|
|
|
|
|
2003-07-10 02:38:19 +02:00
|
|
|
stub_added = 1;
|
2002-05-01 04:34:54 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Another call-back for ppc64_elf_size_stubs. */
|
|
|
|
|
|
|
|
static void
|
2003-06-20 07:33:26 +02:00
|
|
|
ppc_layout_sections_again (void)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
|
|
|
/* If we have changed sizes of the stub sections, then we need
|
|
|
|
to recalculate all the section offsets. This may mean we need to
|
|
|
|
add even more stubs. */
|
2006-06-20 04:22:16 +02:00
|
|
|
gld${EMULATION_NAME}_map_segments (TRUE);
|
|
|
|
need_laying_out = -1;
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
|
|
|
|
2002-01-16 06:52:38 +01:00
|
|
|
|
|
|
|
/* Call the back-end function to set TOC base after we have placed all
|
|
|
|
the sections. */
|
|
|
|
static void
|
2003-06-20 07:33:26 +02:00
|
|
|
gld${EMULATION_NAME}_after_allocation (void)
|
2002-01-16 06:52:38 +01:00
|
|
|
{
|
2003-06-25 08:40:27 +02:00
|
|
|
if (!link_info.relocatable)
|
2002-05-02 11:48:15 +02:00
|
|
|
_bfd_set_gp_value (output_bfd, ppc64_elf_toc (output_bfd));
|
2002-01-16 06:52:38 +01:00
|
|
|
}
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
|
2003-06-08 16:07:34 +02:00
|
|
|
static void
|
2003-06-20 07:33:26 +02:00
|
|
|
build_toc_list (lang_statement_union_type *statement)
|
2003-06-08 16:07:34 +02:00
|
|
|
{
|
2005-11-17 01:10:05 +01:00
|
|
|
if (statement->header.type == lang_input_section_enum)
|
|
|
|
{
|
|
|
|
asection *i = statement->input_section.section;
|
|
|
|
|
|
|
|
if (!((lang_input_statement_type *) i->owner->usrdata)->just_syms_flag
|
|
|
|
&& (i->flags & SEC_EXCLUDE) == 0
|
|
|
|
&& i->output_section == toc_section)
|
|
|
|
ppc64_elf_next_toc_section (&link_info, i);
|
|
|
|
}
|
2003-06-08 16:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
static void
|
2003-06-20 07:33:26 +02:00
|
|
|
build_section_lists (lang_statement_union_type *statement)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
2005-11-17 01:10:05 +01:00
|
|
|
if (statement->header.type == lang_input_section_enum)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
2005-11-17 01:10:05 +01:00
|
|
|
asection *i = statement->input_section.section;
|
|
|
|
|
|
|
|
if (!((lang_input_statement_type *) i->owner->usrdata)->just_syms_flag
|
|
|
|
&& (i->flags & SEC_EXCLUDE) == 0
|
|
|
|
&& i->output_section != NULL
|
|
|
|
&& i->output_section->owner == output_bfd)
|
|
|
|
{
|
|
|
|
if (!ppc64_elf_next_input_section (&link_info, i))
|
|
|
|
einfo ("%X%P: can not size stub section: %E\n");
|
|
|
|
}
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-22 11:04:48 +02:00
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
/* Final emulation specific call. */
|
2002-01-16 06:52:38 +01:00
|
|
|
|
|
|
|
static void
|
2006-06-20 04:22:16 +02:00
|
|
|
gld${EMULATION_NAME}_finish (void)
|
2002-01-16 06:52:38 +01:00
|
|
|
{
|
2002-02-10 11:55:23 +01:00
|
|
|
/* e_entry on PowerPC64 points to the function descriptor for
|
|
|
|
_start. If _start is missing, default to the first function
|
|
|
|
descriptor in the .opd section. */
|
|
|
|
entry_section = ".opd";
|
|
|
|
|
2005-03-29 13:07:38 +02:00
|
|
|
/* bfd_elf_discard_info just plays with debugging sections,
|
|
|
|
ie. doesn't affect any code, so we can delay resizing the
|
|
|
|
sections. It's likely we'll resize everything in the process of
|
|
|
|
adding stubs. */
|
|
|
|
if (bfd_elf_discard_info (output_bfd, &link_info))
|
|
|
|
need_laying_out = 1;
|
|
|
|
|
2002-11-12 08:56:38 +01:00
|
|
|
/* If generating a relocatable output file, then we don't have any
|
|
|
|
stubs. */
|
2003-06-25 08:40:27 +02:00
|
|
|
if (stub_file != NULL && !link_info.relocatable)
|
2002-01-16 06:52:38 +01:00
|
|
|
{
|
2005-01-06 10:03:56 +01:00
|
|
|
int ret = ppc64_elf_setup_section_lists (output_bfd, &link_info,
|
|
|
|
no_multi_toc);
|
2005-02-16 03:20:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
einfo ("%X%P: can not size stub section: %E\n");
|
|
|
|
else if (ret > 0)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
2003-07-10 02:38:19 +02:00
|
|
|
toc_section = bfd_get_section_by_name (output_bfd, ".got");
|
2003-06-08 16:07:34 +02:00
|
|
|
if (toc_section != NULL)
|
|
|
|
lang_for_each_statement (build_toc_list);
|
|
|
|
|
|
|
|
ppc64_elf_reinit_toc (output_bfd, &link_info);
|
|
|
|
|
2002-11-12 08:56:38 +01:00
|
|
|
lang_for_each_statement (build_section_lists);
|
2002-05-01 04:34:54 +02:00
|
|
|
|
2002-11-12 08:56:38 +01:00
|
|
|
/* Call into the BFD backend to do the real work. */
|
|
|
|
if (!ppc64_elf_size_stubs (output_bfd,
|
|
|
|
&link_info,
|
|
|
|
group_size,
|
|
|
|
&ppc_add_stub_section,
|
|
|
|
&ppc_layout_sections_again))
|
2005-02-16 03:20:13 +01:00
|
|
|
einfo ("%X%P: can not size stub section: %E\n");
|
2002-01-16 06:52:38 +01:00
|
|
|
}
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
2002-01-16 06:52:38 +01:00
|
|
|
|
2006-06-20 04:22:16 +02:00
|
|
|
if (need_laying_out != -1)
|
|
|
|
gld${EMULATION_NAME}_map_segments (need_laying_out);
|
2005-03-29 13:07:38 +02:00
|
|
|
|
2004-08-09 08:48:37 +02:00
|
|
|
if (link_info.relocatable)
|
|
|
|
{
|
|
|
|
asection *toc = bfd_get_section_by_name (output_bfd, ".toc");
|
|
|
|
if (toc != NULL
|
|
|
|
&& bfd_section_size (output_bfd, toc) > 0x10000)
|
|
|
|
einfo ("%X%P: TOC section size exceeds 64k\n");
|
|
|
|
}
|
|
|
|
|
2003-07-10 02:38:19 +02:00
|
|
|
if (stub_added)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
2003-06-19 15:51:05 +02:00
|
|
|
char *msg = NULL;
|
|
|
|
char *line, *endline;
|
|
|
|
|
2004-09-27 01:42:30 +02:00
|
|
|
emit_stub_syms |= link_info.emitrelocations;
|
2003-06-19 15:51:05 +02:00
|
|
|
if (!ppc64_elf_build_stubs (emit_stub_syms, &link_info,
|
|
|
|
config.stats ? &msg : NULL))
|
2002-05-01 04:34:54 +02:00
|
|
|
einfo ("%X%P: can not build stubs: %E\n");
|
2003-06-19 15:51:05 +02:00
|
|
|
|
|
|
|
for (line = msg; line != NULL; line = endline)
|
|
|
|
{
|
|
|
|
endline = strchr (line, '\n');
|
|
|
|
if (endline != NULL)
|
|
|
|
*endline++ = '\0';
|
|
|
|
fprintf (stderr, "%s: %s\n", program_name, line);
|
|
|
|
}
|
|
|
|
if (msg != NULL)
|
|
|
|
free (msg);
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
2004-08-10 13:23:03 +02:00
|
|
|
|
|
|
|
ppc64_elf_restore_symbols (&link_info);
|
2005-08-04 03:19:10 +02:00
|
|
|
finish_default ();
|
2002-05-01 04:34:54 +02:00
|
|
|
}
|
2002-01-16 06:52:38 +01:00
|
|
|
|
2002-02-05 08:07:21 +01:00
|
|
|
|
2002-05-22 11:04:48 +02:00
|
|
|
/* Add a pattern matching ".foo" for every "foo" in a version script.
|
|
|
|
|
|
|
|
The reason for doing this is that many shared library version
|
|
|
|
scripts export a selected set of functions or data symbols, forcing
|
|
|
|
others local. eg.
|
|
|
|
|
|
|
|
. VERS_1 {
|
|
|
|
. global:
|
|
|
|
. this; that; some; thing;
|
|
|
|
. local:
|
|
|
|
. *;
|
|
|
|
. };
|
|
|
|
|
|
|
|
To make the above work for PowerPC64, we need to export ".this",
|
|
|
|
".that" and so on, otherwise only the function descriptor syms are
|
|
|
|
exported. Lack of an exported function code sym may cause a
|
|
|
|
definition to be pulled in from a static library. */
|
|
|
|
|
2003-06-20 07:33:26 +02:00
|
|
|
static struct bfd_elf_version_expr *
|
|
|
|
gld${EMULATION_NAME}_new_vers_pattern (struct bfd_elf_version_expr *entry)
|
2002-05-22 11:04:48 +02:00
|
|
|
{
|
|
|
|
struct bfd_elf_version_expr *dot_entry;
|
|
|
|
unsigned int len;
|
|
|
|
char *dot_pat;
|
|
|
|
|
2007-05-14 10:53:23 +02:00
|
|
|
if (!dotsyms
|
|
|
|
|| (entry->pattern != NULL
|
|
|
|
&& (entry->pattern[0] == '*' || entry->pattern[0] == '.')))
|
2002-05-22 11:04:48 +02:00
|
|
|
return entry;
|
|
|
|
|
2003-06-20 07:33:26 +02:00
|
|
|
dot_entry = xmalloc (sizeof *dot_entry);
|
2003-10-22 08:58:17 +02:00
|
|
|
*dot_entry = *entry;
|
2002-05-22 11:04:48 +02:00
|
|
|
dot_entry->next = entry;
|
2007-05-14 10:53:23 +02:00
|
|
|
if (entry->pattern != NULL)
|
|
|
|
{
|
|
|
|
len = strlen (entry->pattern) + 2;
|
|
|
|
dot_pat = xmalloc (len);
|
|
|
|
dot_pat[0] = '.';
|
|
|
|
memcpy (dot_pat + 1, entry->pattern, len - 1);
|
|
|
|
dot_entry->pattern = dot_pat;
|
|
|
|
}
|
2004-08-17 14:33:59 +02:00
|
|
|
if (entry->symbol != NULL)
|
|
|
|
{
|
|
|
|
len = strlen (entry->symbol) + 2;
|
|
|
|
dot_pat = xmalloc (len);
|
|
|
|
dot_pat[0] = '.';
|
|
|
|
memcpy (dot_pat + 1, entry->symbol, len - 1);
|
|
|
|
dot_entry->symbol = dot_pat;
|
|
|
|
}
|
2002-05-22 11:04:48 +02:00
|
|
|
return dot_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
/* Avoid processing the fake stub_file in vercheck, stat_needed and
|
|
|
|
check_needed routines. */
|
2002-01-16 06:52:38 +01:00
|
|
|
|
2003-06-20 07:33:26 +02:00
|
|
|
static void (*real_func) (lang_input_statement_type *);
|
2002-01-16 06:52:38 +01:00
|
|
|
|
2003-06-20 07:33:26 +02:00
|
|
|
static void ppc_for_each_input_file_wrapper (lang_input_statement_type *l)
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
|
|
|
if (l != stub_file)
|
|
|
|
(*real_func) (l);
|
2002-01-16 06:52:38 +01:00
|
|
|
}
|
2002-05-01 04:34:54 +02:00
|
|
|
|
|
|
|
static void
|
2003-06-20 07:33:26 +02:00
|
|
|
ppc_lang_for_each_input_file (void (*func) (lang_input_statement_type *))
|
2002-05-01 04:34:54 +02:00
|
|
|
{
|
|
|
|
real_func = func;
|
|
|
|
lang_for_each_input_file (&ppc_for_each_input_file_wrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lang_for_each_input_file ppc_lang_for_each_input_file
|
|
|
|
|
2002-01-16 06:52:38 +01:00
|
|
|
EOF
|
|
|
|
|
2007-03-26 13:10:44 +02:00
|
|
|
if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
|
|
|
|
cat >>e${EMULATION_NAME}.c <<EOF
|
|
|
|
/* Special handling for embedded SPU executables. */
|
|
|
|
extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
|
|
|
|
static bfd_boolean gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *);
|
|
|
|
|
|
|
|
static bfd_boolean
|
|
|
|
ppc64_recognized_file (lang_input_statement_type *entry)
|
|
|
|
{
|
|
|
|
if (embedded_spu_file (entry, "-m64"))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return gld${EMULATION_NAME}_load_symbols (entry);
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
LDEMUL_RECOGNIZED_FILE=ppc64_recognized_file
|
|
|
|
fi
|
|
|
|
|
2002-05-01 04:34:54 +02:00
|
|
|
# Define some shell vars to insert bits of code into the standard elf
|
|
|
|
# parse_args and list_options functions.
|
|
|
|
#
|
|
|
|
PARSE_AND_LIST_PROLOGUE='
|
|
|
|
#define OPTION_STUBGROUP_SIZE 301
|
2003-06-08 16:07:34 +02:00
|
|
|
#define OPTION_STUBSYMS (OPTION_STUBGROUP_SIZE + 1)
|
|
|
|
#define OPTION_DOTSYMS (OPTION_STUBSYMS + 1)
|
2002-05-22 11:04:48 +02:00
|
|
|
#define OPTION_NO_DOTSYMS (OPTION_DOTSYMS + 1)
|
2003-02-09 05:36:44 +01:00
|
|
|
#define OPTION_NO_TLS_OPT (OPTION_NO_DOTSYMS + 1)
|
2004-11-04 12:55:13 +01:00
|
|
|
#define OPTION_NO_OPD_OPT (OPTION_NO_TLS_OPT + 1)
|
|
|
|
#define OPTION_NO_TOC_OPT (OPTION_NO_OPD_OPT + 1)
|
2005-01-06 10:03:56 +01:00
|
|
|
#define OPTION_NO_MULTI_TOC (OPTION_NO_TOC_OPT + 1)
|
|
|
|
#define OPTION_NON_OVERLAPPING_OPD (OPTION_NO_MULTI_TOC + 1)
|
2002-05-01 04:34:54 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
PARSE_AND_LIST_LONGOPTS='
|
|
|
|
{ "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
|
2003-06-08 16:07:34 +02:00
|
|
|
{ "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
|
2002-05-22 11:04:48 +02:00
|
|
|
{ "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
|
|
|
|
{ "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
|
2003-02-09 05:36:44 +01:00
|
|
|
{ "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
|
2004-11-04 12:55:13 +01:00
|
|
|
{ "no-opd-optimize", no_argument, NULL, OPTION_NO_OPD_OPT },
|
|
|
|
{ "no-toc-optimize", no_argument, NULL, OPTION_NO_TOC_OPT },
|
2005-01-06 10:03:56 +01:00
|
|
|
{ "no-multi-toc", no_argument, NULL, OPTION_NO_MULTI_TOC },
|
2004-08-19 09:47:25 +02:00
|
|
|
{ "non-overlapping-opd", no_argument, NULL, OPTION_NON_OVERLAPPING_OPD },
|
2002-05-01 04:34:54 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
PARSE_AND_LIST_OPTIONS='
|
|
|
|
fprintf (file, _("\
|
|
|
|
--stub-group-size=N Maximum size of a group of input sections that can be\n\
|
|
|
|
handled by one stub section. A negative value\n\
|
|
|
|
locates all stubs before their branches (with a\n\
|
|
|
|
group size of -N), while a positive value allows\n\
|
|
|
|
two groups of input sections, one before, and one\n\
|
|
|
|
after each stub section. Values of +/-1 indicate\n\
|
|
|
|
the linker should choose suitable defaults.\n"
|
|
|
|
));
|
2002-05-22 11:04:48 +02:00
|
|
|
fprintf (file, _("\
|
2003-06-08 16:07:34 +02:00
|
|
|
--emit-stub-syms Label linker stubs with a symbol.\n"
|
|
|
|
));
|
|
|
|
fprintf (file, _("\
|
2002-05-22 11:04:48 +02:00
|
|
|
--dotsyms For every version pattern \"foo\" in a version script,\n\
|
|
|
|
add \".foo\" so that function code symbols are\n\
|
|
|
|
treated the same as function descriptor symbols.\n\
|
|
|
|
Defaults to on.\n"
|
|
|
|
));
|
|
|
|
fprintf (file, _("\
|
|
|
|
--no-dotsyms Don'\''t do anything special in version scripts.\n"
|
|
|
|
));
|
2003-02-09 05:36:44 +01:00
|
|
|
fprintf (file, _("\
|
|
|
|
--no-tls-optimize Don'\''t try to optimize TLS accesses.\n"
|
|
|
|
));
|
2004-08-19 09:47:25 +02:00
|
|
|
fprintf (file, _("\
|
2004-11-04 12:55:13 +01:00
|
|
|
--no-opd-optimize Don'\''t optimize the OPD section.\n"
|
|
|
|
));
|
|
|
|
fprintf (file, _("\
|
|
|
|
--no-toc-optimize Don'\''t optimize the TOC section.\n"
|
|
|
|
));
|
|
|
|
fprintf (file, _("\
|
2005-01-06 10:03:56 +01:00
|
|
|
--no-multi-toc Disallow automatic multiple toc sections.\n"
|
|
|
|
));
|
|
|
|
fprintf (file, _("\
|
2004-08-19 09:47:25 +02:00
|
|
|
--non-overlapping-opd Canonicalize .opd, so that there are no overlapping\n\
|
|
|
|
.opd entries.\n"
|
|
|
|
));
|
2002-05-01 04:34:54 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
PARSE_AND_LIST_ARGS_CASES='
|
|
|
|
case OPTION_STUBGROUP_SIZE:
|
|
|
|
{
|
|
|
|
const char *end;
|
|
|
|
group_size = bfd_scan_vma (optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
einfo (_("%P%F: invalid number `%s'\''\n"), optarg);
|
|
|
|
}
|
|
|
|
break;
|
2002-05-22 11:04:48 +02:00
|
|
|
|
2003-06-08 16:07:34 +02:00
|
|
|
case OPTION_STUBSYMS:
|
|
|
|
emit_stub_syms = 1;
|
|
|
|
break;
|
|
|
|
|
2002-05-22 11:04:48 +02:00
|
|
|
case OPTION_DOTSYMS:
|
2003-02-09 05:36:44 +01:00
|
|
|
dotsyms = 1;
|
2002-05-22 11:04:48 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_NO_DOTSYMS:
|
2003-02-09 05:36:44 +01:00
|
|
|
dotsyms = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_NO_TLS_OPT:
|
2004-11-04 12:55:13 +01:00
|
|
|
no_tls_opt = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_NO_OPD_OPT:
|
|
|
|
no_opd_opt = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_NO_TOC_OPT:
|
|
|
|
no_toc_opt = 1;
|
2002-05-22 11:04:48 +02:00
|
|
|
break;
|
2004-08-19 09:47:25 +02:00
|
|
|
|
2005-01-06 10:03:56 +01:00
|
|
|
case OPTION_NO_MULTI_TOC:
|
|
|
|
no_multi_toc = 1;
|
|
|
|
break;
|
|
|
|
|
2004-08-19 09:47:25 +02:00
|
|
|
case OPTION_NON_OVERLAPPING_OPD:
|
|
|
|
non_overlapping_opd = 1;
|
|
|
|
break;
|
2002-05-01 04:34:54 +02:00
|
|
|
'
|
|
|
|
|
2002-01-16 06:52:38 +01:00
|
|
|
# Put these extra ppc64elf routines in ld_${EMULATION_NAME}_emulation
|
|
|
|
#
|
2002-11-12 08:56:38 +01:00
|
|
|
LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
|
2002-01-16 06:52:38 +01:00
|
|
|
LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
|
2006-06-20 04:22:16 +02:00
|
|
|
LDEMUL_FINISH=gld${EMULATION_NAME}_finish
|
2002-05-01 04:34:54 +02:00
|
|
|
LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_create_output_section_statements
|
2002-05-22 11:04:48 +02:00
|
|
|
LDEMUL_NEW_VERS_PATTERN=gld${EMULATION_NAME}_new_vers_pattern
|