xref: /netbsd-src/external/gpl3/gcc.old/dist/libgcc/vtv_end.c (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
1*8feb0f0bSmrg /* Copyright (C) 2012-2020 Free Software Foundation, Inc.
21debfc3dSmrg 
31debfc3dSmrg This file is part of GCC.
41debfc3dSmrg 
51debfc3dSmrg GCC is free software; you can redistribute it and/or modify it under
61debfc3dSmrg the terms of the GNU General Public License as published by the Free
71debfc3dSmrg Software Foundation; either version 3, or (at your option) any later
81debfc3dSmrg version.
91debfc3dSmrg 
101debfc3dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
111debfc3dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
121debfc3dSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
131debfc3dSmrg for more details.
141debfc3dSmrg 
151debfc3dSmrg Under Section 7 of GPL version 3, you are granted additional
161debfc3dSmrg permissions described in the GCC Runtime Library Exception, version
171debfc3dSmrg 3.1, as published by the Free Software Foundation.
181debfc3dSmrg 
191debfc3dSmrg You should have received a copy of the GNU General Public License and
201debfc3dSmrg a copy of the GCC Runtime Library Exception along with this program;
211debfc3dSmrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
221debfc3dSmrg <http://www.gnu.org/licenses/>.  */
231debfc3dSmrg 
241debfc3dSmrg /* This file is part of the vtable verification feature (for a
251debfc3dSmrg    detailed description of the feature, see comments in
261debfc3dSmrg    vtable-verify.c).  The vtable verification feature creates
271debfc3dSmrg    certain global symbols that need to be read-write sometimes during
281debfc3dSmrg    program execution, and read-only at others.  It uses 'mprotect' to
291debfc3dSmrg    change the memory protections of the pages on which these variables
301debfc3dSmrg    are stored.  In order to not affect the protections of other
311debfc3dSmrg    program variables, these variables are put into a special named
321debfc3dSmrg    section, ".vtable_map_vars", which is page-aligned at the start,
331debfc3dSmrg    and which is padded with a page-sized amount of zeros at the end.
341debfc3dSmrg    To make this section page aligned, we create a special symbol,
351debfc3dSmrg    "_vtable_map_vars_start" which we make the very first thing that
361debfc3dSmrg    goes into the section.  That is defined in vtv_start.c (which
371debfc3dSmrg    contains nothing else).  vtv_start.c gest compiled into
381debfc3dSmrg    vtv_start.o, and vtv_start.o gets inserted into the link line
391debfc3dSmrg    immediately after crtbegin.o, if the program is compiled with
401debfc3dSmrg    -fvtable.verify.
411debfc3dSmrg 
421debfc3dSmrg    In order to pad the ".vtable_map_vars" section with a page-sized
431debfc3dSmrg    amount of zeros at the end, there is a second symbol,
441debfc3dSmrg    _vtable_map_vars_end.  This file defines that symbol (and only this
451debfc3dSmrg    symbol).  This second symbol is a page-sized array of chars,
461debfc3dSmrg    zero-filled, and is the very last thing to go into the section.
471debfc3dSmrg    When the GCC driver inserts vtv_start.o into the link line (just
481debfc3dSmrg    after crtbegin.o) it also inserts vtv_end.o into the link line,
491debfc3dSmrg    just before crtend.o.  This has the desired effect of making our
501debfc3dSmrg    section page-aligned and page-size paded, ensuring that no other
511debfc3dSmrg    program data lands on our pages.  */
521debfc3dSmrg 
531debfc3dSmrg 
541debfc3dSmrg #include "vtv-change-permission.h"
551debfc3dSmrg 
561debfc3dSmrg __attribute__ ((constructor(100))) void
__VLTprotect(void)571debfc3dSmrg __VLTprotect (void)
581debfc3dSmrg {
591debfc3dSmrg   __VLTChangePermission (__VLTP_READ_ONLY);
601debfc3dSmrg }
611debfc3dSmrg 
621debfc3dSmrg /* Page-sized variable to mark end of .vtable_map_vars section.  */
631debfc3dSmrg char _vtable_map_vars_end[VTV_PAGE_SIZE]
641debfc3dSmrg   __attribute__ ((__visibility__ ("protected"), used,
651debfc3dSmrg 		  section(".vtable_map_vars")));
66