Subject: New-toolchain bug on m68k
To: None <tech-toolchain@netbsd.org>
From: Steve Woodford <steve@mctavish.co.uk>
List: tech-toolchain
Date: 12/15/2001 17:22:31
Hi,

I've spent today re-testing new-toolchain on m68k following the recent
strength reduce bugfix. Unfortunately, the problem I was seeing with a
gas(1) built by new-toolchain persists.

The problem actually turns out to be in libbfd.so. Specifically,
bfd_set_section_contents() in section.c. This function tickles an
m68k-specific PIC bug to do with allocation of register %a5 as the GOT
pointer.

This function *does* potentially access global data, so the cc1 flag
`current_function_uses_pic_offset_table' gets set, triggering the load of
%a5 in the prologue. However, during optimisation, the compiler decides
that the reference to the global data is dead, optimises it away and
therefore it doesn't need a GOT pointer.

Unfortunately, gcc/config/m68k/m68k.c *still* emits the load of %a5, even
though regs_ever_live[%a5] is clear. As a result, %a5 doesn't get
callee-saved before loading the GOT... Non-pic callers who use %a5 lose.

I've fixed this locally using the following patch to
gcc/config/m68k/m68k.c, but I thought it better to run it past folks with
more gcc clue than me before commiting.

Cheers, Steve

Index: m68k.c
===================================================================
RCS file: /cvsroot/gnusrc/gnu/dist/toolchain/gcc/config/m68k/m68k.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 m68k.c
--- m68k.c	2000/07/26 00:18:31	1.1.1.1
+++ m68k.c	2001/12/15 17:19:16
@@ -462,7 +462,8 @@
 				  -cfa_store_offset + n_regs++ * 4);
 	}
     }
-  if (flag_pic && current_function_uses_pic_offset_table)
+  if (flag_pic && current_function_uses_pic_offset_table &&
+      regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
     {
 #ifdef MOTOROLA
       asm_fprintf (stream, "\t%Olea (%Rpc, %U_GLOBAL_OFFSET_TABLE_@GOTPC), %s\n",