This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

TREE_PUBLIC vs DECL_EXTERNAL


Since I switched the x86 backend to use default_binds_local_p
instead of simply looking at TREE_PUBLIC and MODULE_LOCAL_P,
we've been calling a lot of static functions through the PLT.

I was surprised to discover that we were setting DECL_EXTERNAL
on static functions.  Which is confusing to me, because I 
thought DECL_EXTERNAL means "defined in some other object".
Which can't be true for !TREE_PUBLIC.

I attempted to fix this in the C front end, but my patch
(available on request) failed on gcc.c-torture/compile/920625-2.c
which has block-scope static forward function declarations.

I also ran into problems with libjava/jni.cc from the C++ front
end.  I'm assuming the problem there is that some of the scary
DECL_NOT_REALLY_EXTERN stuff slipped through.  Certainly I don't
feel that I understand that code enough to touch it.

I think we should be able to put a check like

	if (!TREE_PUBLIC (decl) && DECL_EXTERNAL (decl))
	  abort ();

in make_decl_rtl.  Or if not, then by gum the documentation 
should be updated to explain why.

For now though, I've chickened out and applied the following.


r~


        * varasm.c (default_binds_local_p): Check TREE_PUBLIC before
        DECL_EXTERNAL.

Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.288
diff -c -p -d -r1.288 varasm.c
*** varasm.c	24 May 2002 18:30:44 -0000	1.288
--- varasm.c	28 May 2002 20:06:50 -0000
*************** default_binds_local_p (exp)
*** 5597,5603 ****
    /* A non-decl is an entry in the constant pool.  */
    if (!DECL_P (exp))
      local_p = true;
!   /* A variable is considered "local" if it is defined by this module.  */
    else if (MODULE_LOCAL_P (exp))
      local_p = true;
    /* Otherwise, variables defined outside this object may not be local.  */
--- 5597,5606 ----
    /* 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 (MODULE_LOCAL_P (exp))
      local_p = true;
    /* Otherwise, variables defined outside this object may not be local.  */
*************** default_binds_local_p (exp)
*** 5606,5614 ****
    /* Linkonce and weak data are never local.  */
    else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
      local_p = false;
-   /* Static variables are always local.  */
-   else if (! TREE_PUBLIC (exp))
-     local_p = true;
    /* If PIC, then assume that any global name can be overridden by
       symbols resolved from other modules.  */
    else if (flag_pic)
--- 5609,5614 ----


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