public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PowerPC64 toc edit fail
@ 2011-08-19  8:07 Alan Modra
  2011-08-22 15:41 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2011-08-19  8:07 UTC (permalink / raw)
  To: binutils

When looking over .toc entries for ones from gcc's -mcmodel=medium or
-mcmodel=large code that can be deleted when ld optimizes the code, ld
first marked the entries with a flag then later reset the flag if
-mcmodel=small code accesses were found.  The trouble with this is the
flag remains set if no code in the current file accesses the toc
entry.  Then the entry is deleted.  That fails when the toc is
accessed from another file using global symbols on the toc entries,
something that ld doesn't consider when optimizing the toc.  Now, gcc
never generates code that accesses the toc in another object, but
IBM's xlf does, and there's no reason why xlf or user code shouldn't
do that;  ld toc editing is supposed to be conservative.

The following patch ensures that the flag is cleared if ld never sees
any access to the toc entry in the current file.  It's not completely
foolproof, but should be enough to cure the xlf problem.

	* elf64-ppc.c (ppc64_elf_edit_toc): Ignore can_optimize bit if
	we haven't seen expected -mcmodel=medium/large code relocs.

Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.360
diff -u -p -r1.360 elf64-ppc.c
--- bfd/elf64-ppc.c	14 Aug 2011 08:11:56 -0000	1.360
+++ bfd/elf64-ppc.c	19 Aug 2011 02:13:57 -0000
@@ -8267,7 +8362,7 @@ ppc64_elf_edit_toc (struct bfd_link_info
 		some_unused = 1;
 	      last = 0;
 	    }
-	  else if (*drop)
+	  else if (*drop & ref_from_discarded)
 	    {
 	      some_unused = 1;
 	      last = ref_from_discarded;

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PowerPC64 toc edit fail
  2011-08-19  8:07 PowerPC64 toc edit fail Alan Modra
@ 2011-08-22 15:41 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2011-08-22 15:41 UTC (permalink / raw)
  To: binutils

Committed.

	* ld-powerpc/tocopt4a.s, * ld-powerpc/tocopt4b.s,
	* ld-powerpc/tocopt4.d: New test.
	* ld-powerpc/powerpc.exp: Run it.

Index: ld-powerpc/tocopt4a.s
===================================================================
RCS file: ld-powerpc/tocopt4a.s
diff -N ld-powerpc/tocopt4a.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-powerpc/tocopt4a.s	22 Aug 2011 14:26:08 -0000
@@ -0,0 +1,4 @@
+ .globl _start
+ .text
+_start:
+ ld 9,xt@toc(9)
Index: ld-powerpc/tocopt4b.s
===================================================================
RCS file: ld-powerpc/tocopt4b.s
diff -N ld-powerpc/tocopt4b.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-powerpc/tocopt4b.s	22 Aug 2011 14:26:08 -0000
@@ -0,0 +1,17 @@
+ .section .toc,"aw"
+ .globl xt
+xt:
+ .quad x
+#
+# This testcase will fail with a warning "xt defined on removed toc entry"
+# if a large-toc access like the following is added to this file, because
+# toc analysis only considers toc accesses from the current object file.
+# The small-toc access from tocopt4a.s doesn't cause xt entry to be marked
+# !can_optimize.  The testcase only passes because toc analysis considers
+# *no* access from the current file as being sufficiently unusual to
+# warrant keeping the toc entry.  So, if you use global symbols on toc
+# entries, don't mix code models.
+#
+# .text
+# addis 9,2,xt@toc@ha
+# ld 9,xt@toc@l(9)
Index: ld-powerpc/tocopt4.d
===================================================================
RCS file: ld-powerpc/tocopt4.d
diff -N ld-powerpc/tocopt4.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-powerpc/tocopt4.d	22 Aug 2011 14:26:08 -0000
@@ -0,0 +1,7 @@
+
+.*:     file format .*
+
+Contents of section \.text:
+ 100000b0 e9298000 .*
+Contents of section \.got:
+ 100100b8 00000000 00000002 .*
Index: ld-powerpc/powerpc.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-powerpc/powerpc.exp,v
retrieving revision 1.35
diff -u -p -r1.35 powerpc.exp
--- ld-powerpc/powerpc.exp	26 Jul 2011 01:57:18 -0000	1.35
+++ ld-powerpc/powerpc.exp	22 Aug 2011 14:26:23 -0000
@@ -209,6 +209,8 @@ set ppc64elftests {
 	{{ld tocopt2.out} {objdump -s tocopt2.d}} "tocopt2"}
     {"TOC opt3" "-melf64ppc -no-keep-memory --defsym x=2" "-a64"  {tocopt3.s}
 	{{objdump -s tocopt3.d}} "tocopt3"}
+    {"TOC opt4" "-melf64ppc -no-keep-memory --defsym x=2" "-a64"
+        {tocopt4a.s tocopt4b.s} {{objdump -s tocopt4.d}} "tocopt4"}
 }
 
 
-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-08-22 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19  8:07 PowerPC64 toc edit fail Alan Modra
2011-08-22 15:41 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).