tree-mudflap.c: Include cgraph.h.

gcc:
	* tree-mudflap.c: Include cgraph.h.
	(mf_init_extern_trees): Rename to mudflap_init.  Export.
	Rewrite to create synthetic declarations instead of looking
	up declarations from mf-runtime.h.
	(mf_make_builtin, mf_make_cache_struct_type): New functions.
	(mf_cache_shift_decl, mf_cache_mask_decl, mf_unregister_fndecl):
	Correct commentary.
	(execute_mudflap_function_decls, mudflap_register_call):
	Don't call mf_init_extern_trees.
	(mudflap_finish_file): Use cgraph_build_static_cdtor.

	* tree-mudflap.h: Update prototypes.
	* c-mudflap.c: Delete file.
	* c-common.c: Include tree-mudflap.h.
	(c_common_nodes_and_builtins): Call mudflap_init if appropriate.
	* Makefile.in: Remove all references to c-mudflap.o.
	Update dependencies.
gcc/cp:
	* cp-mudflap.c: Delete file.
	* Makefile.in: Remove all references to cp-mudflap.o.
libmudflap:
	* mf-runtime.h.in: Wrap declarations of struct __mf_cache,
	__mf_lookup_cache, __mf_lc_mask, or __mf_lc_shift in
	#ifndef _MUDFLAP.

From-SVN: r84126
This commit is contained in:
Zack Weinberg 2004-07-05 18:12:47 +00:00
parent 5dbf8812f1
commit c31b8e1b17
11 changed files with 137 additions and 238 deletions

View File

@ -1,3 +1,23 @@
2004-07-05 Zack Weinberg <zack@codesourcery.com>
* tree-mudflap.c: Include cgraph.h.
(mf_init_extern_trees): Rename to mudflap_init. Export.
Rewrite to create synthetic declarations instead of looking
up declarations from mf-runtime.h.
(mf_make_builtin, mf_make_cache_struct_type): New functions.
(mf_cache_shift_decl, mf_cache_mask_decl, mf_unregister_fndecl):
Correct commentary.
(execute_mudflap_function_decls, mudflap_register_call):
Don't call mf_init_extern_trees.
(mudflap_finish_file): Use cgraph_build_static_cdtor.
* tree-mudflap.h: Update prototypes.
* c-mudflap.c: Delete file.
* c-common.c: Include tree-mudflap.h.
(c_common_nodes_and_builtins): Call mudflap_init if appropriate.
* Makefile.in: Remove all references to c-mudflap.o.
Update dependencies.
2004-07-05 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* pa.md (prefetch, prefetch_32, prefetch_64): Only allow short

View File

@ -878,7 +878,7 @@ C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \
c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \
c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
c-objc-common.o c-dump.o c-pch.o $(C_TARGET_OBJS) \
c-gimplify.o tree-mudflap.o c-mudflap.o c-pretty-print.o
c-gimplify.o tree-mudflap.o c-pretty-print.o
# Language-specific object files for C.
C_OBJS = c-parse.o c-lang.o stub-objc.o $(C_AND_OBJC_OBJS)
@ -1414,7 +1414,7 @@ c-common.o : c-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(OBSTACK_H) $(C_COMMON_H) $(FLAGS_H) toplev.h output.h c-pragma.h intl.h \
$(GGC_H) $(EXPR_H) $(TM_P_H) builtin-types.def builtin-attrs.def \
$(DIAGNOSTIC_H) gt-c-common.h langhooks.h varray.h $(RTL_H) \
$(TARGET_H) $(C_TREE_H) tree-iterator.h langhooks.h
$(TARGET_H) $(C_TREE_H) tree-iterator.h langhooks.h tree-mudflap.h
c-pretty-print.o : c-pretty-print.c $(C_PRETTY_PRINT_H) \
$(C_COMMON_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) real.h \
$(DIAGNOSTIC_H)
@ -1713,10 +1713,7 @@ tree-gimple.o : tree-gimple.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(EXPR_H) \
tree-mudflap.o : $(CONFIG_H) errors.h $(SYSTEM_H) $(TREE_H) tree-inline.h \
$(C_TREE_H) $(C_COMMON_H) $(TREE_GIMPLE_H) diagnostic.h $(HASHTAB_H) \
output.h varray.h langhooks.h tree-mudflap.h $(TM_H) coretypes.h \
$(TREE_DUMP_H) tree-pass.h
c-mudflap.o : $(CONFIG_H) errors.h $(SYSTEM_H) $(TREE_H) tree-inline.h \
$(C_TREE_H) $(C_COMMON_H) $(TREE_GIMPLE_H) diagnostic.h $(HASHTAB_H) \
output.h varray.h langhooks.h tree-mudflap.h $(TM_H) coretypes.h
$(TREE_DUMP_H) tree-pass.h cgraph.h
tree-nomudflap.o : $(CONFIG_H) errors.h $(SYSTEM_H) $(TREE_H) tree-inline.h \
$(C_TREE_H) $(C_COMMON_H) $(TREE_GIMPLE_H) diagnostic.h $(HASHTAB_H) \
output.h varray.h langhooks.h tree-mudflap.h $(TM_H) coretypes.h

View File

@ -44,6 +44,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "toplev.h"
#include "tree-iterator.h"
#include "hashtab.h"
#include "tree-mudflap.h"
cpp_reader *parse_in; /* Declared in c-pragma.h. */
@ -3122,6 +3123,8 @@ c_common_nodes_and_builtins (void)
#undef DEF_BUILTIN
targetm.init_builtins ();
if (flag_mudflap)
mudflap_init ();
main_identifier_node = get_identifier ("main");
}

View File

@ -1,92 +0,0 @@
/* Mudflap: narrow-pointer bounds-checking by tree rewriting:
C front-end interface.
Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Frank Ch. Eigler <fche@redhat.com>
and Graydon Hoare <graydon@redhat.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include "config.h"
#include "errors.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "tree-inline.h"
#include "c-tree.h"
#include "c-common.h"
#include "diagnostic.h"
#include "output.h"
#include "varray.h"
#include "tree-mudflap.h"
#include "target.h"
#include "flags.h"
#include "rtl.h"
#include "toplev.h"
#include "function.h"
/* ------------------------------------------------------------------------ */
/* Initialize the global tree nodes that correspond to mf-runtime.h
declarations. */
tree
mflang_lookup_decl (const char* name)
{
tree decl = lookup_name (get_identifier (name));
if (decl == NULL_TREE)
internal_error ("mudflap: cannot find declaration of `%s' from mf-runtime.h",
name);
return decl;
}
/* Emit a synthetic CTOR function for the current file. Populate it from
the enqueued __mf_register calls. Compile the function. */
void
mflang_flush_calls (tree enqueued_call_stmt_chain)
{
tree fnname, t1, t2, cs;
/* Short-circuit! */
if (enqueued_call_stmt_chain == NULL_TREE)
return;
fnname = get_identifier ("__mudflap_static_initializer");
t1 = build_tree_list (NULL_TREE, void_type_node);
t2 = tree_cons (NULL, NULL, t1);
start_function (t1, build_nt (CALL_EXPR, fnname, t2, NULL), NULL);
store_parm_decls ();
DECL_STATIC_CONSTRUCTOR (current_function_decl) = 1;
TREE_PUBLIC (current_function_decl) = 0;
TREE_USED (current_function_decl) = 1;
mf_mark (current_function_decl);
cs = c_begin_compound_stmt (true);
c_finish_expr_stmt (enqueued_call_stmt_chain);
add_stmt (c_end_compound_stmt (cs, true));
finish_function ();
}

View File

@ -1,3 +1,8 @@
2004-07-05 Zack Weinberg <zack@codesourcery.com>
* cp-mudflap.c: Delete file.
* Makefile.in: Remove all references to cp-mudflap.o.
2004-07-05 Zack Weinberg <zack@codesourcery.com>
* decl.c (cxx_init_decl_processing): Call

View File

@ -82,7 +82,7 @@ CXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o cp/optimize.o \
cp/mangle.o cp/cp-lang.o cp/name-lookup.o cp/cxx-pretty-print.o \
cp/cp-gimplify.o tree-mudflap.o cp/cp-mudflap.o
cp/cp-gimplify.o tree-mudflap.o
# Use strict warnings for this front end.
cp-warn = $(STRICT_WARN) $(WERROR)
@ -267,8 +267,6 @@ cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) diagnostic.h gt-cp-parser.h \
output.h
cp/cp-gimplify.o: cp/cp-gimplify.c $(CXX_TREE_H) toplev.h c-common.h \
$(TM_H) coretypes.h
cp/cp-mudflap.o: cp/cp-mudflap.c $(CXX_TREE_H) toplev.h c-common.h \
$(TM_H) coretypes.h
cp/name-lookup.o: cp/name-lookup.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(CXX_TREE_H) timevar.h gt-cp-name-lookup.h toplev.h \

View File

@ -1,107 +0,0 @@
/* Mudflap: narrow-pointer bounds-checking by tree rewriting:
C++ front-end interface.
Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Frank Ch. Eigler <fche@redhat.com>
and Graydon Hoare <graydon@redhat.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include "config.h"
#include "errors.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "tree-inline.h"
#include "cp-tree.h"
#include "c-common.h"
#include "diagnostic.h"
#include "output.h"
#include "varray.h"
#include "tree-mudflap.h"
#include "target.h"
#include "flags.h"
#include "rtl.h"
#include "toplev.h"
/* Initialize the global tree nodes that correspond to mf-runtime.h
declarations. */
tree
mflang_lookup_decl (const char* name)
{
tree decl = lookup_name (get_identifier (name), 1);
if (decl == NULL_TREE)
internal_error ("mudflap: cannot find declaration of `%s' from mf-runtime.h",
name);
return decl;
}
/* Emit a synthetic CTOR function for the current file. Populate it from
the enqueued __mf_register calls. Register it with the constructors. */
void
mflang_flush_calls (tree enqueued_call_stmt_chain)
{
tree fnname, fndecl, body;
tree type;
/* Short-circuit! */
if (enqueued_call_stmt_chain == NULL_TREE)
return;
/* Create a ctor function declaration. */
fnname = get_identifier ("__static_initialization_and_destruction_mudflap");
type = build_function_type (void_type_node, void_list_node);
fndecl = build_lang_decl (FUNCTION_DECL, fnname, type);
TREE_PUBLIC (fndecl) = 0;
TREE_USED (fndecl) = 1;
DECL_ARTIFICIAL (fndecl) = 1;
mf_mark (fndecl);
/* Generate the body, one statement at a time. */
start_preparsed_function (fndecl, /*attrs=*/NULL_TREE, SF_PRE_PARSED);
body = begin_compound_stmt (BCS_FN_BODY);
while (enqueued_call_stmt_chain)
{
tree next = TREE_CHAIN (enqueued_call_stmt_chain);
finish_expr_stmt (enqueued_call_stmt_chain);
enqueued_call_stmt_chain = next;
}
finish_compound_stmt (body);
fndecl = finish_function (0);
/* NB: We cannot call expand_or_defer_fn here, since that goes through
the callgraph queue. This queue will have already been processed by the
time this function is running. */
expand_body (fndecl);
if (targetm.have_ctors_dtors)
(* targetm.asm_out.constructor) (XEXP (DECL_RTL (fndecl), 0),
DEFAULT_INIT_PRIORITY);
else
/* By this time, it's too late to do this:
static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors); */
abort ();
}

View File

@ -44,6 +44,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include <demangle.h>
#include "langhooks.h"
#include "ggc.h"
#include "cgraph.h"
/* Internal function decls */
@ -52,9 +53,6 @@ static tree mf_build_string (const char *string);
static tree mf_varname_tree (tree);
static tree mf_file_function_line_tree (location_t);
/* Initialization of all the mf-runtime.h extern decls. */
static void mf_init_extern_trees (void);
/* Indirection-related instrumentation. */
static void mf_decl_cache_locals (void);
static void mf_decl_clear_locals (void);
@ -247,10 +245,10 @@ static GTY (()) tree mf_cache_structptr_type;
/* extern struct __mf_cache __mf_lookup_cache []; */
static GTY (()) tree mf_cache_array_decl;
/* extern const unsigned char __mf_lc_shift; */
/* extern unsigned char __mf_lc_shift; */
static GTY (()) tree mf_cache_shift_decl;
/* extern const uintptr_t __mf_lc_mask; */
/* extern uintptr_t __mf_lc_mask; */
static GTY (()) tree mf_cache_mask_decl;
/* Their function-scope local shadows, used in single-threaded mode only. */
@ -267,31 +265,98 @@ static GTY (()) tree mf_check_fndecl;
/* extern void __mf_register (void *ptr, size_t sz, int type, const char *); */
static GTY (()) tree mf_register_fndecl;
/* extern void __mf_unregister (void *ptr, size_t sz); */
/* extern void __mf_unregister (void *ptr, size_t sz, int type); */
static GTY (()) tree mf_unregister_fndecl;
/* Helper for mudflap_init: construct a decl with the given category,
name, and type, mark it an external reference, and pushdecl it. */
static inline tree
mf_make_builtin (enum tree_code category, const char *name, tree type)
{
tree decl = mf_mark (build_decl (category, get_identifier (name), type));
TREE_PUBLIC (decl) = 1;
DECL_EXTERNAL (decl) = 1;
lang_hooks.decls.pushdecl (decl);
return decl;
}
/* Helper for mudflap_init: construct a tree corresponding to the type
struct __mf_cache { uintptr_t low; uintptr_t high; };
where uintptr_t is the FIELD_TYPE argument. */
static inline tree
mf_make_mf_cache_struct_type (tree field_type)
{
/* There is, abominably, no language-independent way to construct a
RECORD_TYPE. So we have to call the basic type construction
primitives by hand. */
tree fieldlo = build_decl (FIELD_DECL, get_identifier ("low"), field_type);
tree fieldhi = build_decl (FIELD_DECL, get_identifier ("high"), field_type);
tree struct_type = make_node (RECORD_TYPE);
DECL_CONTEXT (fieldlo) = struct_type;
DECL_CONTEXT (fieldhi) = struct_type;
TREE_CHAIN (fieldlo) = fieldhi;
TYPE_FIELDS (struct_type) = fieldlo;
TYPE_NAME (struct_type) = get_identifier ("__mf_cache");
layout_type (struct_type);
return struct_type;
}
#define build_function_type_3(rtype, arg1, arg2, arg3) \
build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2, \
tree_cons (0, arg3, void_list_node))))
#define build_function_type_4(rtype, arg1, arg2, arg3, arg4) \
build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2, \
tree_cons (0, arg3, tree_cons (0, arg4, \
void_list_node)))))
/* Initialize the global tree nodes that correspond to mf-runtime.h
declarations. */
static void
mf_init_extern_trees (void)
void
mudflap_init (void)
{
static bool done = false;
tree mf_const_string_type;
tree mf_cache_array_type;
tree mf_check_register_fntype;
tree mf_unregister_fntype;
if (done)
return;
done = true;
mf_uintptr_type = TREE_TYPE (mflang_lookup_decl ("uintptr_t"));
mf_cache_array_decl = mf_mark (mflang_lookup_decl ("__mf_lookup_cache"));
mf_cache_struct_type = TREE_TYPE (TREE_TYPE (mf_cache_array_decl));
mf_uintptr_type = lang_hooks.types.type_for_mode (ptr_mode,
/*unsignedp=*/true);
mf_const_string_type
= build_pointer_type (build_qualified_type
(char_type_node, TYPE_QUAL_CONST));
mf_cache_struct_type = mf_make_mf_cache_struct_type (mf_uintptr_type);
mf_cache_structptr_type = build_pointer_type (mf_cache_struct_type);
mf_cache_shift_decl = mf_mark (mflang_lookup_decl ("__mf_lc_shift"));
mf_cache_mask_decl = mf_mark (mflang_lookup_decl ("__mf_lc_mask"));
mf_check_fndecl = mflang_lookup_decl ("__mf_check");
mf_register_fndecl = mflang_lookup_decl ("__mf_register");
mf_unregister_fndecl = mflang_lookup_decl ("__mf_unregister");
mf_cache_array_type = build_array_type (mf_cache_struct_type, 0);
mf_check_register_fntype =
build_function_type_4 (void_type_node, ptr_type_node, size_type_node,
integer_type_node, mf_const_string_type);
mf_unregister_fntype =
build_function_type_3 (void_type_node, ptr_type_node, size_type_node,
integer_type_node);
mf_cache_array_decl = mf_make_builtin (VAR_DECL, "__mf_lookup_cache",
mf_cache_array_type);
mf_cache_shift_decl = mf_make_builtin (VAR_DECL, "__mf_lc_shift",
unsigned_char_type_node);
mf_cache_mask_decl = mf_make_builtin (VAR_DECL, "__mf_lc_mask",
mf_uintptr_type);
mf_check_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_check",
mf_check_register_fntype);
mf_register_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_register",
mf_check_register_fntype);
mf_unregister_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_unregister",
mf_unregister_fntype);
}
#undef build_function_type_4
#undef build_function_type_3
/* ------------------------------------------------------------------------ */
@ -773,7 +838,6 @@ execute_mudflap_function_decls (void)
push_gimplify_context ();
mf_init_extern_trees ();
mf_xform_decls (DECL_SAVED_TREE (current_function_decl),
DECL_ARGUMENTS (current_function_decl));
@ -1064,7 +1128,6 @@ mudflap_register_call (tree obj, tree object_size, tree varname)
arg = convert (ptr_type_node, arg);
args = tree_cons (NULL_TREE, arg, args);
mf_init_extern_trees ();
call_stmt = build_function_call_expr (mf_register_fndecl, args);
append_to_statement_list (call_stmt, &enqueued_call_stmt_chain);
@ -1181,7 +1244,11 @@ mudflap_finish_file (void)
VARRAY_CLEAR (deferred_static_decls);
}
mflang_flush_calls (enqueued_call_stmt_chain);
if (enqueued_call_stmt_chain)
{
cgraph_build_static_cdtor ('I', enqueued_call_stmt_chain);
enqueued_call_stmt_chain = 0;
}
}

View File

@ -23,6 +23,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#define TREE_MUDFLAP_H
/* Instrumentation. */
extern void mudflap_init (void);
extern void mudflap_c_function_decls (tree);
extern void mudflap_c_function_ops (tree);
extern void mudflap_enqueue_decl (tree);
@ -33,9 +34,4 @@ extern void mudflap_finish_file (void);
extern int mf_marked_p (tree);
extern tree mf_mark (tree);
/* To be provided by a front-end interface module. */
extern tree mflang_lookup_decl (const char *);
extern void mflang_flush_calls (tree);
#endif /* TREE_MUDFLAP_H */

View File

@ -1,3 +1,9 @@
2004-07-05 Zack Weinberg <zack@codesourcery.com>
* mf-runtime.h.in: Wrap declarations of struct __mf_cache,
__mf_lookup_cache, __mf_lc_mask, or __mf_lc_shift in
#ifndef _MUDFLAP.
2004-06-29 Frank Ch. Eigler <fche@redhat.com>
Splay tree implementation fork.
@ -95,7 +101,7 @@
* testsuite/libmudflap.c/pass46-frag.c: Ditto.
* configure, Makefile, aclocal.m4, config.h.in, testsuite/Makefile.in:
Regenerated with autoconf 2.57 and automake 1.7.
2004-06-04 Per Bothner <per@bothner.com>
* configure.in (LIBMUDFLAPTH): Fix thinko.
@ -229,8 +235,8 @@
2003-11-19 Frank Ch. Eigler <fche@redhat.com>
libstdc++/11696
* mf-runtime.h.in: Switch to #pragma redefine_extname for
symbols interposed at compile time.
* mf-runtime.h.in: Switch to #pragma redefine_extname for
symbols interposed at compile time.
* testsuite/libmudflap.c++/pass41-frag.cxx: New test.
libmudflap/12939
@ -254,7 +260,7 @@
2003-07-29 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
* configure.in: Update check for union semun.
* configure.in: Update check for union semun.
2003-07-29 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>

View File

@ -15,12 +15,18 @@ typedef unsigned long uintptr_t;
#endif
/* Global declarations used by instrumentation. */
/* Global declarations used by instrumentation. When _MUDFLAP is
defined, these have been auto-declared by the compiler and we
should not declare them again (ideally we *would* declare them
again, to verify that the compiler's declarations match the
library's, but the C++ front end has no mechanism for allowing
the re-definition of a structure type). */
#ifndef _MUDFLAP
struct __mf_cache { uintptr_t low; uintptr_t high; };
extern struct __mf_cache __mf_lookup_cache [];
extern uintptr_t __mf_lc_mask;
extern unsigned char __mf_lc_shift;
#endif
/* Multithreading support. */
#ifdef _MUDFLAPTH