[Ping] Port of VTV for Cygwin and MinGW

Patrick Wollgast patrick.wollgast@rub.de
Thu Sep 18 22:24:00 GMT 2014

Added Benjamin De Kosnik as a c++ runtime libs maintainer and Kai Tietz
as Windows/Cygwin/MinGW maintainer.

>> In changes to gcc/config/i386/cygwin.h  mingw-w64.h and mingw32.h, you forgot to handle the "fvtable-verify=preinit" options.  fvtable-veriy=preinit should cause vtv_start_preinit.o to be added to the STARTFILE_SPEC and vtv_end_preinit.o to be added to the ENDFILE_SPEC (as in  gcc/config/gnu-user.h).  I expect you will also need to add it to your LIB_SPEC definitions in those config files.

Like discussed via email I set preinit=std. This required additional
changes in gcc/cp/vtable-class-hierarchy.c.

>> in libgcc/config.host, the indentation looks wrong on the line 660 (where you add the extra parts for vtable verification for the case "i[34567]86-*-mingw*)". It also looks wrong on line 709 (again, adding extra parts, for case "x86_64-*-mingw*)".  The rest of the changes in that file look ok, but someone else will need to approve them.

Indentation fixed.

>> The changes in libgcc/Makefile.in and gcc/varasm.c look ok to me, but someone will will have to approve them since I don't have authority to approve changes there.
>> in libstdc++-v3/libsupc++:
>> Your change in Makefile.am looks ok to me; your changes in vtv_stubs.cc look ok, except that you appear to have messed up the indentations in the function headers (both for the declarations and the actual functions).  Also there is a typo in your comment:  'build' should be 'built'.  But content-wise, the change looks fine.  Again, someone else will have to actually approve these changes since I do not have that authority.

Typo and indentation fixed.

>> in libstdc++-v3/src/Makefile.am also looks ok to me; someone else will have to give final approval.
>> in libvtv/Makefile.am, you need to fix the indentation at line 64 (vtv_stubs.cc):
>> vtv_stubs_sources = \
>>         vtv_start.c \
>>         vtv_stubs.cc \
>>         vtv_end.c

Indentation fixed.

>> the rest of the changes in that file look good.
>> Why did you make a copy of obstack.c in libvtv rather than using the one in libiberty?  It would be better not to make a second copy of the source file if that can be avoided...

I removed obstack.c from libvtv and added the changes from
libvtv/obstack.c to libiberty/obstack.c with #ifdefs.

>> in libvtv/vtv_malloc.cc:
>> lines 207-213:  Fix the indentation on the second line of call to VirtualAlloc.
>> #if defined (__CYGWIN__) || defined (__MINGW32__)
>>   if ((allocated = VirtualAlloc(NULL, size,  MEM_RESERVE|MEM_COMMIT,
>>                         PAGE_READWRITE)) == 0)
>> #else
>>   if ((allocated = mmap (NULL, size, PROT_READ | PROT_WRITE,"
>>                          MAP_PRIVATE | MAP_ANONYMOUS,  -1, 0)) == 0)
>> #endif
>> Remove extra blank line at line 216.

Line removed and indentation fixed.

>> in libvtv/vtv_rts.cc:
>> Your version of the function read_section_offset_and_length has several lines that exceed the 80 character limit; please fix that.  Your function iterate_modules  also has one or two lines that are too long, and it needs a function comment.

Character per line are now correct and comment added.

>> in libvtv/vtv_utils.cc:
>> In the function __vtv_open_log, you seem to have the following code twice:
>> #ifdef __MINGW32__
>>       mkdir (logs_prefix);
>> #else
>>       mkdir (logs_prefix, S_IRWXU);
>> #endif
>> was there a reason for this, or is this an accident (in which case the second occurrence should be removed)?

Should have been 'log_dir' instead of 'logs_prefix' the 2nd time. Fixed now.

-------------- next part --------------
* gcc/config/i386/cygwin.h (STARTFILE_SPEC): Add vtv_start.o,
    if -fvtable-verify=preinit/std is used.
* gcc/config/i386/mingw-w64.h (STARTFILE_SPEC): Likewise.
* gcc/config/i386/mingw32.h (STARTFILE_SPEC): Likewise.
* gcc/config/i386/cygwin.h (ENDFILE_SPEC): Add vtv_end.o,
    if -fvtable-verify=preinit/std is used.
* gcc/config/i386/mingw32.h (ENDFILE_SPEC): Likewise.
* gcc/config/i386/cygwin.h (LIB_SPEC): Pass -lvtv and -lpsapi,
    if -fvtable-verify=preinit/std is used.
* gcc/config/i386/mingw-w64.h (LIB_SPEC): Likewise.
* gcc/config/i386/mingw32.h (LIB_SPEC): Likewise.

* gcc/cp/vtable-class-hierarchy.c (vtv_generate_init_routine): Add
    check for not TARGET_PECOFF at the VTV_PREINIT_PRIORITY checks.

* gcc/varasm.c (assemble_variable): Add code to properly set the comdat
    section and name for the .vtable_map_vars section in case the
    target is PE or COFF.

* libgcc/Makefile.in: Move rules to build vtv_*.o out of the check
* libgcc/config.host (i[34567]86-*-cygwin*, x86_64-*-cygwin*, i[34567]86-*-mingw*)
    (x86_64-*-mingw*): Only add vtv_*.o to extra_parts if enable_vtable_verify.

* libiberty/obstack.c: Include windows.h on Cygwin and MinGW.
    Exchange abort with TerminateProcess on Cygwin and MinGW.
    Exchange exit with ExitProcess on Cygwin and MinGW.

* libstdc++-v3/acinclude.m4: Define VTV_CYGMIN.
* libstdc++-v3/configure: Regenerate.

* libstdc++-v3/libsupc++/Makefile.am: Add vtv_sources only to
    libsupc___la_SOURCES and libsupc__convenience_la_SOURCES if VTV_CYGMIN is
    not set.
* libstdc++-v3/libsupc++/Makefile.in: Regenerated.
* libstdc++-v3/libsupc++/vtv_stubs.cc: Add none weak declaration of every
    function for Cygwin and MinGW.

* libstdc++-v3/src/Makefile.am: Add libvtv.la to toolexeclib_LTLIBRARIES,
    if VTV_CYGMIN is set. Define libvtv_la_SOURCES, libvtv_la_LDFLAGS,
    libvtv_la_AM_CXXFLAGS and libvtv_la_LINK if VTV_CYGMIN is set.
* libstdc++-v3/src/Makefile.in: Regenerate.

* libvtv/Makefile.am : Add libvtv.la to toolexeclib_LTLIBRARIES, if VTV_CYGMIN
    is set. Define libvtv_la_LIBADD, libvtv_la_LDFLAGS, libvtv_stubs_la_LDFLAGS
    and libvtv_stubs_la_SOURCES if VTV_CYGMIN is set. Add obstac.c to
    libvtv_la_SOURCES if VTV_CYGMIN is set.
* libvtv/Makefile.in : Regenerate.
* libvtv/aclocal.m4 : Regenerate.
* libvtv/configure : Regenerate.
* libvtv/configure.ac : Add ACX_LT_HOST_FLAGS. Define VTV_CYGMIN.
* libvtv/configure.tgt : (x86_64-*-cygwin*, i?86-*-cygwin*, x86_64-*-mingw*)
    (i?86-*-mingw*): Add to supported targets.
* libvtv/vtv_fail.cc : Skip inclusion of execinfo.h on Cygwin and MinGW.
(log_error_message): Skip calls to backtrace and backtrace_symbols_fd on Cygwin
    and MinGW.
* libvtv/vtv_malloc.cc : Include windows.h and skip sys/mman.h inclusion on
    Cygwin and MinGW. Add sysconf and mprotect port on Cygwin and MinGW.
(obstack_chunk_alloc): Exchange call to mmap with call to VirtualAlloc on Cygwin
    and MinGW.
(__vtv_malloc_init): Exchange call to sysconf with call to port of sysconf on
    Cygwin and MinGW.
* libvtv/vtv_malloc.h : Declare mprotect and define PROT_READ and PROT_WRITE on
    Cygwin and MinGW.
* libvtv/map.h : Include stdint.h on MinGW.
* libvtv/rts.cc : Include windows.h, winternl.h and psapi.h, skip include of
    execinfo.h, sys/mman.h and link.h on Cygwin and MinGW.
    Add port of __fortify_fail on Cygwin and MinGW.
    Change ElfW (Addr) to uintptr_t on Cygwin and MinGW.
(read_section_offset_and_length): Add port for Cygwin and MinGW
(iterate_modules): New function.
(vtv_unprotect_vtable_vars): Use iterate_modules instead of dl_iterate_phdr on
    Cygwin and MinGW.
(vtv_protect_vtable_vars): Likewise.
(count_all_pages): Likewise.
(dl_iterate_phdr_count_pages): Don't build on Cygwin and MinGW.
* libvtv/utils.cc : Include windows.h and skip execinfo.h inclusion on
    Cygwin and MinGW.
(__vtv_open_log): Exchange call to getuid and getpid with GetCurrentProcessId and
    adjust call to snprintf accordingly on Cygwin and MinGW.
    Adjust calls to mkdir on MinGW.
    Adjust call to open on Cygwin and MinGW.
(__vtv_add_to_log): Adjust call to snprintf on Cygwin and MinGW.
(__vtv_log_verification_failure): Don't generate a backtrace on Cygwin and MinGW.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtv_cygmin.patch
Type: text/x-patch
Size: 38799 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140918/f87bdf83/attachment.bin>

More information about the Gcc-patches mailing list