[v2,3/3] Support relocation for weak references

Message ID VI2PR83MB0718F20F685EDC4B23F9AF5FF8272@VI2PR83MB0718.EURPRD83.prod.outlook.com
State New
Headers
Series aarch64: Relocation fixes and LTO |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Evgeny Karpov Nov. 18, 2024, 11:16 a.m. UTC
  This patch adds handling weak referencies in similar way how it is
done in _bfd_coff_generic_relocate_section.

bfd/ChangeLog:

	* coff-aarch64.c (coff_pe_aarch64_relocate_section): Support
	weak references.
---
 bfd/coff-aarch64.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
  

Patch

diff --git a/bfd/coff-aarch64.c b/bfd/coff-aarch64.c
index 84af335b3a0..23b1e7da37f 100644
--- a/bfd/coff-aarch64.c
+++ b/bfd/coff-aarch64.c
@@ -522,11 +522,30 @@  coff_pe_aarch64_relocate_section (bfd *output_bfd,
 
       h = obj_coff_sym_hashes (input_bfd)[symndx];
 
-      if (h && h->root.type == bfd_link_hash_defined)
+      if (h && (h->root.type == bfd_link_hash_defined
+	|| h->root.type == bfd_link_hash_defweak))
 	{
 	  sec = h->root.u.def.section;
 	  sym_value = h->root.u.def.value;
 	}
+      else if (h && h->root.type == bfd_link_hash_undefweak
+	&& h->symbol_class == C_NT_WEAK && h->numaux == 1)
+	{
+	  struct coff_link_hash_entry *h2;
+	  h2 = h->auxbfd->tdata.coff_obj_data->sym_hashes
+	       [h->aux->x_sym.x_tagndx.u32];
+
+	  if (!h2 || h2->root.type == bfd_link_hash_undefined)
+	  {
+	    sec = bfd_abs_section_ptr;
+	    sym_value = 0;
+	  }
+	  else
+	  {
+	    sec = h2->root.u.def.section;
+	    sym_value = h2->root.u.def.value;
+	  }
+	}
       else
 	{
 	  sec = sections[symndx];