Backport upstream patches to fix ICEs when using -fdebug-types-section.
[official-gcc.git] / gcc-4_7-mobile / libgcc / vtv_start.c
blob7899fdbd643bbeebd94ef1fdb6a7fec4a22367d9
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 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file is part of the vtable verification feature (for a
21 detailed description of the feature, see comments in
22 tree-vtable-verify.c). The vtable verification feature creates
23 certain global symbols that need to be read-write sometimes during
24 program execution, and read-only at others. It uses 'mprotect' to
25 change the memory protections of the pages on which these variables
26 are stored. In order to not affect the protections of other
27 program variables, these variables are put into a special named
28 section, ".vtable_map_vars", which is page-aligned at the start,
29 and which is padded with a page-sized amount of zeros at the end.
30 To make this section page aligned, we create a special symbol,
31 "_vtable_map_vars_start" which we make the very first thing that
32 goes into the section. This file defines that symbol (and only
33 that symbol). GCC compiles this file into vtv_start.o, and
34 inserts vtv_start.o into the link line immediately after
35 crtbegin.o, if the program is compiled with -fvtable.verify.
37 In order to pad the ".vtable_map_vars" section with a page-sized
38 amount of zeros at the end, there is a second symbol,
39 _vtable_map_vars_end, which is defined in another file, vtv_end.c.
40 This second symbol is a page-sized array of chars, zero-filled, and
41 is the very last thing to go into the section. When the GCC driver
42 inserts vtv_start.o into the link line (just after crtbegin.o) it
43 also inserts vtv_end.o into the link line, just before crtend.o.
44 This has the desired effect of making our section page-aligned and
45 page-size paded, ensuring that no other program data lands on our
46 pages. */
48 #ifdef BIG_PAGE_SIZE
49 /* TODO - Replace '4096' below with correct big page size. */
50 #define VTV_PAGE_SIZE 4096
51 #else
52 #define VTV_PAGE_SIZE 4096
53 #endif
55 /* Page-aligned symbol to mark beginning of .vtable_map_vars section. */
56 char _vtable_map_vars_start []
57 __attribute__ ((__visibility__ ("protected"), used, aligned(VTV_PAGE_SIZE),
58 section(".vtable_map_vars")))
59 = { };