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]

Fix glibc builds


Hi,
this is another attept to fix glibc failure.  As discussed earlier, the notion
of renaming is weird and should be restricted to avoid renaming of symbol
aready used.  Said that, one discover that it is very dificult to do, as
symbols are often used by extern inline functions and typeof specifier before
renamed so restricting it breaks glibc completely.

The patch for it has been never accepted and I think it is not good way
to go at least for 3.4.
This is more conservative approach that allows this renaming and adds an warning when
user actually manage to trigger the undefined behaviour.

Bootstrapped/regtested i386 and verified that I can build glibc 2.3.2 now.
OK?
Honza
2003-11-12  Jan Hubicka  <jh@suse.cz>
	* c-decl.c (finish_decl): Use change_decl_assembler_name.
	* c-pragma.c (handle_pragma_redefine_extname): Likewise.
	* varasm.c (make_decl_rtl): Likewise.
	* cgraph.c (change_decl_assembler_name): New function.
	* tree.h (set_decl_assembler_name): Kill dead declaration.
	(change_decl_assembler_name): Declare.

	* decl.c (make_rtl_for_nonlocal_decl): Use change_decl_assembler_name.
	* decl2.c (make_rtl_for_nonlocal_decl): Use change_decl_assembler_name.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.456
diff -c -3 -p -r1.456 c-decl.c
*** c-decl.c	28 Oct 2003 01:05:12 -0000	1.456
--- c-decl.c	12 Nov 2003 19:18:45 -0000
*************** finish_decl (tree decl, tree init, tree 
*** 2870,2876 ****
  #endif
  	}
        SET_DECL_RTL (decl, NULL_RTX);
!       SET_DECL_ASSEMBLER_NAME (decl, get_identifier (starred));
      }
  
    /* If #pragma weak was used, mark the decl weak now.  */
--- 2870,2876 ----
  #endif
  	}
        SET_DECL_RTL (decl, NULL_RTX);
!       change_decl_assembler_name (decl, get_identifier (starred));
      }
  
    /* If #pragma weak was used, mark the decl weak now.  */
*************** finish_decl (tree decl, tree init, tree 
*** 2920,2926 ****
  		warning ("%Jignoring asm-specifier for non-static local "
                           "variable '%D'", decl, decl);
  	      else
! 		SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
  	    }
  
  	  if (TREE_CODE (decl) != FUNCTION_DECL)
--- 2920,2926 ----
  		warning ("%Jignoring asm-specifier for non-static local "
                           "variable '%D'", decl, decl);
  	      else
! 		change_decl_assembler_name (decl, get_identifier (asmspec));
  	    }
  
  	  if (TREE_CODE (decl) != FUNCTION_DECL)
Index: c-pragma.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pragma.c,v
retrieving revision 1.64
diff -c -3 -p -r1.64 c-pragma.c
*** c-pragma.c	21 Sep 2003 05:07:09 -0000	1.64
--- c-pragma.c	12 Nov 2003 19:18:45 -0000
*************** handle_pragma_redefine_extname (cpp_read
*** 382,388 ****
        if (DECL_ASSEMBLER_NAME_SET_P (decl)
  	  && DECL_ASSEMBLER_NAME (decl) != newname)
          warning ("#pragma redefine_extname conflicts with declaration");
!       SET_DECL_ASSEMBLER_NAME (decl, newname);
      }
    else
      add_to_renaming_pragma_list(oldname, newname);
--- 382,388 ----
        if (DECL_ASSEMBLER_NAME_SET_P (decl)
  	  && DECL_ASSEMBLER_NAME (decl) != newname)
          warning ("#pragma redefine_extname conflicts with declaration");
!       change_decl_assembler_name (decl, newname);
      }
    else
      add_to_renaming_pragma_list(oldname, newname);
Index: cgraph.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraph.c,v
retrieving revision 1.35
diff -c -3 -p -r1.35 cgraph.c
*** cgraph.c	11 Nov 2003 17:43:45 -0000	1.35
--- cgraph.c	12 Nov 2003 19:18:45 -0000
*************** cgraph_varpool_node (tree decl)
*** 442,447 ****
--- 440,541 ----
    cgraph_varpool_nodes = node;
    *slot = node;
    return node;
+ }
+ 
+ /* Set the DECL_ASSEMBLER_NAME and update cgraph hashtables.  */
+ void
+ change_decl_assembler_name (tree decl, tree name)
+ {
+   struct cgraph_node *node = NULL;
+   struct cgraph_varpool_node *vnode = NULL;
+   void **slot;
+ 
+   if (!DECL_ASSEMBLER_NAME_SET_P (decl))
+     {
+       SET_DECL_ASSEMBLER_NAME (decl, name);
+       return;
+     }
+   if (name == DECL_ASSEMBLER_NAME (decl))
+     return;
+ 
+   if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
+     warning ("%D renamed after being referenced in assembly", decl);
+ 
+   if (TREE_CODE (decl) == FUNCTION_DECL && cgraph_hash)
+     {
+       /* Take a look whether declaration is in the cgraph structure.  */
+       slot = 
+ 	htab_find_slot_with_hash (cgraph_hash, DECL_ASSEMBLER_NAME (decl),
+ 				   IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME
+ 							  (decl)), NO_INSERT);
+       if (slot)
+ 	node = *slot;
+ 
+       /* It is, verify that we are the canonical node for this decl.  */
+       if (node && node->decl == decl)
+ 	{
+ 	  void **slot1;
+ 
+ 	  /* Check that we didn't introduce entry earlier.  */
+ 	  slot1 = 
+ 	    htab_find_slot_with_hash (cgraph_hash, name,
+ 				      IDENTIFIER_HASH_VALUE (name), NO_INSERT);
+ 	  if (slot1)
+ 	    abort ();
+ 
+ 	  node = *slot;
+ 	  htab_clear_slot (cgraph_hash, slot);
+       	 }
+        else
+ 	 node = NULL;
+     }
+   if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl) && cgraph_varpool_hash)
+     {
+       /* Take a look whether declaration is in the cgraph structure.  */
+       slot = 
+ 	htab_find_slot_with_hash (cgraph_varpool_hash, DECL_ASSEMBLER_NAME (decl),
+ 				   IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME
+ 							  (decl)), NO_INSERT);
+       if (slot)
+ 	vnode = *slot;
+ 
+       /* It is, verify that we are the canonical vnode for this decl.  */
+       if (vnode && vnode->decl == decl)
+ 	{
+ 	  void **slot1;
+ 
+ 	  /* Check that we didn't introduce entry earlier.  */
+ 	  slot1 = 
+ 	    htab_find_slot_with_hash (cgraph_varpool_hash, name,
+ 				      IDENTIFIER_HASH_VALUE (name), NO_INSERT);
+ 	  if (slot1)
+ 	    abort ();
+ 
+ 	  vnode = *slot;
+ 	  htab_clear_slot (cgraph_varpool_hash, slot);
+       	 }
+        else
+ 	 vnode = NULL;
+     }
+   SET_DECL_ASSEMBLER_NAME (decl, name);
+   if (node)
+     {
+       slot = 
+ 	htab_find_slot_with_hash (cgraph_hash, name,
+ 				  IDENTIFIER_HASH_VALUE (name), INSERT);
+       if (*slot)
+ 	abort ();
+       *slot = node;
+     }
+   if (vnode)
+     {
+       slot = 
+ 	htab_find_slot_with_hash (cgraph_varpool_hash, name,
+ 				  IDENTIFIER_HASH_VALUE (name), INSERT);
+       if (*slot)
+ 	abort ();
+       *slot = vnode;
+     }
  }
  
  /* Try to find existing function for identifier ID.  */
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.451
diff -c -3 -p -r1.451 tree.h
*** tree.h	6 Nov 2003 22:08:17 -0000	1.451
--- tree.h	12 Nov 2003 19:18:48 -0000
*************** extern tree get_file_function_name_long 
*** 2712,2718 ****
  extern tree get_set_constructor_bits (tree, char *, int);
  extern tree get_set_constructor_bytes (tree, unsigned char *, int);
  extern tree get_callee_fndecl (tree);
! extern void set_decl_assembler_name (tree);
  extern int type_num_arguments (tree);
  extern tree lhd_unsave_expr_now (tree);
  
--- 2712,2718 ----
  extern tree get_set_constructor_bits (tree, char *, int);
  extern tree get_set_constructor_bytes (tree, unsigned char *, int);
  extern tree get_callee_fndecl (tree);
! extern void change_decl_assembler_name (tree, tree);
  extern int type_num_arguments (tree);
  extern tree lhd_unsave_expr_now (tree);
  
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.397
diff -c -3 -p -r1.397 varasm.c
*** varasm.c	6 Nov 2003 22:08:17 -0000	1.397
--- varasm.c	12 Nov 2003 19:18:49 -0000
*************** make_decl_rtl (tree decl, const char *as
*** 791,797 ****
        char *starred = alloca (strlen (asmspec) + 2);
        starred[0] = '*';
        strcpy (starred + 1, asmspec);
!       SET_DECL_ASSEMBLER_NAME (decl, get_identifier (starred));
      }
  
    name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
--- 791,797 ----
        char *starred = alloca (strlen (asmspec) + 2);
        starred[0] = '*';
        strcpy (starred + 1, asmspec);
!       change_decl_assembler_name (decl, get_identifier (starred));
      }
  
    name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1151
diff -c -3 -p -r1.1151 decl.c
*** cp/decl.c	6 Nov 2003 22:08:23 -0000	1.1151
--- cp/decl.c	12 Nov 2003 19:18:51 -0000
*************** make_rtl_for_nonlocal_decl (tree decl, t
*** 4529,4535 ****
    /* Set the DECL_ASSEMBLER_NAME for the variable.  */
    if (asmspec)
      {
!       SET_DECL_ASSEMBLER_NAME (decl, get_identifier (asmspec));
        /* The `register' keyword, when used together with an
  	 asm-specification, indicates that the variable should be
  	 placed in a particular register.  */
--- 4529,4535 ----
    /* Set the DECL_ASSEMBLER_NAME for the variable.  */
    if (asmspec)
      {
!       change_decl_assembler_name (decl, get_identifier (asmspec));
        /* The `register' keyword, when used together with an
  	 asm-specification, indicates that the variable should be
  	 placed in a particular register.  */
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.685
diff -c -3 -p -r1.685 decl2.c
*** cp/decl2.c	21 Oct 2003 02:16:12 -0000	1.685
--- cp/decl2.c	12 Nov 2003 19:18:51 -0000
*************** grokfield (tree declarator, tree declspe
*** 1000,1006 ****
  	  /* This must override the asm specifier which was placed
  	     by grokclassfn.  Lay this out fresh.  */
  	  SET_DECL_RTL (value, NULL_RTX);
! 	  SET_DECL_ASSEMBLER_NAME (value, get_identifier (asmspec));
  	}
        if (!DECL_FRIEND_P (value))
  	grok_special_member_properties (value);
--- 1000,1006 ----
  	  /* This must override the asm specifier which was placed
  	     by grokclassfn.  Lay this out fresh.  */
  	  SET_DECL_RTL (value, NULL_RTX);
! 	  change_decl_assembler_name (value, get_identifier (asmspec));
  	}
        if (!DECL_FRIEND_P (value))
  	grok_special_member_properties (value);


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