This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/2] BFD: Use `bfd_is_abs_symbol' to determine whether a symbol is absolute


Use `bfd_is_abs_symbol' to determine whether a symbol is absolute, 
avoiding a problem with ordinary symbols defined in a linker script 
outside an output section definition.  Such symbols have its owning 
section set to the absolute section up to the final link phase.  A flag 
has been added to the link hash to identify such symbols.  Rather than 
checking the flag by hand, use the macro that does it uniformly for all 
users.

	bfd/
	* elf32-nds32.c (nds32_elf_relax_loadstore): Use 
	`bfd_is_abs_symbol' rather than `bfd_is_abs_section' in checking
	whether the symbol is absolute.
	(nds32_elf_relax_lo12): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	(elfNN_aarch64_check_relocs): Likewise.
	* xcofflink.c (xcoff_need_ldrel_p): Likewise.
	(bfd_xcoff_import_symbol): Likewise.
	(xcoff_write_global_symbol): Likewise.
---
Hi,

 I believe the `elfNN_aarch64_final_link_relocate' case may be redundant, 
as may `xcoff_write_global_symbol' as I'm fairly sure the symbol will have 
been converted by that time.  I think it may make sense to use the macro 
there regardless, for consistency, so that uniform code people see makes 
them sure that this is The Right Way, as the `rel_from_abs' stuff is IMHO 
quite obscure.

 The remaining cases are likely required, but target maintainer's input 
will help to tell whether that is really the case and, more importantly, 
whether backend code will still work correctly as I only verified 
surrounding code in the function affected and not places elsewhere that 
may be affected.  Stuff such as relocation calculation should work 
automagically, but target-specific special arrangements may not.

 Also having target-specific test cases for the paths affected would help 
and I have no resources right now to make them, as my time is very limited 
and I would have to study the architectures and binary formats affected.

 All places that wanted to examine the symbol section's BFD or the 
symbol's output section had of course to be excluded.  Such code may or 
may not be correct in the context of the symbols concerned and may have to 
be audited as it may be buggy regardless of these two changes proposed.

  Maciej
---
 bfd/elf32-nds32.c   |    4 ++--
 bfd/elfnn-aarch64.c |    6 ++----
 bfd/xcofflink.c     |    6 +++---
 3 files changed, 7 insertions(+), 9 deletions(-)

binutils-ld-rel-from-abs-update.diff
Index: binutils/bfd/elf32-nds32.c
===================================================================
--- binutils.orig/bfd/elf32-nds32.c	2018-07-15 00:18:04.818001488 +0100
+++ binutils/bfd/elf32-nds32.c	2018-07-15 00:18:29.781920994 +0100
@@ -10567,7 +10567,7 @@ nds32_elf_relax_loadstore (struct bfd_li
 
 	  /* This is avoid to relax symbol address which is fixed
 	     relocations.  Ex: _stack.  */
-	  if (h && bfd_is_abs_section (h->root.u.def.section))
+	  if (h && bfd_is_abs_symbol (&h->root))
 	    return FALSE;
 	}
 
@@ -10707,7 +10707,7 @@ nds32_elf_relax_lo12 (struct bfd_link_in
   /* This is avoid to relax symbol address which is fixed
      relocations.  Ex: _stack.  */
   else if (N32_OP6 (insn) == N32_OP6_ORI
-	   && h && bfd_is_abs_section (h->root.u.def.section))
+	   && h && bfd_is_abs_symbol (&h->root))
     return;
   else
     {
Index: binutils/bfd/elfnn-aarch64.c
===================================================================
--- binutils.orig/bfd/elfnn-aarch64.c	2018-07-15 00:18:04.828075364 +0100
+++ binutils/bfd/elfnn-aarch64.c	2018-07-15 00:18:29.794055010 +0100
@@ -5224,8 +5224,7 @@ elfNN_aarch64_final_link_relocate (reloc
 
   weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
 		  : bfd_is_und_section (sym_sec));
-  abs_symbol_p = (h !=NULL && h->root.type == bfd_link_hash_defined
-		  && bfd_is_abs_section (h->root.u.def.section));
+  abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root);
 
 
   /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
@@ -7363,8 +7362,7 @@ elfNN_aarch64_check_relocs (bfd *abfd, s
 	      if (h != NULL
 		  /* This is an absolute symbol.  It represents a value instead
 		     of an address.  */
-		  && ((h->root.type == bfd_link_hash_defined
-		       && bfd_is_abs_section (h->root.u.def.section))
+		  && (bfd_is_abs_symbol (&h->root)
 		      /* This is an undefined symbol.  */
 		      || h->root.type == bfd_link_hash_undefined))
 		break;
Index: binutils/bfd/xcofflink.c
===================================================================
--- binutils.orig/bfd/xcofflink.c	2018-07-15 00:18:04.843213432 +0100
+++ binutils/bfd/xcofflink.c	2018-07-15 00:18:29.809153342 +0100
@@ -2690,7 +2690,7 @@ xcoff_need_ldrel_p (struct bfd_link_info
       if (h != NULL
 	  && (h->root.type == bfd_link_hash_defined
 	      || h->root.type == bfd_link_hash_defweak)
-	  && bfd_is_abs_section (h->root.u.def.section))
+	  && bfd_is_abs_symbol (&h->root))
 	return FALSE;
 
       return TRUE;
@@ -3125,7 +3125,7 @@ bfd_xcoff_import_symbol (bfd *output_bfd
   if (val != (bfd_vma) -1)
     {
       if (h->root.type == bfd_link_hash_defined
-	  && (! bfd_is_abs_section (h->root.u.def.section)
+	  && (!bfd_is_abs_symbol (&h->root)
 	      || h->root.u.def.value != val))
 	(*info->callbacks->multiple_definition) (info, &h->root, output_bfd,
 						 bfd_abs_section_ptr, val);
@@ -5589,7 +5589,7 @@ xcoff_write_global_symbol (struct bfd_ha
 	    || h->root.type == bfd_link_hash_defweak)
 	   && h->smclas == XMC_XO)
     {
-      BFD_ASSERT (bfd_is_abs_section (h->root.u.def.section));
+      BFD_ASSERT (bfd_is_abs_symbol (&h->root));
       isym.n_value = h->root.u.def.value;
       isym.n_scnum = N_UNDEF;
       if (h->root.type == bfd_link_hash_defweak


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]