|
| 1 | +diff --git a/bfd/cofflink.c b/bfd/cofflink.c |
| 2 | +index 8d98fec..8f76b4d 100644 |
| 3 | +--- a/bfd/cofflink.c |
| 4 | ++++ b/bfd/cofflink.c |
| 5 | +@@ -426,7 +426,7 @@ coff_link_add_symbols (bfd *abfd, |
| 6 | + if (((*sym_hash)->symbol_class == C_NULL |
| 7 | + && (*sym_hash)->type == T_NULL) |
| 8 | + || sym.n_scnum != 0 |
| 9 | +- || (sym.n_value != 0 |
| 10 | ++ || ((sym.n_value != 0 || IS_WEAK_EXTERNAL(abfd, sym)) |
| 11 | + && (*sym_hash)->root.type != bfd_link_hash_defined |
| 12 | + && (*sym_hash)->root.type != bfd_link_hash_defweak)) |
| 13 | + { |
| 14 | +@@ -2890,6 +2890,37 @@ _bfd_coff_reloc_link_order (bfd *output_bfd, |
| 15 | + return TRUE; |
| 16 | + } |
| 17 | + |
| 18 | ++/* See _Microsoft Portable Executable and Common Object File Format |
| 19 | ++ Specification_, section 5.5.3. Note that weak symbols without aux records |
| 20 | ++ are a GNU extension. |
| 21 | ++ |
| 22 | ++ FIXME: All weak externals are treated as having characteristic |
| 23 | ++ IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY (1). These behave as per SVR4 ABI: A |
| 24 | ++ library member will resolve a weak external only if a normal external causes |
| 25 | ++ the library member to be linked. See also linker.c: |
| 26 | ++ generic_link_check_archive_element. */ |
| 27 | ++ |
| 28 | ++static void _bfd_coff_relocate_weak_externals(struct coff_link_hash_entry *h, |
| 29 | ++ bfd_vma *val, asection **sec) |
| 30 | ++{ |
| 31 | ++ long aux_index = h->aux->x_sym.x_tagndx.l; |
| 32 | ++ struct coff_tdata *cdata = h->auxbfd->tdata.coff_obj_data; |
| 33 | ++ struct coff_link_hash_entry *h2 = cdata->sym_hashes[aux_index]; |
| 34 | ++ |
| 35 | ++ if (!h2 || h2->root.type == bfd_link_hash_undefined) |
| 36 | ++ { |
| 37 | ++ *sec = bfd_abs_section_ptr; |
| 38 | ++ *val = 0; |
| 39 | ++ } |
| 40 | ++ else |
| 41 | ++ { |
| 42 | ++ *sec = h2->root.u.def.section; |
| 43 | ++ *val = h2->root.u.def.value + (*sec)->output_section->vma + |
| 44 | ++ (*sec)->output_offset; |
| 45 | ++ } |
| 46 | ++} |
| 47 | ++ |
| 48 | ++ |
| 49 | + /* A basic reloc handling routine which may be used by processors with |
| 50 | + simple relocs. */ |
| 51 | + |
| 52 | +@@ -2999,38 +3030,14 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd, |
| 53 | + else if (h->root.type == bfd_link_hash_undefweak) |
| 54 | + { |
| 55 | + if (h->symbol_class == C_NT_WEAK && h->numaux == 1) |
| 56 | +- { |
| 57 | +- /* See _Microsoft Portable Executable and Common Object |
| 58 | +- File Format Specification_, section 5.5.3. |
| 59 | +- Note that weak symbols without aux records are a GNU |
| 60 | +- extension. |
| 61 | +- FIXME: All weak externals are treated as having |
| 62 | +- characteristic IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY (1). |
| 63 | +- These behave as per SVR4 ABI: A library member |
| 64 | +- will resolve a weak external only if a normal |
| 65 | +- external causes the library member to be linked. |
| 66 | +- See also linker.c: generic_link_check_archive_element. */ |
| 67 | +- struct coff_link_hash_entry *h2 = |
| 68 | +- h->auxbfd->tdata.coff_obj_data->sym_hashes[ |
| 69 | +- h->aux->x_sym.x_tagndx.l]; |
| 70 | +- |
| 71 | +- if (!h2 || h2->root.type == bfd_link_hash_undefined) |
| 72 | +- { |
| 73 | +- sec = bfd_abs_section_ptr; |
| 74 | +- val = 0; |
| 75 | +- } |
| 76 | +- else |
| 77 | +- { |
| 78 | +- sec = h2->root.u.def.section; |
| 79 | +- val = h2->root.u.def.value |
| 80 | +- + sec->output_section->vma + sec->output_offset; |
| 81 | +- } |
| 82 | +- } |
| 83 | ++ _bfd_coff_relocate_weak_externals(h, &val, &sec); |
| 84 | + else |
| 85 | + /* This is a GNU extension. */ |
| 86 | + val = 0; |
| 87 | + } |
| 88 | +- |
| 89 | ++ else if (h->root.type == bfd_link_hash_undefined && |
| 90 | ++ h->symbol_class == C_NT_WEAK && h->numaux == 1) |
| 91 | ++ _bfd_coff_relocate_weak_externals(h, &val, &sec); |
| 92 | + else if (! bfd_link_relocatable (info)) |
| 93 | + { |
| 94 | + if (! ((*info->callbacks->undefined_symbol) |
| 95 | +-- |
| 96 | +2.1.0 |
0 commit comments