summaryrefslogtreecommitdiff
path: root/libgcc
diff options
context:
space:
mode:
Diffstat (limited to 'libgcc')
-rw-r--r--libgcc/ChangeLog13
-rw-r--r--libgcc/Makefile.in17
-rw-r--r--libgcc/config.host2
-rw-r--r--libgcc/configure16
-rw-r--r--libgcc/configure.ac10
-rw-r--r--libgcc/vtv_end.c66
-rw-r--r--libgcc/vtv_end_preinit.c71
-rw-r--r--libgcc/vtv_start.c65
-rw-r--r--libgcc/vtv_start_preinit.c73
9 files changed, 332 insertions, 1 deletions
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index ab4d2c1b049..af42e3e4555 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,16 @@
+2013-08-06 Caroline Tice <cmtice@google.com>
+
+ config.host (extra_parts): Add vtv_start.o, vtv_end.o
+ vtv_start_preinit.o and vtv_end_preinit.o.
+ configure.ac: Add code to check/set enable_vtable_verify.
+ Makefile.in: Add rules to build vtv_*.o, if enable_vtable_verify is
+ true.
+ vtv_start_preinit.c: New file.
+ vtv_end_preinit.c: New file.
+ vtv_start.c: New file.
+ vtv_end.c: New file.
+ configure: Regenerated.
+
2013-08-01 Maxim Kuvyrkov <maxim@kugelworks.com>
* config/aarch64/sfp-machine.h, config/aarch64/sync-cache.c,
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index 958be5ec86f..63fd626da40 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -39,6 +39,7 @@ enable_shared = @enable_shared@
double_type_size = @double_type_size@
long_double_type_size = @long_double_type_size@
decimal_float = @decimal_float@
+enable_vtable_verify = @enable_vtable_verify@
enable_decimal_float = @enable_decimal_float@
fixed_point = @fixed_point@
@@ -971,6 +972,22 @@ crtendS$(objext): $(srcdir)/crtstuff.c
# This is a version of crtbegin for -static links.
crtbeginT$(objext): $(srcdir)/crtstuff.c
$(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN -DCRTSTUFFT_O
+
+ifeq ($(enable_vtable_verify),yes)
+# These are used in vtable verification; see comments in source files for
+# more details.
+vtv_start$(objext): $(srcdir)/vtv_start.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $(srcdir)/vtv_start.c
+
+vtv_end$(objext): $(srcdir)/vtv_end.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $(srcdir)/vtv_end.c
+
+vtv_start_preinit$(objext): $(srcdir)/vtv_start_preinit.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $(srcdir)/vtv_start_preinit.c
+
+vtv_end_preinit$(objext): $(srcdir)/vtv_end_preinit.c
+ $(crt_compile) $(CRTSTUFF_T_CFLAGS_S) -c $(srcdir)/vtv_end_preinit.c
+endif
endif
ifeq ($(CUSTOM_CRTIN),)
diff --git a/libgcc/config.host b/libgcc/config.host
index 9c47e1b4233..f75ae9a571c 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -197,7 +197,7 @@ case ${host} in
;;
*-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu)
tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver t-linux"
- extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o"
+ extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o"
;;
*-*-lynxos*)
tmake_file="$tmake_file t-lynx $cpu_type/t-crtstuff t-crtstuff-pic t-libgcc-pic"
diff --git a/libgcc/configure b/libgcc/configure
index bb36889ae56..29fa46f597a 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -608,6 +608,7 @@ build_os
build_vendor
build_cpu
build
+enable_vtable_verify
enable_shared
libgcc_topdir
target_alias
@@ -655,6 +656,7 @@ with_target_subdir
with_cross_host
with_ld
enable_shared
+enable_vtable_verify
enable_version_specific_runtime_libs
with_slibdir
enable_maintainer_mode
@@ -1288,6 +1290,7 @@ Optional Features:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--disable-shared don't provide a shared libgcc
+ --enable-vtable-verify Enable vtable verification feature
--enable-version-specific-runtime-libs Specify that runtime libraries should be installed in a compiler-specific directory
--enable-maintainer-mode
enable make rules and dependencies not useful (and
@@ -2140,6 +2143,19 @@ fi
+# Check whether --enable-vtable-verify was given.
+if test "${enable_vtable_verify+set}" = set; then :
+ enableval=$enable_vtable_verify; case "$enableval" in
+ yes) enable_vtable_verify=yes ;;
+ no) enable_vtable_verify=no ;;
+ *) enable_vtable_verify=no;;
+ esac
+else
+ enable_vtable_verify=no
+fi
+
+
+
# Make sure we can run config.sub.
$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
as_fn_error "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 8b7aba5823b..186cd6e9cd7 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -66,6 +66,16 @@ AC_ARG_ENABLE(shared,
], [enable_shared=yes])
AC_SUBST(enable_shared)
+AC_ARG_ENABLE(vtable-verify,
+[ --enable-vtable-verify Enable vtable verification feature ],
+[case "$enableval" in
+ yes) enable_vtable_verify=yes ;;
+ no) enable_vtable_verify=no ;;
+ *) enable_vtable_verify=no;;
+ esac],
+[enable_vtable_verify=no])
+AC_SUBST(enable_vtable_verify)
+
GCC_PICFLAG
AC_SUBST(PICFLAG)
diff --git a/libgcc/vtv_end.c b/libgcc/vtv_end.c
new file mode 100644
index 00000000000..83fa101c8e3
--- /dev/null
+++ b/libgcc/vtv_end.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 2012, 2013
+ Free Software Foundation, Inc.
+
+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 verification feature (for a
+ detailed description of the feature, see comments in
+ vtable-verify.c). The vtable verification feature creates
+ certain global symbols that need to be read-write sometimes during
+ program execution, and read-only at others. It uses 'mprotect' to
+ change the memory protections of the pages on which these variables
+ are stored. In order to not affect the protections of other
+ program variables, these variables are put into a special named
+ section, ".vtable_map_vars", which is page-aligned at the start,
+ and which is padded with a page-sized amount of zeros at the end.
+ To make this section page aligned, we create a special symbol,
+ "_vtable_map_vars_start" which we make the very first thing that
+ goes into the section. That is defined in vtv_start.c (which
+ contains nothing else). vtv_start.c gest compiled into
+ vtv_start.o, and vtv_start.o gets inserted into the link line
+ immediately after crtbegin.o, if the program is compiled with
+ -fvtable.verify.
+
+ In order to pad the ".vtable_map_vars" section with a page-sized
+ amount of zeros at the end, there is a second symbol,
+ _vtable_map_vars_end. This file defines that symbol (and only this
+ symbol). This second symbol is a page-sized array of chars,
+ zero-filled, and is the very last thing to go into the section.
+ When the GCC driver inserts vtv_start.o into the link line (just
+ after crtbegin.o) it also inserts vtv_end.o into the link line,
+ just before crtend.o. This has the desired effect of making our
+ section page-aligned and page-size paded, ensuring that no other
+ program data lands on our pages. */
+
+
+#include "vtv-change-permission.h"
+
+__attribute__ ((constructor(100))) void
+__VLTprotect (void)
+{
+ __VLTChangePermission (__VLTP_READ_ONLY);
+}
+
+/* Page-sized variable to mark end of .vtable_map_vars section. */
+char _vtable_map_vars_end[VTV_PAGE_SIZE]
+ __attribute__ ((__visibility__ ("protected"), used,
+ section(".vtable_map_vars")));
diff --git a/libgcc/vtv_end_preinit.c b/libgcc/vtv_end_preinit.c
new file mode 100644
index 00000000000..53d12b07ea1
--- /dev/null
+++ b/libgcc/vtv_end_preinit.c
@@ -0,0 +1,71 @@
+/* Copyright (C) 2012, 2013
+ Free Software Foundation, Inc.
+
+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 verification feature (for a
+ detailed description of the feature, see comments in
+ vtable-verify.c). The vtable verification feature creates
+ certain global symbols that need to be read-write sometimes during
+ program execution, and read-only at others. It uses 'mprotect' to
+ change the memory protections of the pages on which these variables
+ are stored. In order to not affect the protections of other
+ program variables, these variables are put into a special named
+ section, ".vtable_map_vars", which is page-aligned at the start,
+ and which is padded with a page-sized amount of zeros at the end.
+ To make this section page aligned, we create a special symbol,
+ "_vtable_map_vars_start" which we make the very first thing that
+ goes into the section. That is defined in vtv_start.c (which
+ contains nothing else). vtv_start.c gest compiled into
+ vtv_start.o, and vtv_start.o gets inserted into the link line
+ immediately after crtbegin.o, if the program is compiled with
+ -fvtable.verify.
+
+ In order to pad the ".vtable_map_vars" section with a page-sized
+ amount of zeros at the end, there is a second symbol,
+ _vtable_map_vars_end. This file defines that symbol (and only this
+ symbol). This second symbol is a page-sized array of chars,
+ zero-filled, and is the very last thing to go into the section.
+ When the GCC driver inserts vtv_start.o into the link line (just
+ after crtbegin.o) it also inserts vtv_end.o into the link line,
+ just before crtend.o. This has the desired effect of making our
+ section page-aligned and page-size paded, ensuring that no other
+ program data lands on our pages. */
+
+#include "vtv-change-permission.h"
+
+void
+__VLTProtectPreinit (void)
+{
+ __VLTChangePermission (__VLTP_READ_ONLY);
+}
+
+/* Page-sized variable to mark end of .vtable_map_vars section. */
+char _vtable_map_vars_end[VTV_PAGE_SIZE]
+ __attribute__ ((__visibility__ ("protected"), used,
+ section(".vtable_map_vars")));
+
+/* Put the function __VLTProtectPreinit into the .preinit_array
+ section. */
+
+__attribute__ ((section (".preinit_array")))
+ typeof (__VLTProtectPreinit) *__preinit_end = __VLTProtectPreinit;
diff --git a/libgcc/vtv_start.c b/libgcc/vtv_start.c
new file mode 100644
index 00000000000..3efb63dfbb0
--- /dev/null
+++ b/libgcc/vtv_start.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 2012, 2013
+ Free Software Foundation, Inc.
+
+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 verification feature (for a
+ detailed description of the feature, see comments in
+ vtable-verify.c). The vtable verification feature creates
+ certain global symbols that need to be read-write sometimes during
+ program execution, and read-only at others. It uses 'mprotect' to
+ change the memory protections of the pages on which these variables
+ are stored. In order to not affect the protections of other
+ program variables, these variables are put into a special named
+ section, ".vtable_map_vars", which is page-aligned at the start,
+ and which is padded with a page-sized amount of zeros at the end.
+ To make this section page aligned, we create a special symbol,
+ "_vtable_map_vars_start" which we make the very first thing that
+ goes into the section. This file defines that symbol (and only
+ that symbol). GCC compiles this file into vtv_start.o, and
+ inserts vtv_start.o into the link line immediately after
+ crtbegin.o, if the program is compiled with -fvtable.verify.
+
+ In order to pad the ".vtable_map_vars" section with a page-sized
+ amount of zeros at the end, there is a second symbol,
+ _vtable_map_vars_end, which is defined in another file, vtv_end.c.
+ This second symbol is a page-sized array of chars, zero-filled, and
+ is the very last thing to go into the section. When the GCC driver
+ inserts vtv_start.o into the link line (just after crtbegin.o) it
+ also inserts vtv_end.o into the link line, just before crtend.o.
+ This has the desired effect of making our section page-aligned and
+ page-size paded, ensuring that no other program data lands on our
+ pages. */
+
+#include "vtv-change-permission.h"
+
+__attribute__ ((constructor(98))) void
+__VLTunprotect (void)
+{
+ __VLTChangePermission (__VLTP_READ_WRITE);
+}
+
+/* Page-aligned symbol to mark beginning of .vtable_map_vars section. */
+char _vtable_map_vars_start []
+__attribute__ ((__visibility__ ("protected"), used, aligned(VTV_PAGE_SIZE),
+ section(".vtable_map_vars")))
+ = { };
diff --git a/libgcc/vtv_start_preinit.c b/libgcc/vtv_start_preinit.c
new file mode 100644
index 00000000000..512c8581a28
--- /dev/null
+++ b/libgcc/vtv_start_preinit.c
@@ -0,0 +1,73 @@
+/* Copyright (C) 2012, 2013
+ Free Software Foundation, Inc.
+
+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 verification feature (for a
+ detailed description of the feature, see comments in
+ vtable-verify.c). The vtable verification feature creates
+ certain global symbols that need to be read-write sometimes during
+ program execution, and read-only at others. It uses 'mprotect' to
+ change the memory protections of the pages on which these variables
+ are stored. In order to not affect the protections of other
+ program variables, these variables are put into a special named
+ section, ".vtable_map_vars", which is page-aligned at the start,
+ and which is padded with a page-sized amount of zeros at the end.
+ To make this section page aligned, we create a special symbol,
+ "_vtable_map_vars_start" which we make the very first thing that
+ goes into the section. This file defines that symbol (and only
+ that symbol). GCC compiles this file into vtv_start.o, and
+ inserts vtv_start.o into the link line immediately after
+ crtbegin.o, if the program is compiled with -fvtable.verify.
+
+ In order to pad the ".vtable_map_vars" section with a page-sized
+ amount of zeros at the end, there is a second symbol,
+ _vtable_map_vars_end, which is defined in another file, vtv_end.c.
+ This second symbol is a page-sized array of chars, zero-filled, and
+ is the very last thing to go into the section. When the GCC driver
+ inserts vtv_start.o into the link line (just after crtbegin.o) it
+ also inserts vtv_end.o into the link line, just before crtend.o.
+ This has the desired effect of making our section page-aligned and
+ page-size paded, ensuring that no other program data lands on our
+ pages. */
+
+#include "vtv-change-permission.h"
+
+void
+__VLTUnprotectPreinit (void)
+{
+ __VLTChangePermission (__VLTP_READ_WRITE);
+}
+
+/* Page-aligned symbol to mark beginning of .vtable_map_vars section. */
+char _vtable_map_vars_start []
+__attribute__ ((__visibility__ ("protected"), used, aligned(VTV_PAGE_SIZE),
+ section(".vtable_map_vars")))
+ = { };
+
+
+/* Put the function __VLTUnprotectPreinit into the .preinit_array
+ section. */
+
+__attribute__ ((section (".preinit_array")))
+ typeof (__VLTUnprotectPreinit) *__preinit = __VLTUnprotectPreinit;
+