2013-11-03 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc.git] / libgcc / vtv_start.c
blob3efb63dfbb034e3f1bb3224dfa225ac56f71012e
1 /* Copyright (C) 2012, 2013
2 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 /* This file is part of the vtable verification feature (for a
26 detailed description of the feature, see comments in
27 vtable-verify.c). The vtable verification feature creates
28 certain global symbols that need to be read-write sometimes during
29 program execution, and read-only at others. It uses 'mprotect' to
30 change the memory protections of the pages on which these variables
31 are stored. In order to not affect the protections of other
32 program variables, these variables are put into a special named
33 section, ".vtable_map_vars", which is page-aligned at the start,
34 and which is padded with a page-sized amount of zeros at the end.
35 To make this section page aligned, we create a special symbol,
36 "_vtable_map_vars_start" which we make the very first thing that
37 goes into the section. This file defines that symbol (and only
38 that symbol). GCC compiles this file into vtv_start.o, and
39 inserts vtv_start.o into the link line immediately after
40 crtbegin.o, if the program is compiled with -fvtable.verify.
42 In order to pad the ".vtable_map_vars" section with a page-sized
43 amount of zeros at the end, there is a second symbol,
44 _vtable_map_vars_end, which is defined in another file, vtv_end.c.
45 This second symbol is a page-sized array of chars, zero-filled, and
46 is the very last thing to go into the section. When the GCC driver
47 inserts vtv_start.o into the link line (just after crtbegin.o) it
48 also inserts vtv_end.o into the link line, just before crtend.o.
49 This has the desired effect of making our section page-aligned and
50 page-size paded, ensuring that no other program data lands on our
51 pages. */
53 #include "vtv-change-permission.h"
55 __attribute__ ((constructor(98))) void
56 __VLTunprotect (void)
58 __VLTChangePermission (__VLTP_READ_WRITE);
61 /* Page-aligned symbol to mark beginning of .vtable_map_vars section. */
62 char _vtable_map_vars_start []
63 __attribute__ ((__visibility__ ("protected"), used, aligned(VTV_PAGE_SIZE),
64 section(".vtable_map_vars")))
65 = { };