summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaroline Tice <cmtice@chromium.org>2013-07-09 11:57:16 -0700
committerCaroline Tice <cmtice@chromium.org>2013-07-09 11:57:16 -0700
commitc280fefb408c40720259d8b267007ec19faa1800 (patch)
treea98785eb84d913f8be838571c452daf42b2431ed
parent301bce67d4f2a7a14e559a443d8dcd5e07e3f31b (diff)
downloadgcc-ctice/vtv.tar.gz
Finish making all changes to fix vtable verification feature, addctice/vtv
debugging flags, rename functions, etc. appropriately, and make testsuite run. Only change not here is creating libvtv.so.
-rw-r--r--gcc/cp/vtable-class-hierarchy.c18
-rw-r--r--gcc/gcc.c13
-rw-r--r--gcc/vtable-verify.c3
-rw-r--r--libstdc++-v3/Makefile.in6
-rw-r--r--libstdc++-v3/doc/Makefile.in6
-rw-r--r--libstdc++-v3/fragment.am5
-rw-r--r--libstdc++-v3/include/Makefile.am2
-rw-r--r--libstdc++-v3/include/Makefile.in8
-rw-r--r--libstdc++-v3/libsupc++/Makefile.am39
-rw-r--r--libstdc++-v3/libsupc++/Makefile.in70
-rw-r--r--libstdc++-v3/libsupc++/vtv_fail.cc233
-rw-r--r--libstdc++-v3/libsupc++/vtv_fail.h7
-rw-r--r--libstdc++-v3/libsupc++/vtv_init.cc92
-rw-r--r--libstdc++-v3/libsupc++/vtv_malloc.cc39
-rw-r--r--libstdc++-v3/libsupc++/vtv_malloc.h16
-rw-r--r--libstdc++-v3/libsupc++/vtv_map.h4
-rw-r--r--libstdc++-v3/libsupc++/vtv_rts.cc270
-rw-r--r--libstdc++-v3/libsupc++/vtv_utils.cc40
-rw-r--r--libstdc++-v3/libsupc++/vtv_utils.h18
-rw-r--r--libstdc++-v3/po/Makefile.in6
-rw-r--r--libstdc++-v3/python/Makefile.in6
-rwxr-xr-xlibstdc++-v3/scripts/testsuite_flags.in3
-rw-r--r--libstdc++-v3/src/Makefile.in6
-rw-r--r--libstdc++-v3/src/c++11/Makefile.in6
-rw-r--r--libstdc++-v3/src/c++98/Makefile.in6
-rw-r--r--libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c2
-rw-r--r--libstdc++-v3/testsuite/Makefile.in6
27 files changed, 419 insertions, 511 deletions
diff --git a/gcc/cp/vtable-class-hierarchy.c b/gcc/cp/vtable-class-hierarchy.c
index 4cb0d325da7..5780638abcb 100644
--- a/gcc/cp/vtable-class-hierarchy.c
+++ b/gcc/cp/vtable-class-hierarchy.c
@@ -162,7 +162,7 @@ struct vtbl_map_node *vtable_find_or_create_map_decl (tree);
__VLTVerifyVtablePointerDebug which can be used in place of
__VLTVerifyVtablePointer, and which takes extra parameters and
outputs extra information, to help debug problems. The debug
- version of this function is generated and used if vtv_debug is
+ version of this function is generated and used if flag_vtv_debug is
true.
The signatures for these functions are:
@@ -180,7 +180,7 @@ vtv_build_vtable_verify_fndecl (void)
&& TREE_CODE (verify_vtbl_ptr_fndecl) != ERROR_MARK)
return;
- if (vtv_debug)
+ if (flag_vtv_debug)
{
func_type = build_function_type_list (const_ptr_type_node,
build_pointer_type (ptr_type_node),
@@ -256,7 +256,7 @@ init_functions (void)
build_pointer_type (ptr_type_node),
NULL_TREE);
- if (vtv_debug)
+ if (flag_vtv_debug)
vlt_register_set_fndecl = build_lang_decl
(FUNCTION_DECL,
get_identifier ("__VLTRegisterSetDebug"),
@@ -278,7 +278,7 @@ init_functions (void)
/* Build function decl for __VLTRegisterPair*. */
- if (vtv_debug)
+ if (flag_vtv_debug)
{
register_pairs_type = build_function_type_list (void_type_node,
build_pointer_type
@@ -771,7 +771,6 @@ insert_call_to_register_set (tree class_name, int num_args,
vec<constructor_elt, va_gc> *array_elements;
vec_alloc (array_elements, num_args);
- /* constructor_elt *celt; */
tree initial = NULL_TREE;
tree arg3 = NULL_TREE;
@@ -786,11 +785,6 @@ insert_call_to_register_set (tree class_name, int num_args,
for (k = 0; k < num_args; ++k)
{
- /*
- vec_safe_push (array_elements, celt);
- celt->index = build_int_cst (integer_type_node, k);
- celt->value = vtbl_ptr_array[k];
- */
CONSTRUCTOR_APPEND_ELT (array_elements, NULL_TREE, vtbl_ptr_array[k]);
}
@@ -825,7 +819,7 @@ insert_call_to_register_pair (tree vtable_address, int num_args, tree arg1,
if (num_args == 0)
vtable_address = build_int_cst (build_pointer_type (void_type_node), 0);
- if (vtv_debug)
+ if (flag_vtv_debug)
call_expr = build_call_expr (vlt_register_pairs_fndecl, 6, arg1, arg2,
size_hint_arg, vtable_address, str1, str2);
else
@@ -912,7 +906,7 @@ register_all_pairs (tree body)
gcc_assert (current->class_info != NULL);
- if (vtv_debug)
+ if (flag_vtv_debug)
str1 = build_string_from_id (DECL_NAME (base_ptr_var_decl));
new_type = build_pointer_type (TREE_TYPE (base_ptr_var_decl));
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 97dd57ac265..7444aab8928 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -722,11 +722,24 @@ proper position among the other output files. */
%{!pie:%{!shared:%e-fsanitize=thread linking must be done with -pie or -shared}}}}}"
#endif
+/* This is the spec to use, once the code for creating the vtable
+ verification runtime library, libvtv.so, has been created. Currently
+ the vtable verification runtime functions are in libstdc++, so we use
+ the spec just below this one. */
+/*
#ifndef VTABLE_VERIFICATION_SPEC
#define VTABLE_VERIFICATION_SPEC "\
%{!nostdlib:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\
%{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}"
#endif
+*/
+
+/* Once libvtv.so has been created, delete this spec and use the one above. */
+#ifndef VTABLE_VERIFICATION_SPEC
+#define VTABLE_VERIFICATION_SPEC "\
+%{!nostdlib:%{fvtable-verify=std: -u_vtable_map_vars_start -u_vtable_map_vars_end}\
+ %{fvtable-verify=preinit: -u_vtable_map_vars_start -u_vtable_map_vars_end}}"
+#endif
/* -u* was put back because both BSD and SysV seem to support it. */
/* %{static:} simply prevents an error message if the target machine
diff --git a/gcc/vtable-verify.c b/gcc/vtable-verify.c
index 749dfb33a89..e48f21f1fb2 100644
--- a/gcc/vtable-verify.c
+++ b/gcc/vtable-verify.c
@@ -157,7 +157,6 @@ along with GCC; see the file COPYING3. If not see
#include "vtable-verify.h"
-bool vtv_debug = false;
unsigned num_vtable_map_nodes = 0;
bool any_verification_calls_generated = false;
int total_num_virtual_calls = 0;
@@ -658,7 +657,7 @@ verify_bb_vtables (basic_block bb)
/* Call different routines if we are interested in
trace information to debug problems. */
- if (vtv_debug)
+ if (flag_vtv_debug)
{
int len1 = IDENTIFIER_LENGTH
(DECL_NAME (vtbl_var_decl));
diff --git a/libstdc++-v3/Makefile.in b/libstdc++-v3/Makefile.in
index 9e7fc77f47c..6f8a03aab69 100644
--- a/libstdc++-v3/Makefile.in
+++ b/libstdc++-v3/Makefile.in
@@ -302,11 +302,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
diff --git a/libstdc++-v3/doc/Makefile.in b/libstdc++-v3/doc/Makefile.in
index ff0ea51c727..23ef84f69dc 100644
--- a/libstdc++-v3/doc/Makefile.in
+++ b/libstdc++-v3/doc/Makefile.in
@@ -284,11 +284,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
diff --git a/libstdc++-v3/fragment.am b/libstdc++-v3/fragment.am
index 5b7c08b3207..21c5f497f6b 100644
--- a/libstdc++-v3/fragment.am
+++ b/libstdc++-v3/fragment.am
@@ -26,12 +26,15 @@ XTEMPLATE_FLAGS =
endif
if ENABLE_VTABLE_VERIFY
-VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
VTV_CXXFLAGS = -fvtable-verify=std \
-Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+VTV_PCH_CXXFLAGS = -fvtable-verify=std
else
VTV_CXXLINKFLAGS =
VTV_CXXFLAGS =
+VTV_PCH_CXXFLAGS =
endif
# These bits are all figured out from configure. Look in acinclude.m4
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 801a8858087..d08864cf7b8 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -893,7 +893,7 @@ pch_output_dirs = \
${pch1_output_builddir} ${pch2_output_builddir} ${pch3_output_builddir}
pch_output_anchors = \
${pch1_output_anchor} ${pch2_output_anchor} ${pch3_output_anchor}
-PCHFLAGS=-x c++-header -nostdinc++ $(CXXFLAGS)
+PCHFLAGS=-x c++-header -nostdinc++ $(CXXFLAGS) $(VTV_PCH_CXXFLAGS)
if GLIBCXX_BUILD_PCH
pch_build = ${pch_output}
else
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 5f4583a3652..cc8d7e1ca51 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -274,11 +274,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
@@ -1155,7 +1159,7 @@ pch_output_dirs = \
pch_output_anchors = \
${pch1_output_anchor} ${pch2_output_anchor} ${pch3_output_anchor}
-PCHFLAGS = -x c++-header -nostdinc++ $(CXXFLAGS)
+PCHFLAGS = -x c++-header -nostdinc++ $(CXXFLAGS) $(VTV_PCH_CXXFLAGS)
@GLIBCXX_BUILD_PCH_FALSE@pch_build =
@GLIBCXX_BUILD_PCH_TRUE@pch_build = ${pch_output}
diff --git a/libstdc++-v3/libsupc++/Makefile.am b/libstdc++-v3/libsupc++/Makefile.am
index 4fdd9f44387..0e423277e56 100644
--- a/libstdc++-v3/libsupc++/Makefile.am
+++ b/libstdc++-v3/libsupc++/Makefile.am
@@ -26,7 +26,8 @@ include $(top_srcdir)/fragment.am
# separately too.
# 1) separate libsupc++.la
if ENABLE_VTABLE_VERIFY
-toolexeclib_LTLIBRARIES = libsupc++.la libvtv.la libvtv_stubs.la
+#toolexeclib_LTLIBRARIES = libsupc++.la libvtv.la
+toolexeclib_LTLIBRARIES = libsupc++.la libvtv_stubs.la
else
toolexeclib_LTLIBRARIES = libsupc++.la
endif
@@ -102,18 +103,31 @@ sources = \
if ENABLE_VTABLE_VERIFY
- sources += \
- vtv_fail.cc
+# Once we have libvtv.so as a separate library, the stubs work will
+# go directly into libsupc++.
+# sources += \
+# vtv_stubs.cc
+
+# These will eventually go into libvtv.so
+# vtv_sources = \
+# vtv_rts.cc \
+# vtv_malloc.cc \
+# vtv_utils.cc
- vtv_sources = \
+# This is only temporary, until libvtv.so is created:
+ sources += \
vtv_rts.cc \
vtv_malloc.cc \
vtv_utils.cc
+# This is only temporary, until libvtv.so is created:
vtv_stubs_sources = \
vtv_stubs.cc
- libvtv_la_SOURCES = $(vtv_sources)
+# These would be for libvtv.so
+# libvtv_la_SOURCES = $(vtv_sources)
+
+# This is only temporary, until libvtv.so is created.
libvtv_stubs_la_SOURCES = $(vtv_stubs_sources)
endif
@@ -200,6 +214,11 @@ AM_CXXFLAGS = \
$(XTEMPLATE_FLAGS) \
$(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
+AM_CXXFLAGS_SHARED = \
+ $(glibcxx_compiler_shared_flag) \
+ $(XTEMPLATE_FLAGS) \
+ $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
+
AM_MAKEFLAGS = \
"gxx_include_dir=$(gxx_include_dir)"
@@ -250,6 +269,12 @@ LTCXXCOMPILE = \
--mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(EXTRA_CXX_FLAGS)
+LTCXXCOMPILE_S = \
+ $(LIBTOOL) --tag CXX --tag enable-shared \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CXX) $(TOPLEVEL_INCLUDES) -DSHARED \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(EXTRA_CXX_FLAGS)
+
LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
# 3) We'd have a problem when building the shared libstdc++ object if
@@ -264,6 +289,10 @@ CXXLINK = \
--mode=link $(CXX) \
$(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LTLDFLAGS) -o $@
+CXXLINK_SHARED = \
+ $(CXX) \
+ $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS_SHARED) $(LTLDFLAGS) -o $@
+
# Install notes
# We have to have rules modified from the default to counteract SUN make
# prepending each of $(*_HEADERS) with VPATH below.
diff --git a/libstdc++-v3/libsupc++/Makefile.in b/libstdc++-v3/libsupc++/Makefile.in
index f9386c43973..fece5d26518 100644
--- a/libstdc++-v3/libsupc++/Makefile.in
+++ b/libstdc++-v3/libsupc++/Makefile.in
@@ -38,8 +38,23 @@ host_triplet = @host@
target_triplet = @target@
DIST_COMMON = $(top_srcdir)/fragment.am $(srcdir)/Makefile.in \
$(srcdir)/Makefile.am $(bits_HEADERS) $(std_HEADERS)
+
+# Once we have libvtv.so as a separate library, the stubs work will
+# go directly into libsupc++.
+# sources += \
+# vtv_stubs.cc
+
+# These will eventually go into libvtv.so
+# vtv_sources = \
+# vtv_rts.cc \
+# vtv_malloc.cc \
+# vtv_utils.cc
+
+# This is only temporary, until libvtv.so is created:
@ENABLE_VTABLE_VERIFY_TRUE@am__append_1 = \
-@ENABLE_VTABLE_VERIFY_TRUE@ vtv_fail.cc
+@ENABLE_VTABLE_VERIFY_TRUE@ vtv_rts.cc \
+@ENABLE_VTABLE_VERIFY_TRUE@ vtv_malloc.cc \
+@ENABLE_VTABLE_VERIFY_TRUE@ vtv_utils.cc
subdir = libsupc++
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -94,7 +109,8 @@ am__installdirs = "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(bitsdir)" \
"$(DESTDIR)$(stddir)"
LTLIBRARIES = $(noinst_LTLIBRARIES) $(toolexeclib_LTLIBRARIES)
libsupc___la_LIBADD =
-@ENABLE_VTABLE_VERIFY_TRUE@am__objects_1 = vtv_fail.lo
+@ENABLE_VTABLE_VERIFY_TRUE@am__objects_1 = vtv_rts.lo vtv_malloc.lo \
+@ENABLE_VTABLE_VERIFY_TRUE@ vtv_utils.lo
am__objects_2 = array_type_info.lo atexit_arm.lo atexit_thread.lo \
bad_alloc.lo bad_array_length.lo bad_array_new.lo bad_cast.lo \
bad_typeid.lo class_type_info.lo del_op.lo del_opnt.lo \
@@ -120,17 +136,10 @@ libsupc__convenience_la_LIBADD =
am_libsupc__convenience_la_OBJECTS = $(am__objects_2) $(am__objects_3)
libsupc__convenience_la_OBJECTS = \
$(am_libsupc__convenience_la_OBJECTS)
-libvtv_la_LIBADD =
-@ENABLE_VTABLE_VERIFY_TRUE@am__objects_4 = vtv_rts.lo vtv_malloc.lo \
-@ENABLE_VTABLE_VERIFY_TRUE@ vtv_utils.lo
-@ENABLE_VTABLE_VERIFY_TRUE@am_libvtv_la_OBJECTS = $(am__objects_4)
-libvtv_la_OBJECTS = $(am_libvtv_la_OBJECTS)
-@ENABLE_VTABLE_VERIFY_TRUE@am_libvtv_la_rpath = -rpath \
-@ENABLE_VTABLE_VERIFY_TRUE@ $(toolexeclibdir)
libvtv_stubs_la_LIBADD =
-@ENABLE_VTABLE_VERIFY_TRUE@am__objects_5 = vtv_stubs.lo
+@ENABLE_VTABLE_VERIFY_TRUE@am__objects_4 = vtv_stubs.lo
@ENABLE_VTABLE_VERIFY_TRUE@am_libvtv_stubs_la_OBJECTS = \
-@ENABLE_VTABLE_VERIFY_TRUE@ $(am__objects_5)
+@ENABLE_VTABLE_VERIFY_TRUE@ $(am__objects_4)
libvtv_stubs_la_OBJECTS = $(am_libvtv_stubs_la_OBJECTS)
@ENABLE_VTABLE_VERIFY_TRUE@am_libvtv_stubs_la_rpath = -rpath \
@ENABLE_VTABLE_VERIFY_TRUE@ $(toolexeclibdir)
@@ -147,7 +156,7 @@ CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
SOURCES = $(libsupc___la_SOURCES) $(libsupc__convenience_la_SOURCES) \
- $(libvtv_la_SOURCES) $(libvtv_stubs_la_SOURCES)
+ $(libvtv_stubs_la_SOURCES)
HEADERS = $(bits_HEADERS) $(std_HEADERS)
ETAGS = etags
CTAGS = ctags
@@ -358,11 +367,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
@@ -380,7 +393,8 @@ AM_CPPFLAGS = $(GLIBCXX_INCLUDES)
# Need this library to both be part of libstdc++.a, and installed
# separately too.
# 1) separate libsupc++.la
-@ENABLE_VTABLE_VERIFY_TRUE@toolexeclib_LTLIBRARIES = libsupc++.la libvtv.la libvtv_stubs.la
+#toolexeclib_LTLIBRARIES = libsupc++.la libvtv.la
+@ENABLE_VTABLE_VERIFY_TRUE@toolexeclib_LTLIBRARIES = libsupc++.la libvtv_stubs.la
# 2) integrated libsupc++convenience.la that is to be a part of libstdc++.a
noinst_LTLIBRARIES = libsupc++convenience.la
std_HEADERS = \
@@ -408,15 +422,16 @@ sources = array_type_info.cc atexit_arm.cc atexit_thread.cc \
pointer_type_info.cc pure.cc si_class_type_info.cc tinfo.cc \
tinfo2.cc vec.cc vmi_class_type_info.cc vterminate.cc \
$(am__append_1)
-@ENABLE_VTABLE_VERIFY_TRUE@vtv_sources = \
-@ENABLE_VTABLE_VERIFY_TRUE@ vtv_rts.cc \
-@ENABLE_VTABLE_VERIFY_TRUE@ vtv_malloc.cc \
-@ENABLE_VTABLE_VERIFY_TRUE@ vtv_utils.cc
+# This is only temporary, until libvtv.so is created:
@ENABLE_VTABLE_VERIFY_TRUE@vtv_stubs_sources = \
@ENABLE_VTABLE_VERIFY_TRUE@ vtv_stubs.cc
-@ENABLE_VTABLE_VERIFY_TRUE@libvtv_la_SOURCES = $(vtv_sources)
+
+# These would be for libvtv.so
+# libvtv_la_SOURCES = $(vtv_sources)
+
+# This is only temporary, until libvtv.so is created.
@ENABLE_VTABLE_VERIFY_TRUE@libvtv_stubs_la_SOURCES = $(vtv_stubs_sources)
libsupc___la_SOURCES = $(sources) $(c_sources)
libsupc__convenience_la_SOURCES = $(sources) $(c_sources)
@@ -431,6 +446,11 @@ AM_CXXFLAGS = \
$(XTEMPLATE_FLAGS) \
$(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
+AM_CXXFLAGS_SHARED = \
+ $(glibcxx_compiler_shared_flag) \
+ $(XTEMPLATE_FLAGS) \
+ $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
+
AM_MAKEFLAGS = \
"gxx_include_dir=$(gxx_include_dir)"
@@ -483,6 +503,12 @@ LTCXXCOMPILE = \
--mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(EXTRA_CXX_FLAGS)
+LTCXXCOMPILE_S = \
+ $(LIBTOOL) --tag CXX --tag enable-shared \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CXX) $(TOPLEVEL_INCLUDES) -DSHARED \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(EXTRA_CXX_FLAGS)
+
LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
# 3) We'd have a problem when building the shared libstdc++ object if
@@ -497,6 +523,10 @@ CXXLINK = \
--mode=link $(CXX) \
$(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LTLDFLAGS) -o $@
+CXXLINK_SHARED = \
+ $(CXX) \
+ $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS_SHARED) $(LTLDFLAGS) -o $@
+
# Install notes
# We have to have rules modified from the default to counteract SUN make
@@ -581,8 +611,6 @@ libsupc++.la: $(libsupc___la_OBJECTS) $(libsupc___la_DEPENDENCIES)
$(CXXLINK) $(am_libsupc___la_rpath) $(libsupc___la_OBJECTS) $(libsupc___la_LIBADD) $(LIBS)
libsupc++convenience.la: $(libsupc__convenience_la_OBJECTS) $(libsupc__convenience_la_DEPENDENCIES)
$(CXXLINK) $(libsupc__convenience_la_OBJECTS) $(libsupc__convenience_la_LIBADD) $(LIBS)
-libvtv.la: $(libvtv_la_OBJECTS) $(libvtv_la_DEPENDENCIES)
- $(CXXLINK) $(am_libvtv_la_rpath) $(libvtv_la_OBJECTS) $(libvtv_la_LIBADD) $(LIBS)
libvtv_stubs.la: $(libvtv_stubs_la_OBJECTS) $(libvtv_stubs_la_DEPENDENCIES)
$(CXXLINK) $(am_libvtv_stubs_la_rpath) $(libvtv_stubs_la_OBJECTS) $(libvtv_stubs_la_LIBADD) $(LIBS)
diff --git a/libstdc++-v3/libsupc++/vtv_fail.cc b/libstdc++-v3/libsupc++/vtv_fail.cc
deleted file mode 100644
index 4f183d8cac2..00000000000
--- a/libstdc++-v3/libsupc++/vtv_fail.cc
+++ /dev/null
@@ -1,233 +0,0 @@
-/* Copyright (C) 2012-2013
- Free Software Foundation
-
- 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 3, 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.
-
- Under Section 7 of GPL version 3, you are granted additional
- permissions described in the GCC Runtime Library Exception, version
- 3.1, as published by the Free Software Foundation.
-
- You should have received a copy of the GNU General Public License and
- a copy of the GCC Runtime Library Exception along with this program;
- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
- <http://www.gnu.org/licenses/>. */
-
-/* This file is part of the vtable security feature implementation.
- The vtable security feature is designed to detect when a virtual
- call is about to be made through an invalid vtable pointer
- (possibly due to data corruption or malicious attacks).
-
- This file also contains the failure functions that get called when
- a vtable pointer is not found in the data set. Two particularly
- important functions are __vtv_verify_fail and __vtv_really_fail.
- They are both externally visible. __vtv_verify_fail is defined in
- such a way that it can be replaced by a programmer, if desired. It
- is the function that __VLTVerifyVtablePointer calls if it can't
- find the pointer in the data set. Allowing the programmer to
- overwrite this function means that he/she can do some alternate
- verification, including NOT failing in certain specific cases, if
- desired. This may be the case if the programmer has to deal wtih
- unverified third party software, for example. __vtv_really_fail is
- available for the programmer to call from his version of
- __vtv_verify_fail, if he decides the failure is real.
-
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <execinfo.h>
-#include <unistd.h>
-
-#include "vtv_utils.h"
-#include "vtv_fail.h"
-
-/* This is used to disable aborts for debugging purposes. */
-bool vtv_no_abort = false;
-
-
-extern "C" {
-
- /* __fortify_fail is a function in glibc that calls __libc_message,
- causing it to print out a program termination error message
- (including the name of the binary being terminated), a stack
- trace where the error occurred, and a memory map dump. Ideally
- we would have called __libc_message directly, but that function
- does not appear to be accessible to functions outside glibc,
- whereas __fortify_fail is. We call __fortify_fail from
- __vtv_really_fail. We looked at calling __libc_fatal, which is
- externally accessible, but it does not do the back trace and
- memory dump. */
-
- extern void __fortify_fail (const char *) __attribute__((noreturn));
-
-} /* extern "C" */
-
-const unsigned long SET_HANDLE_HANDLE_BIT = 0x2;
-
-/* Instantiate the template classes (in vtv_set.h) for our particular
- hash table needs. */
-typedef void * vtv_set_handle;
-typedef vtv_set_handle * vtv_set_handle_handle;
-
-static int vtv_failures_log_fd = -1;
-
-/* Open error logging file, if not already open, and write vtable
- verification failure messages (LOG_MSG) to the log file. Also
- generate a backtrace in the log file, if GENERATE_BACKTRACE is
- set. */
-
-static void
-log_error_message (const char *log_msg, bool generate_backtrace)
-{
- if (vtv_failures_log_fd == -1)
- vtv_failures_log_fd = vtv_open_log ("vtable_verification_failures.log");
-
- if (vtv_failures_log_fd == -1)
- return;
-
- vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg);
-
- if (generate_backtrace)
- {
-#define STACK_DEPTH 20
- void *callers[STACK_DEPTH];
- int actual_depth = backtrace (callers, STACK_DEPTH);
- backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd);
- }
-}
-
-/* In the case where a vtable map variable is the only instance of the
- variable we have seen, it points directly to the set of valid
- vtable pointers. All subsequent instances of the 'same' vtable map
- variable point to the first vtable map variable. This function,
- given a vtable map variable PTR, checks a bit to see whether it's
- pointing directly to the data set or to the first vtable map
- variable. */
-
-static inline bool
-is_set_handle_handle (void * ptr)
-{
- return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT)
- == SET_HANDLE_HANDLE_BIT;
-}
-
-/* Returns the actual pointer value of a vtable map variable, PTR (see
- comments for is_set_handle_handle for more details). */
-
-static inline vtv_set_handle *
-ptr_from_set_handle_handle (void * ptr)
-{
- return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT);
-}
-
-/* Given a vtable map variable, PTR, this function sets the bit that
- says this is the second (or later) instance of a vtable map
- variable. */
-
-static inline vtv_set_handle_handle
-set_handle_handle (vtv_set_handle * ptr)
-{
- return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT);
-}
-
-/* This function is called from __VLTVerifyVtablePointerDebug; it
- sends as much debugging information as it can to the error log
- file, then calls __vtv_verify_fail. SET_HANDLE_PTR is the pointer
- to the set of valid vtable pointers, VTBL_PTR is the pointer that
- was not found in the set, and DEBUG_MSG is the message to be
- written to the log file before failing. n */
-
-void
-__vtv_verify_fail_debug (void **set_handle_ptr, const void *vtbl_ptr,
- const char *debug_msg)
-{
- log_error_message (debug_msg, false);
-
- /* Call the public interface in case it has been overwritten by
- user. */
- __vtv_verify_fail (set_handle_ptr, vtbl_ptr);
-
- log_error_message ("Returned from __vtv_verify_fail."
- " Secondary verification succeeded.\n", false);
-}
-
-/* This function calls __fortify_fail with a FAILURE_MSG and then
- calls abort. */
-
-void
-__vtv_really_fail (const char *failure_msg)
-{
- __fortify_fail (failure_msg);
-
- /* We should never get this far; __fortify_fail calls __libc_message
- which prints out a back trace and a memory dump and then is
- supposed to call abort, but let's play it safe anyway and call abort
- ourselves. */
- abort ();
-}
-
-/* This function takes an error MSG, a vtable map variable
- (DATA_SET_PTR) and a vtable pointer (VTBL_PTR). It is called when
- an attempt to verify VTBL_PTR with the set pointed to by
- DATA_SET_PTR failed. It outputs a failure message with the
- addresses involved, and calls __vtv_really_fail. */
-
-static void
-vtv_fail (const char *msg, void **data_set_ptr, const void *vtbl_ptr)
-{
- char buffer[128];
- int buf_len;
- const char *format_str =
- "*** Unable to verify vtable pointer (%p) in set (%p) *** \n";
-
- snprintf (buffer, sizeof (buffer), format_str, vtbl_ptr,
- is_set_handle_handle(*data_set_ptr) ?
- ptr_from_set_handle_handle (*data_set_ptr) :
- *data_set_ptr);
- buf_len = strlen (buffer);
- /* Send this to to stderr. */
- write (2, buffer, buf_len);
-
- if (!vtv_no_abort)
- __vtv_really_fail (msg);
-}
-
-/* Send information about what we were trying to do when verification
- failed to the error log, then call vtv_fail. This function can be
- overwritten/replaced by the user, to implement a secondary
- verification function instead. DATA_SET_PTR is the vtable map
- variable used for the failed verification, and VTBL_PTR is the
- vtable pointer that was not found in the set. */
-
-void
-__vtv_verify_fail (void **data_set_ptr, const void *vtbl_ptr)
-{
- char log_msg[256];
- snprintf (log_msg, sizeof (log_msg), "Looking for vtable %p in set %p.\n",
- vtbl_ptr,
- is_set_handle_handle (*data_set_ptr) ?
- ptr_from_set_handle_handle (*data_set_ptr) :
- *data_set_ptr);
- log_error_message (log_msg, false);
-
- const char *format_str =
- "*** Unable to verify vtable pointer (%p) in set (%p) *** \n";
- snprintf (log_msg, sizeof (log_msg), format_str, vtbl_ptr, *data_set_ptr);
- log_error_message (log_msg, false);
- log_error_message (" Backtrace: \n", true);
-
- const char *fail_msg = "Potential vtable pointer corruption detected!!\n";
- vtv_fail (fail_msg, data_set_ptr, vtbl_ptr);
-}
-
diff --git a/libstdc++-v3/libsupc++/vtv_fail.h b/libstdc++-v3/libsupc++/vtv_fail.h
index ff525b919a9..30741616a46 100644
--- a/libstdc++-v3/libsupc++/vtv_fail.h
+++ b/libstdc++-v3/libsupc++/vtv_fail.h
@@ -32,7 +32,8 @@
attempt to rewrite __vtv_really_fail. */
extern void
-__vtv_really_fail (const char *fail_msg) __attribute__ ((noreturn));
+__vtv_really_fail (const char *fail_msg)
+ __attribute__ ((visibility ("default"), noreturn, nothrow));
/* __vtv_verify_fail is the function that gets called if the vtable
verification code discovers a vtable pointer that it cannot verify
@@ -48,11 +49,11 @@ __vtv_really_fail (const char *fail_msg) __attribute__ ((noreturn));
extern void
__vtv_verify_fail (void **data_set_ptr, const void *vtbl_pointer)
- __attribute__((visibility ("default")));
+ __attribute__((visibility ("default"), nothrow));
extern void
__vtv_verify_fail_debug (void **data_set_ptr, const void *vtbl_pointer,
const char *debug_msg)
- __attribute__((visibility ("default")));
+ __attribute__((visibility ("default"), nothrow));
#endif /* _VTV_FAIL_H */
diff --git a/libstdc++-v3/libsupc++/vtv_init.cc b/libstdc++-v3/libsupc++/vtv_init.cc
deleted file mode 100644
index d902d8e5653..00000000000
--- a/libstdc++-v3/libsupc++/vtv_init.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Copyright (C) 2012-2013
- Free Software Foundation
-
- 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 3, 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.
-
- Under Section 7 of GPL version 3, you are granted additional
- permissions described in the GCC Runtime Library Exception, version
- 3.1, as published by the Free Software Foundation.
-
- You should have received a copy of the GNU General Public License and
- a copy of the GCC Runtime Library Exception along with this program;
- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
- <http://www.gnu.org/licenses/>. */
-
-
-/* This file contains all the definitions that go into the libvtv_init
- library, which is part of the vtable verification feature. This
- library should contain exactly two functions (__VLTunprotect and
- __VLTprotect) and one global variable definition
- (__vtv_defined_in_vtv_init_lib). Any program that was compiled
- with the option "-fvtable-verify=std" MUST also be linked with
- libvtv_init, because the two functions defined here are used by the
- vtable verification code. The reason they are in a separate
- library rather than in libstdc++ with all the rest of the vtable
- verification runtime code is as follows. Each .o file that was
- compiled with vtable verification will contain calls into the
- runtime (made from constructor initialization functions) to build
- the data structures needed for verification. At all times except
- when they are being constructed, these data structures need to be
- in protected memory, so that attackers cannot corrupt them.
- __VLTunprotect sets the memory containing these data structures to
- be writable, for updates. __VLTprotect makes the memory read-only,
- for all other times. This memory protection and unprotection is
- done via calls to mprotect, which are costly. So instead of
- calling __VLTunprotect and __VLTprotect once per object file we
- want to call them once per executable. Therefore instead of
- putting calls to them directly into each object file, we put the
- calls to them only in __VLTRegisterPair, in the libstdc++ library.
- We give __VLTunprotect an initialization priority to make it run
- before all of our data structure construction functions, and we
- give __VLTprotect an initialization priority to make it run after
- all of our data structure constructiion functions. We put them
- into a separate library and link that library with the
- "--whole-archive" linker option, to make sure that both functions get
- linked in (since the actual calls to them are in the libstdc++
- runtime). We can't put them into libstdc++ because linking
- libstdc++ with "--whole-archive" is probably not a good idea.
-
- The __vtv_defined_in_vtv_lib variable is referenced, but not
- defined, in the constructor initialization functions where we have
- the calls to build our data structures. The purpose of this
- variable is to cause a linker error to occur if the programmer
- compiled with -fvtable-verify=std and did not link with the vtv_int
- library (better a link-time error than a run-time error). */
-
-#ifndef __cplusplus
-#error "This file must be compiled with a C++ compiler"
-#endif
-
-#include "../../include/vtv-change-permission.h"
-#include "vtv_rts.h"
-
-/* Define this dummy symbol to detect at link time the cases where
- user is compiling with -fvtable-verify=std and not linking with the
- vtv_init library. Note that the visibility needs to be hidden. Each
- object module is supposed to link with the vtv_init library and we
- don't want this definition to come from a different library */
-unsigned int
-__vtv_defined_in_vtv_init_lib __attribute__ ((visibility ("hidden"))) = 0;
-
-
-__attribute__ ((constructor(98))) void
-__VLTunprotect (void)
-{
- __VLTChangePermission (__VLTP_READ_WRITE);
-}
-
-__attribute__ ((constructor(100))) void
-__VLTprotect (void)
-{
- __VLTChangePermission (__VLTP_READ_ONLY);
-}
diff --git a/libstdc++-v3/libsupc++/vtv_malloc.cc b/libstdc++-v3/libsupc++/vtv_malloc.cc
index f50ee7c9fad..f4725c20268 100644
--- a/libstdc++-v3/libsupc++/vtv_malloc.cc
+++ b/libstdc++-v3/libsupc++/vtv_malloc.cc
@@ -55,20 +55,18 @@ unsigned int long long mprotect_cycles = 0;
/* Put the following variables in our ".vtable_map_vars" section so
that they are protected. They are explicitly unprotected and
- protected again by calls to VTV_unprotect and VTV_protect */
+ protected again by calls to __vtv_unprotect and __vtv_protect */
-static struct obstack VTV_obstack VTV_PROTECTED_VAR;
+static struct obstack vtv_obstack VTV_PROTECTED_VAR;
static void *current_chunk VTV_PROTECTED_VAR = 0;
static size_t current_chunk_size VTV_PROTECTED_VAR = 0;
static int malloc_initialized VTV_PROTECTED_VAR = 0;
-static bool debug_malloc = false;
-
/* The function goes through and counts all the pages we have allocated
so far. It returns the page count. */
int
-VTV_count_mmapped_pages (void)
+__vtv_count_mmapped_pages (void)
{
int count = 0;
struct _obstack_chunk * ci = (struct _obstack_chunk *) current_chunk;
@@ -130,14 +128,15 @@ change_protections_on_data_chunks (int protection_flag)
num_pages_protected += (total_size + VTV_PAGE_SIZE - 1)/ VTV_PAGE_SIZE;
}
- if (debug_malloc)
+#ifdef VTV_DEBUG
VTV_malloc_dump_stats ();
+#endif
}
/* This function makes all of our allocated pages read-only. */
void
-VTV_malloc_protect (void)
+__vtv_malloc_protect (void)
{
change_protections_on_data_chunks (PROT_READ);
}
@@ -145,7 +144,7 @@ VTV_malloc_protect (void)
/* This function makes all of our allocated pages read-write. */
void
-VTV_malloc_unprotect (void)
+__vtv_malloc_unprotect (void)
{
change_protections_on_data_chunks (PROT_READ | PROT_WRITE);
}
@@ -185,7 +184,7 @@ obstack_chunk_free (size_t size)
memory allocation scheme. */
void
-VTV_malloc_init (void)
+__vtv_malloc_init (void)
{
/* Make sure we only execute the main body of this function ONCE. */
if (malloc_initialized)
@@ -194,14 +193,14 @@ VTV_malloc_init (void)
if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE))
VTV_error ();
- obstack_chunk_size (&VTV_obstack) = VTV_PAGE_SIZE;
- obstack_alignment_mask (&VTV_obstack) = sizeof (long) - 1;
+ obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE;
+ obstack_alignment_mask (&vtv_obstack) = sizeof (long) - 1;
/* We guarantee that the obstack alloc failed handler will never be
called because in case the allocation of the chunk fails, it will
never return */
obstack_alloc_failed_handler = NULL;
- obstack_init (&VTV_obstack);
+ obstack_init (&vtv_obstack);
malloc_initialized = 1;
}
@@ -209,16 +208,16 @@ VTV_malloc_init (void)
the requested number of bytes to be allocated/ */
void *
-VTV_malloc (size_t size)
+__vtv_malloc (size_t size)
{
- return obstack_alloc (&VTV_obstack, size);
+ return obstack_alloc (&vtv_obstack, size);
}
/* This is our external interface for memory deallocation. */
void
-VTV_free (void *)
+__vtv_free (void *)
{
/* Do nothing. We dont care about recovering unneded memory at this
time. */
@@ -228,7 +227,7 @@ VTV_free (void *)
/* This is a debugging function tat collects statistics about our
memory allocation. */
void
-VTV_malloc_stats (void)
+__vtv_malloc_stats (void)
{
int count = 0;
struct _obstack_chunk * ci = (struct _obstack_chunk *) current_chunk;
@@ -238,7 +237,7 @@ VTV_malloc_stats (void)
ci = ci->prev;
}
fprintf (stderr,
- "VTV_malloc_stats:\n Page Size = %lu bytes\n "
+ "__vtv_malloc_stats:\n Page Size = %lu bytes\n "
"Number of pages = %d\n", VTV_PAGE_SIZE, count);
}
@@ -246,12 +245,12 @@ VTV_malloc_stats (void)
statistics to a log file. */
void
-VTV_malloc_dump_stats (void)
+__vtv_malloc_dump_stats (void)
{
static int fd = -1;
if (fd == -1)
- fd = vtv_open_log ("vtv_mem_protection.log");
+ fd = __vtv_open_log ("vtv_mem_protection.log");
if (fd == -1)
return;
@@ -263,5 +262,5 @@ VTV_malloc_dump_stats (void)
ci = ci->prev;
}
- vtv_add_to_log (fd, "VTV_malloc_protect protected=%d pages\n", count);
+ __vtv_add_to_log (fd, "__vtv_malloc_protect protected=%d pages\n", count);
}
diff --git a/libstdc++-v3/libsupc++/vtv_malloc.h b/libstdc++-v3/libsupc++/vtv_malloc.h
index 2abbb5cd88c..55f5fe8022b 100644
--- a/libstdc++-v3/libsupc++/vtv_malloc.h
+++ b/libstdc++-v3/libsupc++/vtv_malloc.h
@@ -86,13 +86,13 @@ extern unsigned long long regpair_cycles;
/* Function declarations. */
-extern void VTV_malloc_init (void);
-extern void *VTV_malloc (size_t size);
-extern void VTV_free (void * ptr);
-extern void VTV_malloc_protect (void);
-extern void VTV_malloc_unprotect (void);
-extern void VTV_malloc_stats (void);
-extern void VTV_malloc_dump_stats (void);
-extern int VTV_count_mmapped_pages (void);
+extern void __vtv_malloc_init (void);
+extern void *__vtv_malloc (size_t size) __attribute__ ((malloc));
+extern void __vtv_free (void * ptr);
+extern void __vtv_malloc_protect (void);
+extern void __vtv_malloc_unprotect (void);
+extern void __vtv_malloc_stats (void);
+extern void __vtv_malloc_dump_stats (void);
+extern int __vtv_count_mmapped_pages (void);
#endif /* vtv_malloc.h */
diff --git a/libstdc++-v3/libsupc++/vtv_map.h b/libstdc++-v3/libsupc++/vtv_map.h
index a2043cf1612..ec058f845f7 100644
--- a/libstdc++-v3/libsupc++/vtv_map.h
+++ b/libstdc++-v3/libsupc++/vtv_map.h
@@ -277,7 +277,7 @@ insert_only_hash_map <T, Alloc>::put_internal (
}
template <typename T, typename Alloc>
-const typename insert_only_hash_map <T, Alloc>::value_type*
+inline const typename insert_only_hash_map <T, Alloc>::value_type*
insert_only_hash_map <T, Alloc>::get (const insert_only_hash_map::key_type *k)
const
{
@@ -298,7 +298,7 @@ insert_only_hash_map <T, Alloc>::get (const insert_only_hash_map::key_type *k)
}
template <typename T, typename Alloc>
-bool
+inline bool
insert_only_hash_map <T, Alloc>::key_type::equals (
const typename insert_only_hash_map <T, Alloc>::key_type *k) const
{
diff --git a/libstdc++-v3/libsupc++/vtv_rts.cc b/libstdc++-v3/libsupc++/vtv_rts.cc
index eb82eb42c8e..cb2b8d27b10 100644
--- a/libstdc++-v3/libsupc++/vtv_rts.cc
+++ b/libstdc++-v3/libsupc++/vtv_rts.cc
@@ -143,7 +143,22 @@
#include "../../include/vtv-change-permission.h"
-bool vtv_debug = false;
+extern "C" {
+
+ /* __fortify_fail is a function in glibc that calls __libc_message,
+ causing it to print out a program termination error message
+ (including the name of the binary being terminated), a stack
+ trace where the error occurred, and a memory map dump. Ideally
+ we would have called __libc_message directly, but that function
+ does not appear to be accessible to functions outside glibc,
+ whereas __fortify_fail is. We call __fortify_fail from
+ __vtv_really_fail. We looked at calling __libc_fatal, which is
+ externally accessible, but it does not do the back trace and
+ memory dump. */
+
+ extern void __fortify_fail (const char *) __attribute__((noreturn));
+
+} /* extern "C" */
/* The following variables are used only for debugging and performance
tuning purposes. Therefore they do not need to be "protected".
@@ -174,12 +189,16 @@ static const int debug_functions = 0;
static const int debug_init = 0;
static const int debug_verify_vtable = 0;
+#ifdef VTV_DEBUG
+static const int debug_functions = 1;
+static const int debug_init = 1;
+static const int debug_verify_vtable = 1;
+#endif
/* Global file descriptor variables for logging, tracing and debugging. */
static int init_log_fd = -1;
static int verify_vtable_log_fd = -1;
-static int vtv_failures_log_fd = -1;
/* This holds a formatted error logging message, to be written to the
vtable verify failures log. */
@@ -193,6 +212,10 @@ static __gthread_mutex_t change_permissions_lock;
#endif
+#ifndef VTV_STATS
+#define VTV_STATS 0
+#endif
+
#if VTV_STATS
static inline unsigned long long
@@ -272,7 +295,7 @@ struct vptr_set_alloc
void *
operator() (size_t n) const
{
- return VTV_malloc (n);
+ return __vtv_malloc (n);
}
};
@@ -373,9 +396,9 @@ log_memory_protection_data (char *message)
static int log_fd = -1;
if (log_fd == -1)
- log_fd = vtv_open_log ("vtv_memory_protection_data_%d.log");
+ log_fd = __vtv_open_log ("vtv_memory_protection_data_%d.log");
- vtv_add_to_log (log_fd, "%s", message);
+ __vtv_add_to_log (log_fd, "%s", message);
}
static void
@@ -444,7 +467,6 @@ read_section_offset_and_length (struct dl_phdr_info *info,
if (fd != -1)
{
-
/* Find the section header information in the file. */
ElfW (Half) strtab_idx = ehdr_info->e_shstrndx;
ElfW (Shdr) shstrtab;
@@ -456,6 +478,14 @@ read_section_offset_and_length (struct dl_phdr_info *info,
ElfW (Shdr) sect_hdr;
+ /* This code will be needed once we have crated libvtv.so. */
+ bool is_libvtv = false;
+
+ /*
+ if (strstr (info->dlpi_name, "libvtv.so"))
+ is_libvtv = true;
+ */
+
/* Loop through all the section headers, looking for one whose
name is ".vtable_map_vars". */
@@ -480,7 +510,10 @@ read_section_offset_and_length (struct dl_phdr_info *info,
/* We found the section; get its load offset and
size. */
*sect_offset = sect_hdr.sh_addr;
- *sect_len = sect_hdr.sh_size - VTV_PAGE_SIZE;
+ if (!is_libvtv)
+ *sect_len = sect_hdr.sh_size - VTV_PAGE_SIZE;
+ else
+ *sect_len = sect_hdr.sh_size;
found = true;
}
}
@@ -516,7 +549,7 @@ read_section_offset_and_length (struct dl_phdr_info *info,
}
/* This is the callback function used by dl_iterate_phdr (which is
- called from VTV_unprotect_vtable_vars and VTV_protect_vtable_vars).
+ called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars).
It attempts to find the binary file on disk for the INFO record
that dl_iterate_phdr passes in; open the binary file, and read its
section header information. If the file contains a
@@ -613,7 +646,8 @@ dl_iterate_phdr_callback (struct dl_phdr_info *info, size_t unused, void *data)
}
}
increment_num_calls (&num_calls_to_mprotect);
- num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) / VTV_PAGE_SIZE;
+ /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) / VTV_PAGE_SIZE; */
+ num_pages_protected += (map_sect_len + 4096 - 1) / 4096;
}
return 0;
@@ -641,10 +675,12 @@ dl_iterate_phdr_callback (struct dl_phdr_info *info, size_t unused, void *data)
static void
change_protections_on_phdr_cache (int protection_flag)
{
- ElfW (Addr) low_address = (ElfW (Addr)) &(vtv_sect_info_cache);
+ char * low_address = (char *) &(vtv_sect_info_cache);
size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data);
- low_address = low_address & ~(VTV_PAGE_SIZE -1);
+ low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1));
+ size_t protection_size =
+ (char *) &vtv_sect_info_cache - low_address + cache_size;
if (mprotect ((void *) low_address, cache_size, protection_flag) == -1)
VTV_error ();
@@ -655,7 +691,7 @@ change_protections_on_phdr_cache (int protection_flag)
into relro sections */
static void
-VTV_unprotect_vtable_vars (void)
+vtv_unprotect_vtable_vars (void)
{
int mprotect_flags;
@@ -669,7 +705,7 @@ VTV_unprotect_vtable_vars (void)
into relro sections */
static void
-VTV_protect_vtable_vars (void)
+vtv_protect_vtable_vars (void)
{
int mprotect_flags;
@@ -722,10 +758,10 @@ log_set_stats (void)
{
#if HASHTABLE_STATS
if (set_log_fd == -1)
- set_log_fd = vtv_open_log ("vtv_set_stats.log");
+ set_log_fd = __vtv_open_log ("vtv_set_stats.log");
- vtv_add_to_log (set_log_fd, "---\n%s\n",
- insert_only_hash_tables_stats().c_str());
+ __vtv_add_to_log (set_log_fd, "---\n%s\n",
+ insert_only_hash_tables_stats().c_str());
#endif
}
@@ -767,9 +803,9 @@ __VLTChangePermission (int perm)
module that is not the first load module. */
__gthread_mutex_lock (&change_permissions_lock);
- VTV_unprotect_vtable_vars ();
- VTV_malloc_init ();
- VTV_malloc_unprotect ();
+ vtv_unprotect_vtable_vars ();
+ __vtv_malloc_init ();
+ __vtv_malloc_unprotect ();
}
else if (perm == __VLTP_READ_ONLY)
@@ -777,8 +813,8 @@ __VLTChangePermission (int perm)
if (debug_hash)
log_set_stats();
- VTV_malloc_protect ();
- VTV_protect_vtable_vars ();
+ __vtv_malloc_protect ();
+ vtv_protect_vtable_vars ();
__gthread_mutex_unlock (&change_permissions_lock);
}
@@ -798,7 +834,7 @@ struct insert_only_hash_map_allocator
void *
alloc (size_t n) const
{
- return VTV_malloc (n);
+ return __vtv_malloc (n);
}
/* P points to the memory to be deallocated; N is the number of
@@ -806,7 +842,7 @@ struct insert_only_hash_map_allocator
void
dealloc (void *p, size_t n) const
{
- VTV_free (p);
+ __vtv_free (p);
}
};
@@ -857,31 +893,6 @@ set_handle_handle (vtv_set_handle * ptr)
return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT);
}
-/* Open error logging file, if not already open, and write vtable
- verification failure messages (LOG_MSG) to the log file. Also
- generate a backtrace in the log file, if GENERATE_BACKTRACE is
- set. */
-
-static void
-log_error_message (const char *log_msg, bool generate_backtrace)
-{
- if (vtv_failures_log_fd == -1)
- vtv_failures_log_fd = vtv_open_log ("vtable_verification_failures.log");
-
- if (vtv_failures_log_fd == -1)
- return;
-
- vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg);
-
- if (generate_backtrace)
- {
-#define STACK_DEPTH 20
- void *callers[STACK_DEPTH];
- int actual_depth = backtrace (callers, STACK_DEPTH);
- backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd);
- }
-}
-
static inline void
register_set_common (void **set_handle_ptr, size_t num_args,
void **vtable_ptr_array, bool debug)
@@ -933,12 +944,12 @@ register_pair_common (void **set_handle_ptr, const void *vtable_ptr,
if (debug && debug_init)
{
if (init_log_fd == -1)
- init_log_fd = vtv_open_log("vtv_init.log");
+ init_log_fd = __vtv_open_log("vtv_init.log");
- vtv_add_to_log(init_log_fd,
- "Registered %s : %s (%p) 2 level deref = %s\n",
- set_symbol_name, vtable_name, vtbl_ptr,
- is_set_handle_handle(*set_handle_ptr) ? "yes" : "no" );
+ __vtv_add_to_log(init_log_fd,
+ "Registered %s : %s (%p) 2 level deref = %s\n",
+ set_symbol_name, vtable_name, vtbl_ptr,
+ is_set_handle_handle(*set_handle_ptr) ? "yes" : "no" );
}
}
@@ -986,7 +997,7 @@ init_set_symbol_debug (void **set_handle_ptr, const void *set_symbol_key,
"*** Found non-NULL local set ptr %p missing for symbol"
" %.*s",
*handle_ptr, symbol_key_ptr->n, symbol_key_ptr->bytes);
- log_error_message (buffer, true);
+ __vtv_log_verification_failure (buffer, true);
VTV_DEBUG_ASSERT (0);
}
}
@@ -1000,7 +1011,7 @@ init_set_symbol_debug (void **set_handle_ptr, const void *set_symbol_key,
"for symbol %.*s",
*handle_ptr, *map_value_ptr,
symbol_key_ptr->n, symbol_key_ptr->bytes);
- log_error_message (buffer, true);
+ __vtv_log_verification_failure (buffer, true);
VTV_DEBUG_ASSERT (0);
}
else if (*handle_ptr == NULL)
@@ -1046,7 +1057,7 @@ init_set_symbol_debug (void **set_handle_ptr, const void *set_symbol_key,
in case the memory where this comes from gets unmapped by
dlclose. */
size_t map_key_len = symbol_key_ptr->n + sizeof (vtv_symbol_key);
- void *map_key = VTV_malloc (map_key_len);
+ void *map_key = __vtv_malloc (map_key_len);
memcpy (map_key, symbol_key_ptr, map_key_len);
@@ -1064,14 +1075,14 @@ init_set_symbol_debug (void **set_handle_ptr, const void *set_symbol_key,
if (debug_init)
{
if (init_log_fd == -1)
- init_log_fd = vtv_open_log ("vtv_init.log");
-
- vtv_add_to_log (init_log_fd,
- "Init handle:%p for symbol:%.*s hash:%u size_hint:%lu"
- "number of symbols:%lu \n",
- set_handle_ptr, symbol_key_ptr->n,
- symbol_key_ptr->bytes, symbol_key_ptr->hash, size_hint,
- vtv_symbol_unification_map->size ());
+ init_log_fd = __vtv_open_log ("vtv_init.log");
+
+ __vtv_add_to_log (init_log_fd,
+ "Init handle:%p for symbol:%.*s hash:%u size_hint:%lu"
+ "number of symbols:%lu \n",
+ set_handle_ptr, symbol_key_ptr->n,
+ symbol_key_ptr->bytes, symbol_key_ptr->hash, size_hint,
+ vtv_symbol_unification_map->size ());
}
}
@@ -1165,10 +1176,10 @@ __VLTVerifyVtablePointerDebug (void **set_handle_ptr, const void *vtable_ptr,
if (debug_verify_vtable)
{
if (verify_vtable_log_fd == -1)
- vtv_open_log ("vtv_verify_vtable.log");
- vtv_add_to_log (verify_vtable_log_fd,
- "Verified %s %s value = %p\n",
- set_symbol_name, vtable_name, vtable_ptr);
+ __vtv_open_log ("vtv_verify_vtable.log");
+ __vtv_add_to_log (verify_vtable_log_fd,
+ "Verified %s %s value = %p\n",
+ set_symbol_name, vtable_name, vtable_ptr);
}
}
else
@@ -1251,7 +1262,7 @@ init_set_symbol (void **set_handle_ptr, const void *set_symbol_key,
in case the memory where this comes from gets unmapped by
dlclose. */
size_t map_key_len = symbol_key_ptr->n + sizeof (vtv_symbol_key);
- void * map_key = VTV_malloc (map_key_len);
+ void * map_key = __vtv_malloc (map_key_len);
memcpy (map_key, symbol_key_ptr, map_key_len);
s2s::value_type * value_ptr;
@@ -1393,31 +1404,122 @@ count_all_pages (void)
page_count_2 = 0;
dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags);
- page_count_2 += VTV_count_mmapped_pages ();
+ page_count_2 += __vtv_count_mmapped_pages ();
}
void
__VLTDumpStats (void)
{
- int log_fd = vtv_open_log ("vtv-runtime-stats.log");
+ int log_fd = __vtv_open_log ("vtv-runtime-stats.log");
if (log_fd != -1)
{
count_all_pages ();
- vtv_add_to_log (log_fd,
- "Calls: mprotect (%d) regset (%d) regpair (%d)"
- " verify_vtable (%d)\n",
- num_calls_to_mprotect, num_calls_to_regset,
- num_calls_to_regpair, num_calls_to_verify_vtable);
- vtv_add_to_log (log_fd,
- "Cycles: mprotect (%lld) regset (%lld) "
- "regpair (%lld) verify_vtable (%lld)\n",
- mprotect_cycles, regset_cycles, regpair_cycles,
- verify_vtable_cycles);
- vtv_add_to_log (log_fd,
- "Pages protected (1): %d\n", num_pages_protected);
- vtv_add_to_log (log_fd, "Pages protected (2): %d\n", page_count_2);
+ __vtv_add_to_log (log_fd,
+ "Calls: mprotect (%d) regset (%d) regpair (%d)"
+ " verify_vtable (%d)\n",
+ num_calls_to_mprotect, num_calls_to_regset,
+ num_calls_to_regpair, num_calls_to_verify_vtable);
+ __vtv_add_to_log (log_fd,
+ "Cycles: mprotect (%lld) regset (%lld) "
+ "regpair (%lld) verify_vtable (%lld)\n",
+ mprotect_cycles, regset_cycles, regpair_cycles,
+ verify_vtable_cycles);
+ __vtv_add_to_log (log_fd,
+ "Pages protected (1): %d\n", num_pages_protected);
+ __vtv_add_to_log (log_fd, "Pages protected (2): %d\n", page_count_2);
close (log_fd);
}
}
+
+/* This function is called from __VLTVerifyVtablePointerDebug; it
+ sends as much debugging information as it can to the error log
+ file, then calls __vtv_verify_fail. SET_HANDLE_PTR is the pointer
+ to the set of valid vtable pointers, VTBL_PTR is the pointer that
+ was not found in the set, and DEBUG_MSG is the message to be
+ written to the log file before failing. n */
+
+void
+__vtv_verify_fail_debug (void **set_handle_ptr, const void *vtbl_ptr,
+ const char *debug_msg)
+{
+ __vtv_log_verification_failure (debug_msg, false);
+
+ /* Call the public interface in case it has been overwritten by
+ user. */
+ __vtv_verify_fail (set_handle_ptr, vtbl_ptr);
+
+ __vtv_log_verification_failure ("Returned from __vtv_verify_fail."
+ " Secondary verification succeeded.\n", false);
+}
+
+/* This function calls __fortify_fail with a FAILURE_MSG and then
+ calls abort. */
+
+void
+__vtv_really_fail (const char *failure_msg)
+{
+ __fortify_fail (failure_msg);
+
+ /* We should never get this far; __fortify_fail calls __libc_message
+ which prints out a back trace and a memory dump and then is
+ supposed to call abort, but let's play it safe anyway and call abort
+ ourselves. */
+ abort ();
+}
+
+/* This function takes an error MSG, a vtable map variable
+ (DATA_SET_PTR) and a vtable pointer (VTBL_PTR). It is called when
+ an attempt to verify VTBL_PTR with the set pointed to by
+ DATA_SET_PTR failed. It outputs a failure message with the
+ addresses involved, and calls __vtv_really_fail. */
+
+static void
+vtv_fail (const char *msg, void **data_set_ptr, const void *vtbl_ptr)
+{
+ char buffer[128];
+ int buf_len;
+ const char *format_str =
+ "*** Unable to verify vtable pointer (%p) in set (%p) *** \n";
+
+ snprintf (buffer, sizeof (buffer), format_str, vtbl_ptr,
+ is_set_handle_handle(*data_set_ptr) ?
+ ptr_from_set_handle_handle (*data_set_ptr) :
+ *data_set_ptr);
+ buf_len = strlen (buffer);
+ /* Send this to to stderr. */
+ write (2, buffer, buf_len);
+
+#ifndef VTV_NO_ABORT
+ __vtv_really_fail (msg);
+#endif
+}
+
+/* Send information about what we were trying to do when verification
+ failed to the error log, then call vtv_fail. This function can be
+ overwritten/replaced by the user, to implement a secondary
+ verification function instead. DATA_SET_PTR is the vtable map
+ variable used for the failed verification, and VTBL_PTR is the
+ vtable pointer that was not found in the set. */
+
+void
+__vtv_verify_fail (void **data_set_ptr, const void *vtbl_ptr)
+{
+ char log_msg[256];
+ snprintf (log_msg, sizeof (log_msg), "Looking for vtable %p in set %p.\n",
+ vtbl_ptr,
+ is_set_handle_handle (*data_set_ptr) ?
+ ptr_from_set_handle_handle (*data_set_ptr) :
+ *data_set_ptr);
+ __vtv_log_verification_failure (log_msg, false);
+
+ const char *format_str =
+ "*** Unable to verify vtable pointer (%p) in set (%p) *** \n";
+ snprintf (log_msg, sizeof (log_msg), format_str, vtbl_ptr, *data_set_ptr);
+ __vtv_log_verification_failure (log_msg, false);
+ __vtv_log_verification_failure (" Backtrace: \n", true);
+
+ const char *fail_msg = "Potential vtable pointer corruption detected!!\n";
+ vtv_fail (fail_msg, data_set_ptr, vtbl_ptr);
+}
diff --git a/libstdc++-v3/libsupc++/vtv_utils.cc b/libstdc++-v3/libsupc++/vtv_utils.cc
index bfe91b16e08..480bfa308dc 100644
--- a/libstdc++-v3/libsupc++/vtv_utils.cc
+++ b/libstdc++-v3/libsupc++/vtv_utils.cc
@@ -32,6 +32,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <execinfo.h>
#include <unistd.h>
#include <errno.h>
@@ -40,6 +41,8 @@
/* This is the directory into which all vtable verication log files
get written. */
static const char * const logs_dir = "/tmp/vtv_logs";
+static int vtv_failures_log_fd = -1;
+
/* This function takes the NAME of a log file to open, attempts to
@@ -47,14 +50,14 @@ static const char * const logs_dir = "/tmp/vtv_logs";
decriptor. */
int
-vtv_open_log (const char *name)
+__vtv_open_log (const char *name)
{
char log_name[256];
snprintf (log_name, sizeof (log_name), "%s/%s", logs_dir, name);
mkdir (logs_dir, S_IRWXU);
int fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU);
if (fd == -1)
- vtv_add_to_log (2, "Cannot open log file %s %s\n", name,
+ __vtv_add_to_log (2, "Cannot open log file %s %s\n", name,
strerror (errno));
return fd;
}
@@ -69,7 +72,7 @@ vtv_log_write (int fd, const char *str)
return 0;
if (fd != 2) /* Make sure we dont get in a loop. */
- vtv_add_to_log (2, "Error writing to log: %s\n", strerror (errno));
+ __vtv_add_to_log (2, "Error writing to log: %s\n", strerror (errno));
return -1;
}
@@ -82,7 +85,7 @@ vtv_log_write (int fd, const char *str)
to vtv_log_write. */
int
-vtv_add_to_log (int log_file, const char * format, ...)
+__vtv_add_to_log (int log_file, const char * format, ...)
{
/* We dont want to dynamically allocate this buffer. This should be
more than enough in most cases. It if isn't we are careful not to
@@ -99,9 +102,30 @@ vtv_add_to_log (int log_file, const char * format, ...)
vtv_log_write (log_file, output);
va_end (ap);
- /* fdatasync is quite expensive. Only enable if you suspect you are
- loosing log data in in a program crash? */
- /* fdatasync(log_file); */
-
return 0;
}
+
+/* Open error logging file, if not already open, and write vtable
+ verification failure messages (LOG_MSG) to the log file. Also
+ generate a backtrace in the log file, if GENERATE_BACKTRACE is
+ set. */
+
+void
+__vtv_log_verification_failure (const char *log_msg, bool generate_backtrace)
+{
+ if (vtv_failures_log_fd == -1)
+ vtv_failures_log_fd = __vtv_open_log ("vtable_verification_failures.log");
+
+ if (vtv_failures_log_fd == -1)
+ return;
+
+ __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg);
+
+ if (generate_backtrace)
+ {
+#define STACK_DEPTH 20
+ void *callers[STACK_DEPTH];
+ int actual_depth = backtrace (callers, STACK_DEPTH);
+ backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd);
+ }
+}
diff --git a/libstdc++-v3/libsupc++/vtv_utils.h b/libstdc++-v3/libsupc++/vtv_utils.h
index b847b863ad9..65600d23354 100644
--- a/libstdc++-v3/libsupc++/vtv_utils.h
+++ b/libstdc++-v3/libsupc++/vtv_utils.h
@@ -28,8 +28,6 @@
#include <stdlib.h>
#include "../../include/vtv-change-permission.h"
-extern bool vtv_debug;
-
static inline void
VTV_not_an_error (void)
{
@@ -39,10 +37,15 @@ VTV_not_an_error (void)
#define VTV_error abort
/* Assertion macros used in vtable verification runtime. */
-#define VTV_ASSERT(EXPR) (!(EXPR) ? VTV_error() : VTV_not_an_error())
-
+#define VTV_ASSERT(EXPR) \
+ if (!(EXPR)) VTV_error();
+
+#ifdef VTV_DEBUG
#define VTV_DEBUG_ASSERT(EXPR) \
- ((bool) (vtv_debug && !(EXPR)) ? VTV_error() : (void) 0)
+ ((bool) (!(EXPR)) ? VTV_error() : (void) 0)
+#else
+#define VTV_DEBUG_ASSERT(EXPR) ((void) 0)
+#endif
/* Name of the section where we put general VTV variables for protection */
#define VTV_PROTECTED_VARS_SECTION ".vtable_map_vars"
@@ -53,7 +56,8 @@ VTV_not_an_error (void)
routines and avoid calling malloc. We need this so that we dont
disturb the order of calls to dlopen. Changing the order of dlopen
calls may lead to deadlocks */
-int vtv_open_log (const char * name);
-int vtv_add_to_log (int log, const char * format, ...);
+int __vtv_open_log (const char * name);
+int __vtv_add_to_log (int log, const char * format, ...);
+void __vtv_log_verification_failure (const char *, bool);
#endif /* VTV_UTILS_H */
diff --git a/libstdc++-v3/po/Makefile.in b/libstdc++-v3/po/Makefile.in
index 858155f0ed0..b770278c544 100644
--- a/libstdc++-v3/po/Makefile.in
+++ b/libstdc++-v3/po/Makefile.in
@@ -274,11 +274,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
diff --git a/libstdc++-v3/python/Makefile.in b/libstdc++-v3/python/Makefile.in
index 4dd0904b2e1..fda085d8684 100644
--- a/libstdc++-v3/python/Makefile.in
+++ b/libstdc++-v3/python/Makefile.in
@@ -298,11 +298,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
diff --git a/libstdc++-v3/scripts/testsuite_flags.in b/libstdc++-v3/scripts/testsuite_flags.in
index 2df82a267fa..155aba3e202 100755
--- a/libstdc++-v3/scripts/testsuite_flags.in
+++ b/libstdc++-v3/scripts/testsuite_flags.in
@@ -56,7 +56,8 @@ case ${query} in
--cxxflags)
CXXFLAGS_default="-D_GLIBCXX_ASSERT -fmessage-length=0"
CXXFLAGS_config="@SECTION_FLAGS@ @CXXFLAGS@ @EXTRA_CXX_FLAGS@"
- CXXFLAGS_vtv=" -lvtv"
+ #CXXFLAGS_vtv=" -fvtable-verify=std -lvtv"
+ CXXFLAGS_vtv=" -fvtable-verify=std"
echo ${CXXFLAGS_default} ${CXXFLAGS_config} ${CXXFLAGS_vtv}
;;
--cxxparallelflags)
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
index de7f3e9567a..f2628fa8ac9 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -324,11 +324,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
diff --git a/libstdc++-v3/src/c++11/Makefile.in b/libstdc++-v3/src/c++11/Makefile.in
index cdf5e538b1d..f296f9a133f 100644
--- a/libstdc++-v3/src/c++11/Makefile.in
+++ b/libstdc++-v3/src/c++11/Makefile.in
@@ -291,11 +291,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
diff --git a/libstdc++-v3/src/c++98/Makefile.in b/libstdc++-v3/src/c++98/Makefile.in
index 8c60e596f4f..a70f407af18 100644
--- a/libstdc++-v3/src/c++98/Makefile.in
+++ b/libstdc++-v3/src/c++98/Makefile.in
@@ -307,11 +307,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.
diff --git a/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c b/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c
index e7cabc30bd2..0b8d1e26d3b 100644
--- a/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c
+++ b/libstdc++-v3/testsuite/18_support/bad_exception/23591_thread-1.c
@@ -1,5 +1,5 @@
// { dg-require-sharedlib "" }
-// { dg-options "-g -O2 -pthread -ldl -x c" { target *-*-linux* *-*-gnu* } }
+// { dg-options "-g -O2 -pthread -ldl -x c -fvtable-verify=none" { target *-*-linux* *-*-gnu* } }
// Copyright (C) 2005-2013 Free Software Foundation, Inc.
//
diff --git a/libstdc++-v3/testsuite/Makefile.in b/libstdc++-v3/testsuite/Makefile.in
index 31e96b9b8ed..ed8a9c04b13 100644
--- a/libstdc++-v3/testsuite/Makefile.in
+++ b/libstdc++-v3/testsuite/Makefile.in
@@ -277,11 +277,15 @@ toolexeclibdir = $(glibcxx_toolexeclibdir)
@ENABLE_EXTERN_TEMPLATE_FALSE@XTEMPLATE_FLAGS =
@ENABLE_EXTERN_TEMPLATE_TRUE@XTEMPLATE_FLAGS = -fno-implicit-templates
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXLINKFLAGS =
-@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = "-Wl,-lvtv"
+
+#VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs -Wl,-lvtv
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXLINKFLAGS = -L$(top_builddir)/libsupc++/.libs
@ENABLE_VTABLE_VERIFY_FALSE@VTV_CXXFLAGS =
@ENABLE_VTABLE_VERIFY_TRUE@VTV_CXXFLAGS = -fvtable-verify=std \
@ENABLE_VTABLE_VERIFY_TRUE@ -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end
+@ENABLE_VTABLE_VERIFY_FALSE@VTV_PCH_CXXFLAGS =
+@ENABLE_VTABLE_VERIFY_TRUE@VTV_PCH_CXXFLAGS = -fvtable-verify=std
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.ac to see how they are set. See GLIBCXX_EXPORT_FLAGS.