From 168706ddf9cdf51463ca7e94065d0d1d9f49253b Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Tue, 2 Jun 2009 18:51:33 +0000 Subject: [PATCH] bfd/ * coff-rs6000.c (xcoff_ppc_relocate_section): Allow undefined symbols to be left unimported when linking statically. * xcofflink.c (xcoff_link_add_symbols): Ignore global linkage code when linking statically. ld/testsuite/ * ld-powerpc/aix-glink-3.s, ld-powerpc/aix-glink-3a.s, ld-powerpc/aix-glink-3b.s, ld-powerpc/aix-glink-3.dd, ld-powerpc/aix-glink-3-32.d, ld-powerpc/aix-glink-3-64.d: New tests. * ld-powerpc/aix52.exp: Run them. Move the lineno tests to maintain alphabetical order. --- bfd/ChangeLog | 7 +++++++ bfd/coff-rs6000.c | 2 ++ bfd/xcofflink.c | 39 +++++++++++++++++++-------------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 77f080c927..b43f595ca0 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2009-06-02 Richard Sandiford + + * coff-rs6000.c (xcoff_ppc_relocate_section): Allow undefined + symbols to be left unimported when linking statically. + * xcofflink.c (xcoff_link_add_symbols): Ignore global linkage + code when linking statically. + 2009-06-02 H.J. Lu * elf32-i386.c (elf_i386_check_relocs): Increment diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index 4859f31b2b..d1931538c1 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c @@ -3460,6 +3460,8 @@ xcoff_ppc_relocate_section (output_bfd, info, input_bfd, else { BFD_ASSERT (info->relocatable + || (info->static_link + && (h->flags & XCOFF_WAS_UNDEFINED) != 0) || (h->flags & XCOFF_DEF_DYNAMIC) != 0 || (h->flags & XCOFF_IMPORT) != 0); } diff --git a/bfd/xcofflink.c b/bfd/xcofflink.c index 896292b393..1c2d0cbc23 100644 --- a/bfd/xcofflink.c +++ b/bfd/xcofflink.c @@ -1889,6 +1889,15 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info) || sym._n._n_n._n_offset == 0) copy = TRUE; + /* Ignore global linkage code when linking statically. */ + if (info->static_link + && (smtyp == XTY_SD || smtyp == XTY_LD) + && aux.x_csect.x_smclas == XMC_GL) + { + section = bfd_und_section_ptr; + value = 0; + } + /* The AIX linker appears to only detect multiple symbol definitions when there is a reference to the symbol. If a symbol is defined multiple times, and the only @@ -1913,8 +1922,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info) We also have to handle the case of statically linking a shared object, which will cause symbol redefinitions, although this is an easier case to detect. */ - - if (info->output_bfd->xvec == abfd->xvec) + else if (info->output_bfd->xvec == abfd->xvec) { if (! bfd_is_und_section (section)) *sym_hash = xcoff_link_hash_lookup (xcoff_hash_table (info), @@ -1934,23 +1942,8 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info) && ! bfd_is_com_section (section)) { /* This is a second definition of a defined symbol. */ - if ((abfd->flags & DYNAMIC) != 0 - && ((*sym_hash)->smclas != XMC_GL - || aux.x_csect.x_smclas == XMC_GL - || ((*sym_hash)->root.u.def.section->owner->flags - & DYNAMIC) == 0)) - { - /* The new symbol is from a shared library, and - either the existing symbol is not global - linkage code or this symbol is global linkage - code. If the existing symbol is global - linkage code and the new symbol is not, then - we want to use the new symbol. */ - section = bfd_und_section_ptr; - value = 0; - } - else if (((*sym_hash)->flags & XCOFF_DEF_REGULAR) == 0 - && ((*sym_hash)->flags & XCOFF_DEF_DYNAMIC) != 0) + if (((*sym_hash)->flags & XCOFF_DEF_REGULAR) == 0 + && ((*sym_hash)->flags & XCOFF_DEF_DYNAMIC) != 0) { /* The existing symbol is from a shared library. Replace it. */ @@ -2049,7 +2042,9 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info) { int flag; - if (smtyp == XTY_ER || smtyp == XTY_CM) + if (smtyp == XTY_ER + || smtyp == XTY_CM + || section == bfd_und_section_ptr) flag = XCOFF_REF_REGULAR; else flag = XCOFF_DEF_REGULAR; @@ -2741,6 +2736,10 @@ xcoff_mark_symbol (struct bfd_link_info *info, struct xcoff_link_hash_entry *h) /* We handle writing out the contents of the descriptor in xcoff_write_global_symbol. */ } + else if (info->static_link) + /* We can't get a symbol value dynamically, so just assume + that it's undefined. */ + h->flags |= XCOFF_WAS_UNDEFINED; else if ((h->flags & XCOFF_CALLED) != 0) { /* This is a function symbol for which we need to create -- 2.11.0