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]

Re: Remove magic treatment of toc symbols for powerpc ELF


On Wed, Mar 05, 2014 at 07:29:53PM +1030, Alan Modra wrote:
> The XCOFF assembler does some weird things with instructions like
> `lwz 9,sym(30'.  See the comment in md_apply_fix.  From an ELF
> perspective, it's weird even to magically select a TOC16 reloc
> when a symbol is in the TOC/GOT.  ELF assemblers generally use
> modifiers like @toc to select relocs, so remove this "feature"
> for ELF.  I believe this was to support gcc -m32 -mcall-aixdesc
> but that combination of gcc options has been broken for a long
> time.

It turns out that glibc's sysdeps/powerpc/powerpc64/start.S uses this
feature.  :-(

	* config/tc-ppc.c (ppc_is_toc_sym): Revert 2014-03-05.
	(md_assemble): Likewise.  Warn.

diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index 8609ce7..9f24f3f 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -2530,16 +2530,25 @@ parse_toc_entry (enum toc_size_qualifier *toc_kind)
 }
 #endif
 
-#ifdef OBJ_XCOFF
+#if defined (OBJ_XCOFF) || defined (OBJ_ELF)
 /* See whether a symbol is in the TOC section.  */
 
 static int
 ppc_is_toc_sym (symbolS *sym)
 {
+#ifdef OBJ_XCOFF
   return (symbol_get_tc (sym)->symbol_class == XMC_TC
 	  || symbol_get_tc (sym)->symbol_class == XMC_TC0);
-}
 #endif
+#ifdef OBJ_ELF
+  const char *sname = segment_name (S_GET_SEGMENT (sym));
+  if (ppc_obj64)
+    return strcmp (sname, ".toc") == 0;
+  else
+    return strcmp (sname, ".got") == 0;
+#endif
+}
+#endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
 
 
 #ifdef OBJ_ELF
@@ -3167,11 +3176,17 @@ md_assemble (char *str)
 		   && operand->shift == 0)
 	    {
 	      reloc = BFD_RELOC_16;
-#ifdef OBJ_XCOFF
+#if defined OBJ_XCOFF || defined OBJ_ELF
 	      /* Note: the symbol may be not yet defined.  */
 	      if ((operand->flags & PPC_OPERAND_PARENS) != 0
 		  && ppc_is_toc_sym (ex.X_add_symbol))
-		reloc = BFD_RELOC_PPC_TOC16;
+		{
+		  reloc = BFD_RELOC_PPC_TOC16;
+#ifdef OBJ_ELF
+		  as_warn (_("assuming %s on symbol"),
+			   ppc_obj64 ? "@toc" : "@xgot");
+#endif
+		}
 #endif
 	    }
 

-- 
Alan Modra
Australia Development Lab, IBM


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