[PATCH] Fix PPC32 local checks in 3.2 (was: Re: [libffi] closures for sparc)
Franz Sirl
Franz.Sirl-kernel@lauterbach.com
Mon Jan 20 23:34:00 GMT 2003
On Tuesday 21 January 2003 00:01, Jakub Jelinek wrote:
> On Sun, Jan 05, 2003 at 11:26:30AM -0500, Jeff Sturm wrote:
> > On Sat, 4 Jan 2003, Andreas Tobler wrote:
> > > Hm, powerpc-unknown-linux-gnu doesn't like the static:
> > >
> > > .libs/ffitest.o: could not read symbols: Bad value
> >
> > Strange. Surely this isn't a problem in libffi though?
> >
> > Can you try a newer ld and see if it fixes the problem? If not, let me
> > know and I'll attempt a cross build (I don't have a powerpc-linux machine
> > handy).
>
> I get the same on ppc-linux. To me this looks like a bug in gcc:
>
> /* { dg-do link } */
> /* { dg-options "-O2 -fpic" } */
> static char foo [128];
> void bar (void)
> {
> ((void (*)(void))foo)();
> }
> int main ()
> {
> }
>
> results in:
> ...
> bl foo@plt
> ...
> .lcomm foo,128,4
>
> Note @plt used for local symbol.
Yeah, I have a patch for that. I simply backported the gllobal gcc-3.3
binds_local_p routine to a local one in rs6000.c. Works like a charm here, no
regressions and it works for glibc, qt, KDE-3.1, kernel just fine.
OK to commit to gcc-3_2-branch?
Jakub, as soon as you pull this over to the rhl8 branch, you can remove the
"ExcludeArch: ppc" of the Omni package in RawHide.
Franz.
* config/rs6000/rs6000.c (rs6000_binds_local_p): New functiion.
(rs6000_encode_section_info): Use it.
-------------- next part --------------
Index: gcc/config/rs6000/rs6000.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.291.2.13.2.5.2.4
diff -u -p -r1.291.2.13.2.5.2.4 rs6000.c
--- gcc/config/rs6000/rs6000.c 8 Dec 2002 19:39:16 -0000 1.291.2.13.2.5.2.4
+++ gcc/config/rs6000/rs6000.c 20 Jan 2003 23:23:41 -0000
@@ -155,6 +155,7 @@ static void rs6000_elf_asm_out_destructo
#ifdef OBJECT_FORMAT_COFF
static void xcoff_asm_named_section PARAMS ((const char *, unsigned int));
#endif
+static bool rs6000_binds_local_p PARAMS ((tree));
static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int));
static int rs6000_adjust_priority PARAMS ((rtx, int));
static int rs6000_issue_rate PARAMS ((void));
@@ -10947,7 +10948,50 @@ rs6000_unique_section (decl, reloc)
DECL_SECTION_NAME (decl) = build_string (len, string);
}
-
+
+static bool
+rs6000_binds_local_p (exp)
+ tree exp;
+{
+ bool local_p;
+ tree attr;
+
+ /* A non-decl is an entry in the constant pool. */
+ if (!DECL_P (exp))
+ local_p = true;
+ /* Static variables are always local. */
+ else if (! TREE_PUBLIC (exp))
+ local_p = true;
+ /* A variable is local if the user tells us so. */
+ else if ((attr = lookup_attribute ("visibility", DECL_ATTRIBUTES (exp)))
+ && strcmp (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))),
+ "default") != 0)
+ local_p = true;
+ /* Otherwise, variables defined outside this object may not be local. */
+ else if (DECL_EXTERNAL (exp))
+ local_p = false;
+ /* Linkonce and weak data are never local. */
+ else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
+ local_p = false;
+ /* If PIC, then assume that any global name can be overridden by
+ * symbols resolved from other modules. */
+ else if (flag_pic || rs6000_flag_pic)
+ local_p = false;
+ /* Uninitialized COMMON variable may be unified with symbols
+ * resolved from other modules. */
+ else if (DECL_COMMON (exp)
+ && (DECL_INITIAL (exp) == NULL
+ || DECL_INITIAL (exp) == error_mark_node))
+ local_p = false;
+ /* Otherwise we're left with initialized (or non-common) global data
+ * which is of necessity defined locally. */
+ else
+ local_p = true;
+
+ return local_p;
+}
+
+
/* If we are referencing a function that is static or is known to be
in this file, make the SYMBOL_REF special. We can use this to indicate
that we can branch to this function without emitting a no-op after the
@@ -10963,12 +11007,7 @@ rs6000_encode_section_info (decl)
if (TREE_CODE (decl) == FUNCTION_DECL)
{
rtx sym_ref = XEXP (DECL_RTL (decl), 0);
- if (!TREE_PUBLIC (decl)
- || (!DECL_EXTERNAL (decl)
- && !DECL_ONE_ONLY (decl)
- && !DECL_WEAK (decl)
- && !flag_pic
- && !rs6000_flag_pic))
+ if (rs6000_binds_local_p (decl))
SYMBOL_REF_FLAG (sym_ref) = 1;
if (DEFAULT_ABI == ABI_AIX)
@@ -10987,10 +11026,14 @@ rs6000_encode_section_info (decl)
&& DEFAULT_ABI == ABI_V4
&& TREE_CODE (decl) == VAR_DECL)
{
+ rtx sym_ref = XEXP (DECL_RTL (decl), 0);
int size = int_size_in_bytes (TREE_TYPE (decl));
tree section_name = DECL_SECTION_NAME (decl);
const char *name = (char *)0;
int len = 0;
+
+ if (rs6000_binds_local_p (decl))
+ SYMBOL_REF_FLAG (sym_ref) = 1;
if (section_name)
{
More information about the Java-patches
mailing list