* Port of VTV for Cygwin and MinGW @ 2014-08-28 11:04 Patrick Wollgast 2014-09-11 4:12 ` [Ping] " Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-08-28 11:04 UTC (permalink / raw) To: gcc-patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 2765 bytes --] This patch contains a port of VTV -fvtable-verify=std for Cygwin and MinGW. Since weak symbols on Windows and Linux are implemented differently, and VTV should have the possibility to be switched on and off, the structure of the feature had to be modified. On Linux libstdc++ contains the weak stub functions of VTV. For Cygwin and MinGW they have been removed, due to the difference of weak symbols. On Linux and on Windows libstdc++ itself gets build with -fvtable-verify=std. Since libvtv gets build after libstdc++, and libstdc++ doesn't contain the stub functions any more, 'undefined reference' errors are thrown during linking of libstdc++. To prevent these errors during the linking process a libvtv-0.dll gets build from the stub functions before libstdc++-6.dll is linked. At the end of the build process two VTV dlls have been build. One is called libvtv-0.dll, containing the real functions, the other is called libvtv_stubs-0.dll, containing the stub functions. Depending on whether libvtv-0.dll is first found in the dll search path or libvtv_stubs-0.dll, renamed to libvtv-0.dll, the real functions or the stub functions are used. Testing: The test builds were configured the following way: Linux 64bit (from patched and unpatched trunk): /path/to/configure --prefix=/prefix/gcc-vtv-bin-64 --enable-libstdcxx-threads --enable-vtable-verify=yes MinGW 32bit cross compiled: /path/to/configure --target=i686-w64-mingw32 --prefix=/prefix/mingw-vtv-bin-32 --with-gnu-ld --with-gnu-as --enable-fully-dynamic-string --disable-multilib --enable-libstdcxx-threads --enable-vtable-verify=yes MinGW 64bit cross compiled: /path/to/configure --target=x86_64-w64-mingw32 --prefix=/prefix/mingw-vtv-bin-64 --with-gnu-ld --with-gnu-as --enable-fully-dynamic-string --disable-multilib --enable-libstdcxx-threads --enable-vtable-verify=yes Cygwin 64bit: /path/to/configure --enable-languages=c,c++ --enable-libstdcxx-threads --enable-vtable-verify=yes At Linux the patched and unpatched version resulted in the same number of passed tests with 'make check-target-libvtv'. Since MinGW was cross compiled the test cases couldn't be built and run with 'make check-target-libvtv'. Therefore they were built with the attached makefiles and tested afterwards on Windows 7 64bit. Some test cases contain Linux specific parts and weren't tested. See the makefiles for further information. Additionally virtual_func_test_min_UAF.cpp was also built and tested. All built tests passed. Cygwin was just tested on gcc 4.9.0, because the current trunk isn't building for me. Even the clean trunk without the patch attached to this mail. On Cygwin with gcc 4.9.0 VTV worked. Besides the test cases Botan was also built and tested (gcc 4.9.0) with MinGW 32bit and VTV. regards [-- Attachment #2: ChangeLog --] [-- Type: text/plain, Size: 3904 bytes --] * config/i386/cygwin.h (STARTFILE_SPEC): Add vtv_start.o, if -fvtable-verify=std is used. * config/i386/mingw-w64.h (STARTFILE_SPEC): Likewise. * config/i386/mingw32.h (STARTFILE_SPEC): Likewise. * config/i386/cygwin.h (ENDFILE_SPEC): Add vtv_end.o, if -fvtable-verify=std is used. * config/i386/mingw32.h (ENDFILE_SPEC): Likewise. * config/i386/cygwin.h (LIB_SPEC): Pass -lvtv and -lpsapi, if -fvtable-verify=std is used. * config/i386/mingw-w64.h (LIB_SPEC): Likewise. * config/i386/mingw32.h (LIB_SPEC): Likewise. * 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 for CUSTOM_CRTSTUFF. * 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. * 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/obstack.c : New file. * 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. [-- Attachment #3: makefile_check_mingw_32 --] [-- Type: text/plain, Size: 12467 bytes --] all: ### -O2 i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/bb_tests.cc -o ./bb_tests-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/const_vtable.cc -o ./const_vtable-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dataentry.cc -o ./dataentry-O2.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-lib.cpp -o ./derived-lib-O2.exe # no lib.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-main.cpp -o ./derived-main-O2.exe # no lib.h i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dup_name.cc -o ./dup_name-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/environment.cc -o ./environment-O2.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-defintions.cpp -o ./event-defintions-O2.exe # undefined reference to 'WinMain' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-main.cpp -o ./event-main-O2.exe # undefined reference to 'Event::Event()' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-private.cpp -o ./event-private-O2.exe # undefined reference to 'Event::*()' i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/mul_inh.cc -o ./mul_inh-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/nested_vcall_test.cc -o ./nested_vcall_test-O2.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts-views.cpp -o ./parts-test-extra-parts-views-O2.exe # undefined reference to 'ExtraParts::*()' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts.cpp -o ./parts-test-extra-parts-O2.exe # undefined reference to 'WinMain' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-main.cpp -o ./parts-test-main-O2.exe # undefined reference to 'ExtraPartsViews::ExtraPartsViews()' i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/povray-derived.cc -o ./povray-derived-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair.cc -o ./register_set_pair-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair_inserts.cc -o ./register_set_pair_inserts-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list-iostream.cc -o ./template-list-iostream-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list.cc -o ./template-list-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list2.cc -o ./template-list2-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/test1.cc -o ./test1-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk.cc -o ./thunk-O2.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk_vtable_map_attack.cc -o ./thunk_vtable_map_attack-O2.exe # no sigjmp_buf, etc. i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/v8-test-2.cc -o ./v8-test-2-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtfunc-test.cc -o ./virtfunc-test-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtual_inheritance.cc -o ./virtual_inheritance-O2.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/xlan-test.cc -o ./xlan-test-O2.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_negative.cc -o ./mempool_negative-O2.exe # no sigjmp_buf, etc. #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_positive.cc -o ./mempool_positive-O2.exe # no siginfo_t, etc. #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_inserts_mt.cc -o ./register_set_pair_inserts_mt-O2.exe # no pthread_* #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_mt.cc -o ./register_set_pair_mt-O2.exe # no pthread_* #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen.cc -o ./dlopen-O2.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen_mt.cc -o ./dlopen_mt-O2.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/field-test.cc -o ./field-test-O2.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/replace-fail.cc -o ./replace-fail-O2.exe # undefined reference to 'WinMain' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/so.cc -o ./so-O2.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv.cc -o ./temp_deriv-O2.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv2.cc -o ./temp_deriv2-O2.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv3.cc -o ./temp_deriv3-O2.exe # no dlfcn.h ### -O0 i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/bb_tests.cc -o ./bb_tests-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/const_vtable.cc -o ./const_vtable-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dataentry.cc -o ./dataentry-O0.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-lib.cpp -o ./derived-lib-O0.exe # no lib.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-main.cpp -o ./derived-main-O0.exe # no lib.h i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dup_name.cc -o ./dup_name-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/environment.cc -o ./environment-O0.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-defintions.cpp -o ./event-defintions-O0.exe # undefined reference to 'WinMain' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-main.cpp -o ./event-main-O0.exe # undefined reference to 'Event::Event()' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-private.cpp -o ./event-private-O0.exe # undefined reference to 'Event::*()' i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/mul_inh.cc -o ./mul_inh-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/nested_vcall_test.cc -o ./nested_vcall_test-O0.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts-views.cpp -o ./parts-test-extra-parts-views-O0.exe # undefined reference to 'ExtraParts::*()' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts.cpp -o ./parts-test-extra-parts-O0.exe # undefined reference to 'WinMain' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-main.cpp -o ./parts-test-main-O0.exe # undefined reference to 'ExtraPartsViews::ExtraPartsViews()' i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/povray-derived.cc -o ./povray-derived-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair.cc -o ./register_set_pair-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair_inserts.cc -o ./register_set_pair_inserts-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list-iostream.cc -o ./template-list-iostream-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list.cc -o ./template-list-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list2.cc -o ./template-list2-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/test1.cc -o ./test1-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk.cc -o ./thunk-O0.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk_vtable_map_attack.cc -o ./thunk_vtable_map_attack-O0.exe # no sigjmp_buf, etc. i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/v8-test-2.cc -o ./v8-test-2-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtfunc-test.cc -o ./virtfunc-test-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtual_inheritance.cc -o ./virtual_inheritance-O0.exe i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/xlan-test.cc -o ./xlan-test-O0.exe #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_negative.cc -o ./mempool_negative-O0.exe # no sigjmp_buf, etc. #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_positive.cc -o ./mempool_positive-O0.exe # no siginfo_t, etc. #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_inserts_mt.cc -o ./register_set_pair_inserts_mt-O0.exe # no pthread_* #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_mt.cc -o ./register_set_pair_mt-O0.exe # no pthread_* #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen.cc -o ./dlopen-O0.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen_mt.cc -o ./dlopen_mt-O0.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/field-test.cc -o ./field-test-O0.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/replace-fail.cc -o ./replace-fail-O0.exe # undefined reference to 'WinMain' #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/so.cc -o ./so-O0.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv.cc -o ./temp_deriv-O0.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv2.cc -o ./temp_deriv2-O0.exe # no dlfcn.h #i686-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv3.cc -o ./temp_deriv3-O0.exe # no dlfcn.h [-- Attachment #4: makefile_test_mingw_32 --] [-- Type: text/plain, Size: 12627 bytes --] all: ### -O2 x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/bb_tests.cc -o ./bb_tests-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/const_vtable.cc -o ./const_vtable-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dataentry.cc -o ./dataentry-O2.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-lib.cpp -o ./derived-lib-O2.exe # no lib.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-main.cpp -o ./derived-main-O2.exe # no lib.h x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dup_name.cc -o ./dup_name-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/environment.cc -o ./environment-O2.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-defintions.cpp -o ./event-defintions-O2.exe # undefined reference to 'WinMain' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-main.cpp -o ./event-main-O2.exe # undefined reference to 'Event::Event()' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-private.cpp -o ./event-private-O2.exe # undefined reference to 'Event::*()' x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/mul_inh.cc -o ./mul_inh-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/nested_vcall_test.cc -o ./nested_vcall_test-O2.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts-views.cpp -o ./parts-test-extra-parts-views-O2.exe # undefined reference to 'ExtraParts::*()' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts.cpp -o ./parts-test-extra-parts-O2.exe # undefined reference to 'WinMain' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-main.cpp -o ./parts-test-main-O2.exe # undefined reference to 'ExtraPartsViews::ExtraPartsViews()' x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/povray-derived.cc -o ./povray-derived-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair.cc -o ./register_set_pair-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair_inserts.cc -o ./register_set_pair_inserts-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list-iostream.cc -o ./template-list-iostream-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list.cc -o ./template-list-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list2.cc -o ./template-list2-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/test1.cc -o ./test1-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk.cc -o ./thunk-O2.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk_vtable_map_attack.cc -o ./thunk_vtable_map_attack-O2.exe # no sigjmp_buf, etc. x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/v8-test-2.cc -o ./v8-test-2-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtfunc-test.cc -o ./virtfunc-test-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtual_inheritance.cc -o ./virtual_inheritance-O2.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/xlan-test.cc -o ./xlan-test-O2.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_negative.cc -o ./mempool_negative-O2.exe # no sigjmp_buf, etc. #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_positive.cc -o ./mempool_positive-O2.exe # no siginfo_t, etc. #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_inserts_mt.cc -o ./register_set_pair_inserts_mt-O2.exe # no pthread_* #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_mt.cc -o ./register_set_pair_mt-O2.exe # no pthread_* #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen.cc -o ./dlopen-O2.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen_mt.cc -o ./dlopen_mt-O2.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/field-test.cc -o ./field-test-O2.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/replace-fail.cc -o ./replace-fail-O2.exe # undefined reference to 'WinMain' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/so.cc -o ./so-O2.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv.cc -o ./temp_deriv-O2.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv2.cc -o ./temp_deriv2-O2.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O2 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv3.cc -o ./temp_deriv3-O2.exe # no dlfcn.h ### -O0 x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/bb_tests.cc -o ./bb_tests-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/const_vtable.cc -o ./const_vtable-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dataentry.cc -o ./dataentry-O0.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-lib.cpp -o ./derived-lib-O0.exe # no lib.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/derived-main.cpp -o ./derived-main-O0.exe # no lib.h x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/dup_name.cc -o ./dup_name-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/environment.cc -o ./environment-O0.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-defintions.cpp -o ./event-defintions-O0.exe # undefined reference to 'WinMain' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-main.cpp -o ./event-main-O0.exe # undefined reference to 'Event::Event()' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/event-private.cpp -o ./event-private-O0.exe # undefined reference to 'Event::*()' x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/mul_inh.cc -o ./mul_inh-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/nested_vcall_test.cc -o ./nested_vcall_test-O0.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts-views.cpp -o ./parts-test-extra-parts-views-O0.exe # undefined reference to 'ExtraParts::*()' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-extra-parts.cpp -o ./parts-test-extra-parts-O0.exe # undefined reference to 'WinMain' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/parts-test-main.cpp -o ./parts-test-main-O0.exe # undefined reference to 'ExtraPartsViews::ExtraPartsViews()' x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/povray-derived.cc -o ./povray-derived-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair.cc -o ./register_set_pair-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/register_set_pair_inserts.cc -o ./register_set_pair_inserts-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list-iostream.cc -o ./template-list-iostream-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list.cc -o ./template-list-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/template-list2.cc -o ./template-list2-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/test1.cc -o ./test1-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk.cc -o ./thunk-O0.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/thunk_vtable_map_attack.cc -o ./thunk_vtable_map_attack-O0.exe # no sigjmp_buf, etc. x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/v8-test-2.cc -o ./v8-test-2-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtfunc-test.cc -o ./virtfunc-test-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/virtual_inheritance.cc -o ./virtual_inheritance-O0.exe x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.cc/xlan-test.cc -o ./xlan-test-O0.exe #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_negative.cc -o ./mempool_negative-O0.exe # no sigjmp_buf, etc. #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mempool.cc/mempool_positive.cc -o ./mempool_positive-O0.exe # no siginfo_t, etc. #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_inserts_mt.cc -o ./register_set_pair_inserts_mt-O0.exe # no pthread_* #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/libvtv.mt.cc/register_set_pair_mt.cc -o ./register_set_pair_mt-O0.exe # no pthread_* #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen.cc -o ./dlopen-O0.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/dlopen_mt.cc -o ./dlopen_mt-O0.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/field-test.cc -o ./field-test-O0.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/replace-fail.cc -o ./replace-fail-O0.exe # undefined reference to 'WinMain' #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/so.cc -o ./so-O0.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv.cc -o ./temp_deriv-O0.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv2.cc -o ./temp_deriv2-O0.exe # no dlfcn.h #x86_64-w64-mingw32-g++ -v -fvtable-verify=std -O0 /home/a/Projects/gcc/libvtv/testsuite/other-tests/temp_deriv3.cc -o ./temp_deriv3-O0.exe # no dlfcn.h [-- Attachment #5: vtv_cygmin.patch --] [-- Type: text/x-patch, Size: 53478 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 214408) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,16 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +85,7 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 214408) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,9 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +45,7 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 214408) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,7 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +144,16 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2165,6 +2165,33 @@ assemble_variable (tree decl, int top_le DECL_NAME (decl)); in_section = sect; #else + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } + else switch_to_section (sect); #endif } Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 214408) +++ libgcc/Makefile.in (Arbeitskopie) @@ -986,6 +986,7 @@ 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 +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1002,7 +1003,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 214408) +++ libgcc/config.host (Arbeitskopie) @@ -615,6 +615,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -631,6 +634,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -648,6 +654,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -694,6 +703,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 214408) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 214408) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -98,9 +98,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 214408) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are build. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -45,26 +78,27 @@ __VLTChangePermission(int) __attribute__ void __VLTRegisterSet(void**, const void*, std::size_t, std::size_t, - void**) __attribute__((weak)); + void**) __attribute__((weak)); void __VLTRegisterPair(void**, const void*, std::size_t, - const void*) __attribute__((weak)); + const void*) __attribute__((weak)); const void* __VLTVerifyVtablePointer(void**, const void*) __attribute__((weak)); void __VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, - void**) __attribute__((weak)); + void**) __attribute__((weak)); void __VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, - const char*, const char*) __attribute__((weak)); + const char*, const char*) __attribute__((weak)); const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, - const char*) __attribute__((weak)); + const char*) __attribute__((weak)); +#endif #endif // Stub definitions. @@ -91,10 +125,10 @@ __VLTRegisterSetDebug(void**, const void void __VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, - const char*, const char*) + const char*, const char*) { } const void* __VLTVerifyVtablePointerDebug(void**, const void* vtable_ptr, const char*, - const char*) + const char*) { return vtable_ptr; } Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 214408) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 214408) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,25 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +104,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 214408) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 214408) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/obstack.c =================================================================== --- libvtv/obstack.c (Revision 0) +++ libvtv/obstack.c (Arbeitskopie) @@ -0,0 +1,515 @@ +/* obstack.c - subroutines used implicitly by object stack macros + Copyright (C) 1988,89,90,91,92,93,94,96,97 Free Software Foundation, Inc. + + + NOTE: This source is derived from an old version taken from the GNU C + Library (glibc). + + This program 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 2, or (at your option) any + later version. + + This program 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. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include <windows.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "obstack.h" + +/* NOTE BEFORE MODIFYING THIS FILE: This version number must be + incremented whenever callers compiled using an old obstack.h can no + longer properly call the functions in this obstack.c. */ +#define OBSTACK_INTERFACE_VERSION 1 + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself, and the installed library + supports the same library interface we do. This code is part of the GNU + C Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object + files, it is simpler to just do this in the source for each such file. */ + +#include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */ +#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1 +#include <gnu-versions.h> +#if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION +#define ELIDE_CODE +#endif +#endif + + +#ifndef ELIDE_CODE + + +#define POINTER void * + +/* Determine default alignment. */ +struct fooalign {char x; double d;}; +#define DEFAULT_ALIGNMENT \ + ((PTR_INT_TYPE) ((char *) &((struct fooalign *) 0)->d - (char *) 0)) +/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT. + But in fact it might be less smart and round addresses to as much as + DEFAULT_ROUNDING. So we prepare for it to do that. */ +union fooround {long x; double d;}; +#define DEFAULT_ROUNDING (sizeof (union fooround)) + +/* When we copy a long block of data, this is the unit to do it with. + On some machines, copying successive ints does not work; + in such a case, redefine COPYING_UNIT to `long' (if that works) + or `char' as a last resort. */ +#ifndef COPYING_UNIT +#define COPYING_UNIT int +#endif + + +/* The functions allocating more room by calling `obstack_chunk_alloc' + jump to the handler pointed to by `obstack_alloc_failed_handler'. + This variable by default points to the internal function + `print_and_abort'. */ +static void print_and_abort (void); +void (*obstack_alloc_failed_handler) (void) = print_and_abort; + +/* Exit value used when `print_and_abort' is used. */ +#if defined __GNU_LIBRARY__ || defined HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifndef EXIT_FAILURE +#define EXIT_FAILURE 1 +#endif +int obstack_exit_failure = EXIT_FAILURE; + +/* The non-GNU-C macros copy the obstack into this global variable + to avoid multiple evaluation. */ + +struct obstack *_obstack; + +/* Define a macro that either calls functions with the traditional malloc/free + calling interface, or calls functions with the mmalloc/mfree interface + (that adds an extra first argument), based on the state of use_extra_arg. + For free, do not use ?:, since some compilers, like the MIPS compilers, + do not allow (expr) ? void : void. */ + +#if defined (__STDC__) && __STDC__ +#define CALL_CHUNKFUN(h, size) \ + (((h) -> use_extra_arg) \ + ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \ + : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size))) + +#define CALL_FREEFUN(h, old_chunk) \ + do { \ + if ((h) -> use_extra_arg) \ + (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \ + else \ + (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \ + } while (0) +#else +#define CALL_CHUNKFUN(h, size) \ + (((h) -> use_extra_arg) \ + ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \ + : (*(struct _obstack_chunk *(*) ()) (h)->chunkfun) ((size))) + +#define CALL_FREEFUN(h, old_chunk) \ + do { \ + if ((h) -> use_extra_arg) \ + (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \ + else \ + (*(void (*) ()) (h)->freefun) ((old_chunk)); \ + } while (0) +#endif + +\f +/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default). + Objects start on multiples of ALIGNMENT (0 means use default). + CHUNKFUN is the function to use to allocate chunks, + and FREEFUN the function to free them. + + Return nonzero if successful, zero if out of memory. + To recover from an out of memory error, + free up some memory, then call this again. */ + +int +_obstack_begin (struct obstack *h, int size, int alignment, + POINTER (*chunkfun) (long), void (*freefun) (void *)) +{ + register struct _obstack_chunk *chunk; /* points to new chunk */ + + if (alignment == 0) + alignment = (int) DEFAULT_ALIGNMENT; + if (size == 0) + /* Default size is what GNU malloc can fit in a 4096-byte block. */ + { + /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc. + Use the values for range checking, because if range checking is off, + the extra bytes won't be missed terribly, but if range checking is on + and we used a larger request, a whole extra 4096 bytes would be + allocated. + + These number are irrelevant to the new GNU malloc. I suspect it is + less sensitive to the size of the request. */ + int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1)) + + 4 + DEFAULT_ROUNDING - 1) + & ~(DEFAULT_ROUNDING - 1)); + size = 4096 - extra; + } + + h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun; + h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; + h->chunk_size = size; + h->alignment_mask = alignment - 1; + h->use_extra_arg = 0; + + chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size); + if (!chunk) + (*obstack_alloc_failed_handler) (); + h->next_free = h->object_base = chunk->contents; + h->chunk_limit = chunk->limit + = (char *) chunk + h->chunk_size; + chunk->prev = 0; + /* The initial chunk now contains no empty object. */ + h->maybe_empty_object = 0; + h->alloc_failed = 0; + return 1; +} + +int +_obstack_begin_1 (struct obstack *h, int size, int alignment, + POINTER (*chunkfun) (POINTER, long), + void (*freefun) (POINTER, POINTER), POINTER arg) +{ + register struct _obstack_chunk *chunk; /* points to new chunk */ + + if (alignment == 0) + alignment = (int) DEFAULT_ALIGNMENT; + if (size == 0) + /* Default size is what GNU malloc can fit in a 4096-byte block. */ + { + /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc. + Use the values for range checking, because if range checking is off, + the extra bytes won't be missed terribly, but if range checking is on + and we used a larger request, a whole extra 4096 bytes would be + allocated. + + These number are irrelevant to the new GNU malloc. I suspect it is + less sensitive to the size of the request. */ + int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1)) + + 4 + DEFAULT_ROUNDING - 1) + & ~(DEFAULT_ROUNDING - 1)); + size = 4096 - extra; + } + + h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun; + h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; + h->chunk_size = size; + h->alignment_mask = alignment - 1; + h->extra_arg = arg; + h->use_extra_arg = 1; + + chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size); + if (!chunk) + (*obstack_alloc_failed_handler) (); + h->next_free = h->object_base = chunk->contents; + h->chunk_limit = chunk->limit + = (char *) chunk + h->chunk_size; + chunk->prev = 0; + /* The initial chunk now contains no empty object. */ + h->maybe_empty_object = 0; + h->alloc_failed = 0; + return 1; +} + +/* Allocate a new current chunk for the obstack *H + on the assumption that LENGTH bytes need to be added + to the current object, or a new object of length LENGTH allocated. + Copies any partial object from the end of the old chunk + to the beginning of the new one. */ + +void +_obstack_newchunk (struct obstack *h, int length) +{ + register struct _obstack_chunk *old_chunk = h->chunk; + register struct _obstack_chunk *new_chunk; + register long new_size; + register long obj_size = h->next_free - h->object_base; + register long i; + long already; + + /* Compute size for new chunk. */ + new_size = (obj_size + length) + (obj_size >> 3) + 100; + if (new_size < h->chunk_size) + new_size = h->chunk_size; + + /* Allocate and initialize the new chunk. */ + new_chunk = CALL_CHUNKFUN (h, new_size); + if (!new_chunk) + (*obstack_alloc_failed_handler) (); + h->chunk = new_chunk; + new_chunk->prev = old_chunk; + new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size; + + /* Move the existing object to the new chunk. + Word at a time is fast and is safe if the object + is sufficiently aligned. */ + if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT) + { + for (i = obj_size / sizeof (COPYING_UNIT) - 1; + i >= 0; i--) + ((COPYING_UNIT *)new_chunk->contents)[i] + = ((COPYING_UNIT *)h->object_base)[i]; + /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT, + but that can cross a page boundary on a machine + which does not do strict alignment for COPYING_UNITS. */ + already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT); + } + else + already = 0; + /* Copy remaining bytes one by one. */ + for (i = already; i < obj_size; i++) + new_chunk->contents[i] = h->object_base[i]; + + /* If the object just copied was the only data in OLD_CHUNK, + free that chunk and remove it from the chain. + But not if that chunk might contain an empty object. */ + if (h->object_base == old_chunk->contents && ! h->maybe_empty_object) + { + new_chunk->prev = old_chunk->prev; + CALL_FREEFUN (h, old_chunk); + } + + h->object_base = new_chunk->contents; + h->next_free = h->object_base + obj_size; + /* The new chunk certainly contains no empty object yet. */ + h->maybe_empty_object = 0; +} + +/* Return nonzero if object OBJ has been allocated from obstack H. + This is here for debugging. + If you use it in a program, you are probably losing. */ + +/* Suppress -Wmissing-prototypes warning. We don't want to declare this in + obstack.h because it is just for debugging. */ +int _obstack_allocated_p (struct obstack *h, POINTER obj); + +int +_obstack_allocated_p (struct obstack *h, POINTER obj) +{ + register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ + register struct _obstack_chunk *plp; /* point to previous chunk if any */ + + lp = (h)->chunk; + /* We use >= rather than > since the object cannot be exactly at + the beginning of the chunk but might be an empty object exactly + at the end of an adjacent chunk. */ + while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj)) + { + plp = lp->prev; + lp = plp; + } + return lp != 0; +} +\f +/* Free objects in obstack H, including OBJ and everything allocate + more recently than OBJ. If OBJ is zero, free everything in H. */ + +#undef obstack_free + +/* This function has two names with identical definitions. + This is the first one, called from non-ANSI code. */ + +void +_obstack_free (struct obstack *h, POINTER obj) +{ + register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ + register struct _obstack_chunk *plp; /* point to previous chunk if any */ + + lp = h->chunk; + /* We use >= because there cannot be an object at the beginning of a chunk. + But there can be an empty object at that address + at the end of another chunk. */ + while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj)) + { + plp = lp->prev; + CALL_FREEFUN (h, lp); + lp = plp; + /* If we switch chunks, we can't tell whether the new current + chunk contains an empty object, so assume that it may. */ + h->maybe_empty_object = 1; + } + if (lp) + { + h->object_base = h->next_free = (char *) (obj); + h->chunk_limit = lp->limit; + h->chunk = lp; + } + else if (obj != 0) + /* obj is not in any of the chunks! */ + //abort (); + TerminateProcess(GetCurrentProcess(),0xff); +} + +/* This function is used from ANSI code. */ + +void +obstack_free (struct obstack *h, POINTER obj) +{ + register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ + register struct _obstack_chunk *plp; /* point to previous chunk if any */ + + lp = h->chunk; + /* We use >= because there cannot be an object at the beginning of a chunk. + But there can be an empty object at that address + at the end of another chunk. */ + while (lp != 0 && ((POINTER) lp >= obj || (POINTER) (lp)->limit < obj)) + { + plp = lp->prev; + CALL_FREEFUN (h, lp); + lp = plp; + /* If we switch chunks, we can't tell whether the new current + chunk contains an empty object, so assume that it may. */ + h->maybe_empty_object = 1; + } + if (lp) + { + h->object_base = h->next_free = (char *) (obj); + h->chunk_limit = lp->limit; + h->chunk = lp; + } + else if (obj != 0) + /* obj is not in any of the chunks! */ + abort (); + TerminateProcess(GetCurrentProcess(),0xff); +} +\f +int +_obstack_memory_used (struct obstack *h) +{ + register struct _obstack_chunk* lp; + register int nbytes = 0; + + for (lp = h->chunk; lp != 0; lp = lp->prev) + { + nbytes += lp->limit - (char *) lp; + } + return nbytes; +} +\f +/* Define the error handler. */ +#ifndef _ +# if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC +# include <libintl.h> +# ifndef _ +# define _(Str) gettext (Str) +# endif +# else +# define _(Str) (Str) +# endif +#endif + +static void +print_and_abort (void) +{ + fputs (_("memory exhausted\n"), stderr); + //exit (obstack_exit_failure); + ExitProcess(obstack_exit_failure); +} +\f +#if 0 +/* These are now turned off because the applications do not use it + and it uses bcopy via obstack_grow, which causes trouble on sysV. */ + +/* Now define the functional versions of the obstack macros. + Define them to simply use the corresponding macros to do the job. */ + +/* The function names appear in parentheses in order to prevent + the macro-definitions of the names from being expanded there. */ + +POINTER (obstack_base) (struct obstack *obstack) +{ + return obstack_base (obstack); +} + +POINTER (obstack_next_free) (struct obstack *obstack) +{ + return obstack_next_free (obstack); +} + +int (obstack_object_size) (struct obstack *obstack) +{ + return obstack_object_size (obstack); +} + +int (obstack_room) (struct obstack *obstack) +{ + return obstack_room (obstack); +} + +int (obstack_make_room) (struct obstack *obstack, int length) +{ + return obstack_make_room (obstack, length); +} + +void (obstack_grow) (struct obstack *obstack, POINTER pointer, int length) +{ + obstack_grow (obstack, pointer, length); +} + +void (obstack_grow0) (struct obstack *obstack, POINTER pointer, int length) +{ + obstack_grow0 (obstack, pointer, length); +} + +void (obstack_1grow) (struct obstack *obstack, int character) +{ + obstack_1grow (obstack, character); +} + +void (obstack_blank) (struct obstack *obstack, int length) +{ + obstack_blank (obstack, length); +} + +void (obstack_1grow_fast) (struct obstack *obstack, int character) +{ + obstack_1grow_fast (obstack, character); +} + +void (obstack_blank_fast) (struct obstack *obstack, int length) +{ + obstack_blank_fast (obstack, length); +} + +POINTER (obstack_finish) (struct obstack *obstack) +{ + return obstack_finish (obstack); +} + +POINTER (obstack_alloc) (struct obstack *obstack, int length) +{ + return obstack_alloc (obstack, length); +} + +POINTER (obstack_copy) (struct obstack *obstack, POINTER pointer, int length) +{ + return obstack_copy (obstack, pointer, length); +} + +POINTER (obstack_copy0) (struct obstack *obstack, POINTER pointer, int length) +{ + return obstack_copy0 (obstack, pointer, length); +} + +#endif /* 0 */ + +#endif /* !ELIDE_CODE */ Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 214408) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 214408) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,44 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} + +int +mprotect (void *addr, int len, int prot) +{ + DWORD np, op; + + if (prot == 7) + np = 0x40; + else if (prot == 5) + np = 0x20; + else if (prot == 4) + np = 0x10; + else if (prot == 3 || prot == 2) + np = 0x04; + else if (prot == 1) + np = 0x02; + else if (prot == 0) + np = 0x01; + else + return -1; + + if (VirtualProtect (addr, len, np, &op)) + return 0; + else + return -1; +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,10 +204,16 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); + VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); current_chunk = allocated; @@ -190,7 +238,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 214408) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,12 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +int +mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 214408) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 214408) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,13 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + abort(); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +174,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +329,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +359,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +429,122 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + // Check if we have to get the section name from the COFF string table. + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +691,110 @@ read_section_offset_and_length (struct d } } } +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, (uintptr_t) hMods[i], map_sect_name, *mprotect_flags, + &map_sect_offset, &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +899,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +926,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +943,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +960,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1124,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1134,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1144,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1618,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1649,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1659,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 214408) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else + mkdir (logs_prefix, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } ^ permalink raw reply [flat|nested] 47+ messages in thread
* [Ping] Port of VTV for Cygwin and MinGW 2014-08-28 11:04 Port of VTV for Cygwin and MinGW Patrick Wollgast @ 2014-09-11 4:12 ` Patrick Wollgast [not found] ` <CABtf2+RU7frwOXOX2FF8Tmfc6ssrpfFVj1Vuue4cZt19FpSWtQ@mail.gmail.com> 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-09-11 4:12 UTC (permalink / raw) To: gcc-patches, libstdc++; +Cc: cmtice [-- Attachment #1: Type: text/plain, Size: 3171 bytes --] Ping for https://gcc.gnu.org/ml/gcc-patches/2014-08/msg02559.html Also added Caroline Tice, as libvtv maintainer, to cc and attached virtual_func_test_min_UAF.cpp, which I forgot in the original mail. Patrick On 28.08.2014 13:03, Patrick Wollgast wrote: > This patch contains a port of VTV -fvtable-verify=std for Cygwin and MinGW. > > Since weak symbols on Windows and Linux are implemented differently, and > VTV should have the possibility to be switched on and off, the structure > of the feature had to be modified. > On Linux libstdc++ contains the weak stub functions of VTV. For Cygwin > and MinGW they have been removed, due to the difference of weak symbols. > On Linux and on Windows libstdc++ itself gets build with > -fvtable-verify=std. Since libvtv gets build after libstdc++, and > libstdc++ doesn't contain the stub functions any more, 'undefined > reference' errors are thrown during linking of libstdc++. To prevent > these errors during the linking process a libvtv-0.dll gets build from > the stub functions before libstdc++-6.dll is linked. > At the end of the build process two VTV dlls have been build. One is > called libvtv-0.dll, containing the real functions, the other is called > libvtv_stubs-0.dll, containing the stub functions. Depending on whether > libvtv-0.dll is first found in the dll search path or > libvtv_stubs-0.dll, renamed to libvtv-0.dll, the real functions or the > stub functions are used. > > Testing: > The test builds were configured the following way: > Linux 64bit (from patched and unpatched trunk): > /path/to/configure --prefix=/prefix/gcc-vtv-bin-64 > --enable-libstdcxx-threads --enable-vtable-verify=yes > MinGW 32bit cross compiled: > /path/to/configure --target=i686-w64-mingw32 > --prefix=/prefix/mingw-vtv-bin-32 --with-gnu-ld --with-gnu-as > --enable-fully-dynamic-string --disable-multilib > --enable-libstdcxx-threads --enable-vtable-verify=yes > MinGW 64bit cross compiled: > /path/to/configure --target=x86_64-w64-mingw32 > --prefix=/prefix/mingw-vtv-bin-64 --with-gnu-ld --with-gnu-as > --enable-fully-dynamic-string --disable-multilib > --enable-libstdcxx-threads --enable-vtable-verify=yes > Cygwin 64bit: > /path/to/configure --enable-languages=c,c++ --enable-libstdcxx-threads > --enable-vtable-verify=yes > > At Linux the patched and unpatched version resulted in the same number > of passed tests with 'make check-target-libvtv'. > > Since MinGW was cross compiled the test cases couldn't be built and run > with 'make check-target-libvtv'. Therefore they were built with the > attached makefiles and tested afterwards on Windows 7 64bit. Some test > cases contain Linux specific parts and weren't tested. See the makefiles > for further information. Additionally virtual_func_test_min_UAF.cpp was > also built and tested. All built tests passed. > > Cygwin was just tested on gcc 4.9.0, because the current trunk isn't > building for me. Even the clean trunk without the patch attached to this > mail. On Cygwin with gcc 4.9.0 VTV worked. > > Besides the test cases Botan was also built and tested (gcc 4.9.0) with > MinGW 32bit and VTV. > > regards > -- Beste GrüÃe, Patrick [-- Attachment #2: virtual_func_test_min_UAF.cpp --] [-- Type: text/x-c++src, Size: 2667 bytes --] #include<iostream> #include<stdio.h> /* * Demonstrates an use after free c++ internally by deleting an object * and resetting its vtable pointing to legitimate functions */ // set pointer size and integer size dependent on architechture #if __x86_64__ /* 64-bit */ const char* arch = "x86_64"; int ptrSize = 8; typedef long long myInt; // 8 byte #else /* 32-bit */ const char* arch = "x86"; int ptrSize = 4; typedef int myInt; // 4 byte #endif // using namespace std; // BASE CLASS class Addition{ protected: // member variables int s1,s2; public: // virtual member function will be implemented in derived class virtual int add(int a,int b){ }; int i; }; // // inherit new class class Add: public Addition{ public: // constructor: /* Add(int a, int b){ s1 = a; s2 = b; }; */ void setvals(int a, int b){ s1 = a; s2 = b; } // implement virtual function virtual int TRIGGER(){ cout<<s1 + s2<<"\n"; }; int j; }; // // use this function in vtable which will be injected void inject(){ printf("%s\n","I've been executed"); } int main(){ printf("We're on a %s architecture\n\n",arch); // create object of inherited class //Add* A = new Add(4,5); Add* A = new Add; //heap allocation happens here A->setvals(4,5); // add attributes A->i = 6; A->j = 7; // get vtable address myInt vtablePTR = NULL; vtablePTR = *((myInt*)A); printf("vtable: %.16x\n", vtablePTR); //function 1 printf("%.16x : %.16x\n", vtablePTR, *((myInt*)vtablePTR)); //function 2 printf("%.16x : %.16x\n", vtablePTR + ptrSize, *((myInt*)(vtablePTR + ptrSize))); // call instantiated virtual function (legitimate) A->TRIGGER(); // FREE OBJECT ! delete A; //A = NULL; // this prevents use after free // get objects address as it is still valid myInt* ObjPTR = (myInt*)A; // let object point to old vtable (inject old vtable) *ObjPTR = vtablePTR; // NOT legitimate A->TRIGGER(); myInt vtable_func = (myInt)inject; // create new vtable myInt vtable_new[2] = {vtable_func, vtable_func}; // let object point to new vtable (inject new vtable) *ObjPTR = (myInt)vtable_new; // USE AFTER FREE (execute injected function in vtable) A->TRIGGER(); __asm__( "nop;" "nop;" "nop;" ); // USE AFTER FREE with data members printf("%i %i\n", A->i, A->j); } ^ permalink raw reply [flat|nested] 47+ messages in thread
[parent not found: <CABtf2+RU7frwOXOX2FF8Tmfc6ssrpfFVj1Vuue4cZt19FpSWtQ@mail.gmail.com>]
* Re: [Ping] Port of VTV for Cygwin and MinGW [not found] ` <CABtf2+RU7frwOXOX2FF8Tmfc6ssrpfFVj1Vuue4cZt19FpSWtQ@mail.gmail.com> @ 2014-09-12 22:44 ` Caroline Tice 2014-09-18 22:24 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Caroline Tice @ 2014-09-12 22:44 UTC (permalink / raw) To: Patrick Wollgast; +Cc: GCC Patches, libstdc++ First attempt to send this failed. On Fri, Sep 12, 2014 at 3:41 PM, Caroline Tice <cmtice@google.com> wrote: > > Hi Patrick, > > Mostly your patch looks OK to me, though there are a couple of serious issues (mentioned below). Most of my comments are for formatting stuff. Once you have fixed these issues, let me know and I'll look at it again. But someone else will still have to approve the parts of this patch that are outside the libvtv directory (I believe). > > -- Caroline Tice > cmtice@google.com > > > 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. > > 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. > > 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. > > 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 > > 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... > > 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. > > 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. > > 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)? > > > > On Wed, Sep 10, 2014 at 9:12 PM, Patrick Wollgast <patrick.wollgast@rub.de> wrote: >> >> Ping for https://gcc.gnu.org/ml/gcc-patches/2014-08/msg02559.html >> >> Also added Caroline Tice, as libvtv maintainer, to cc and attached >> virtual_func_test_min_UAF.cpp, which I forgot in the original mail. >> >> Patrick >> >> On 28.08.2014 13:03, Patrick Wollgast wrote: >> > This patch contains a port of VTV -fvtable-verify=std for Cygwin and MinGW. >> > >> > Since weak symbols on Windows and Linux are implemented differently, and >> > VTV should have the possibility to be switched on and off, the structure >> > of the feature had to be modified. >> > On Linux libstdc++ contains the weak stub functions of VTV. For Cygwin >> > and MinGW they have been removed, due to the difference of weak symbols. >> > On Linux and on Windows libstdc++ itself gets build with >> > -fvtable-verify=std. Since libvtv gets build after libstdc++, and >> > libstdc++ doesn't contain the stub functions any more, 'undefined >> > reference' errors are thrown during linking of libstdc++. To prevent >> > these errors during the linking process a libvtv-0.dll gets build from >> > the stub functions before libstdc++-6.dll is linked. >> > At the end of the build process two VTV dlls have been build. One is >> > called libvtv-0.dll, containing the real functions, the other is called >> > libvtv_stubs-0.dll, containing the stub functions. Depending on whether >> > libvtv-0.dll is first found in the dll search path or >> > libvtv_stubs-0.dll, renamed to libvtv-0.dll, the real functions or the >> > stub functions are used. >> > >> > Testing: >> > The test builds were configured the following way: >> > Linux 64bit (from patched and unpatched trunk): >> > /path/to/configure --prefix=/prefix/gcc-vtv-bin-64 >> > --enable-libstdcxx-threads --enable-vtable-verify=yes >> > MinGW 32bit cross compiled: >> > /path/to/configure --target=i686-w64-mingw32 >> > --prefix=/prefix/mingw-vtv-bin-32 --with-gnu-ld --with-gnu-as >> > --enable-fully-dynamic-string --disable-multilib >> > --enable-libstdcxx-threads --enable-vtable-verify=yes >> > MinGW 64bit cross compiled: >> > /path/to/configure --target=x86_64-w64-mingw32 >> > --prefix=/prefix/mingw-vtv-bin-64 --with-gnu-ld --with-gnu-as >> > --enable-fully-dynamic-string --disable-multilib >> > --enable-libstdcxx-threads --enable-vtable-verify=yes >> > Cygwin 64bit: >> > /path/to/configure --enable-languages=c,c++ --enable-libstdcxx-threads >> > --enable-vtable-verify=yes >> > >> > At Linux the patched and unpatched version resulted in the same number >> > of passed tests with 'make check-target-libvtv'. >> > >> > Since MinGW was cross compiled the test cases couldn't be built and run >> > with 'make check-target-libvtv'. Therefore they were built with the >> > attached makefiles and tested afterwards on Windows 7 64bit. Some test >> > cases contain Linux specific parts and weren't tested. See the makefiles >> > for further information. Additionally virtual_func_test_min_UAF.cpp was >> > also built and tested. All built tests passed. >> > >> > Cygwin was just tested on gcc 4.9.0, because the current trunk isn't >> > building for me. Even the clean trunk without the patch attached to this >> > mail. On Cygwin with gcc 4.9.0 VTV worked. >> > >> > Besides the test cases Botan was also built and tested (gcc 4.9.0) with >> > MinGW 32bit and VTV. >> > >> > regards >> > >> >> -- >> Beste Grüße, >> Patrick > > ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-09-12 22:44 ` Caroline Tice @ 2014-09-18 22:24 ` Patrick Wollgast 2014-09-23 6:16 ` Caroline Tice 2014-09-23 10:22 ` Jonathan Wakely 0 siblings, 2 replies; 47+ messages in thread From: Patrick Wollgast @ 2014-09-18 22:24 UTC (permalink / raw) To: Caroline Tice, bkoz, ktietz; +Cc: GCC Patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 3620 bytes --] 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. regards Patrick [-- Attachment #2: ChangeLog --] [-- Type: text/plain, Size: 4246 bytes --] * 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 for CUSTOM_CRTSTUFF. * 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. [-- Attachment #3: vtv_cygmin.patch --] [-- Type: text/x-patch, Size: 38799 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 214408) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,18 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +87,8 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 214408) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,10 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +46,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 214408) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +145,18 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1182,7 +1182,7 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1190,7 +1190,7 @@ vtv_generate_init_routine (void) cgraph_process_new_functions (); - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) assemble_vtv_preinit_initializer (vtv_fndecl); } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2165,6 +2165,33 @@ assemble_variable (tree decl, int top_le DECL_NAME (decl)); in_section = sect; #else + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } + else switch_to_section (sect); #endif } Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 214408) +++ libgcc/Makefile.in (Arbeitskopie) @@ -986,6 +986,7 @@ 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 +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1002,7 +1003,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 214408) +++ libgcc/config.host (Arbeitskopie) @@ -615,6 +615,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -631,6 +634,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -648,6 +654,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -694,6 +703,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libiberty/obstack.c =================================================================== --- libiberty/obstack.c (Revision 214408) +++ libiberty/obstack.c (Arbeitskopie) @@ -20,6 +20,10 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#endif + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -353,7 +357,11 @@ _obstack_free (struct obstack *h, POINTE } else if (obj != 0) /* obj is not in any of the chunks! */ +#if defined (__CYGWIN__) || defined (__MINGW32__) + TerminateProcess(GetCurrentProcess(),0xff); +#else abort (); +#endif } /* This function is used from ANSI code. */ @@ -385,7 +393,11 @@ obstack_free (struct obstack *h, POINTER } else if (obj != 0) /* obj is not in any of the chunks! */ +#if defined (__CYGWIN__) || defined (__MINGW32__) + TerminateProcess(GetCurrentProcess(),0xff); +#else abort (); +#endif } \f int @@ -417,7 +429,11 @@ static void print_and_abort (void) { fputs (_("memory exhausted\n"), stderr); +#if defined (__CYGWIN__) || defined (__MINGW32__) + ExitProcess(obstack_exit_failure); +#else exit (obstack_exit_failure); +#endif } \f #if 0 Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 214408) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 214408) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -98,9 +98,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 214408) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are built. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -66,6 +99,7 @@ const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, const char*) __attribute__((weak)); #endif +#endif // Stub definitions. extern "C" Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 214408) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 214408) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,29 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + obstack.c: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libiberty/obstack.c $@ + + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +108,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 214408) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 214408) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 214408) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 214408) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,44 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} + +int +mprotect (void *addr, int len, int prot) +{ + DWORD np, op; + + if (prot == 7) + np = 0x40; + else if (prot == 5) + np = 0x20; + else if (prot == 4) + np = 0x10; + else if (prot == 3 || prot == 2) + np = 0x04; + else if (prot == 1) + np = 0x02; + else if (prot == 0) + np = 0x01; + else + return -1; + + if (VirtualProtect (addr, len, np, &op)) + return 0; + else + return -1; +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,8 +204,13 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); @@ -190,7 +237,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 214408) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,12 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +int +mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 214408) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 214408) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,14 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + // ERROR_BAD_FUNCTION_TABLE + TerminateProcess(GetCurrentProcess(), 0x22F); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +175,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +330,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +360,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +430,130 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = + (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + /* Check if we have to get the section name from the COFF string + table. */ + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, + name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, + sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE + - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +700,125 @@ read_section_offset_and_length (struct d } } } +#endif + +#if defined (__CYGWIN__) || defined (__MINGW32__) +/* This function is used to iterate over all loaded modules and searches + for a section called ".vtable_map_vars". The only interaction with + the binary file on disk of the module is to read section names in the + COFF string table. If the module contains a ".vtable_map_vars" section, + read section offset and size from the section header of the loaded module. + Call 'mprotect' on those pages, setting the protection either to + read-only or read-write, depending on what's in data. + The calls to change the protection occur in vtv_unprotect_vtable_vars + and vtv_protect_vtable_vars. */ + +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, + (uintptr_t) hMods[i], + map_sect_name, + *mprotect_flags, + &map_sect_offset, + &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) + / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +923,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +950,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +967,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +984,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1148,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1158,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1168,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1642,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1673,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1683,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 214408) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (log_dir); +#else + mkdir (log_dir, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-09-18 22:24 ` Patrick Wollgast @ 2014-09-23 6:16 ` Caroline Tice 2014-09-23 10:22 ` Jonathan Wakely 1 sibling, 0 replies; 47+ messages in thread From: Caroline Tice @ 2014-09-23 6:16 UTC (permalink / raw) To: Patrick Wollgast; +Cc: bkoz, ktietz, GCC Patches, libstdc++ Ok, your patch looks OK to me, but I can only approve the libvtv file changes. The changes in the other files also seem ok to me, but someone else will have to approve the modifications in them: gcc/config/i386/cygwin.h gcc/config/i386/mingw-w64.h gcc/config/i386/mingw32.h gcc/cp/vtable-class-hierarchy.c gcc/varasm.c libgcc/Makefile.in libgcc/config.host libiberty/obstack.c libstdc++-v3/acinclude.m4 libstdc++-v3/libsupc++/Makefile.am libstdc++-v3/libsupc++/vtv_stubs.cc -- Caroline Tice cmtice@google.com On Thu, Sep 18, 2014 at 3:23 PM, Patrick Wollgast <patrick.wollgast@rub.de> wrote: > 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. > > regards > Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-09-18 22:24 ` Patrick Wollgast 2014-09-23 6:16 ` Caroline Tice @ 2014-09-23 10:22 ` Jonathan Wakely 2014-09-24 22:25 ` Patrick Wollgast 1 sibling, 1 reply; 47+ messages in thread From: Jonathan Wakely @ 2014-09-23 10:22 UTC (permalink / raw) To: Patrick Wollgast; +Cc: Caroline Tice, bkoz, ktietz, GCC Patches, libstdc++ On 19/09/14 00:23 +0200, Patrick Wollgast wrote: >Index: libstdc++-v3/acinclude.m4 >=================================================================== >--- libstdc++-v3/acinclude.m4 (Revision 214408) >+++ libstdc++-v3/acinclude.m4 (Arbeitskopie) >@@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], > AC_MSG_RESULT([$enable_vtable_verify]) > > if test $enable_vtable_verify = yes; then >+ case ${target_os} in >+ cygwin*|mingw32*) >+ VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" >+ vtv_cygmin="yes" >+ ;; >+ *) > VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" >+ vtv_cygmin="no" >+ ;; >+ esac >+ AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) > VTV_PCH_CXXFLAGS="-fvtable-verify=std" > VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" > else The lines between case and esac should be indented by four more spaces. Apart from that the libstdc++ changes are OK and I'll approve them. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-09-23 10:22 ` Jonathan Wakely @ 2014-09-24 22:25 ` Patrick Wollgast 2014-09-27 10:50 ` Kai Tietz 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-09-24 22:25 UTC (permalink / raw) To: Jonathan Wakely, cmtice@google.com >> Caroline Tice Cc: bkoz, ktietz, iant, GCC Patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 1920 bytes --] On 23.09.2014 12:22, Jonathan Wakely wrote: > On 19/09/14 00:23 +0200, Patrick Wollgast wrote: >> Index: libstdc++-v3/acinclude.m4 >> =================================================================== >> --- libstdc++-v3/acinclude.m4 (Revision 214408) >> +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) >> @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], >> AC_MSG_RESULT([$enable_vtable_verify]) >> >> if test $enable_vtable_verify = yes; then >> + case ${target_os} in >> + cygwin*|mingw32*) >> + VTV_CXXFLAGS="-fvtable-verify=std >> -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" >> + vtv_cygmin="yes" >> + ;; >> + *) >> VTV_CXXFLAGS="-fvtable-verify=std >> -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" >> + vtv_cygmin="no" >> + ;; >> + esac >> + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) >> VTV_PCH_CXXFLAGS="-fvtable-verify=std" >> VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath >> -Wl,${toplevel_builddir}/libvtv/.libs" >> else > > The lines between case and esac should be indented by four more > spaces. > > Apart from that the libstdc++ changes are OK and I'll approve them. > I've changed the indentation at the newly attached patch. On 23.09.2014 08:16, Caroline Tice wrote: > Ok, your patch looks OK to me, but I can only approve the libvtv file > changes. The changes in the other files also seem ok to me, but > someone else will have to approve the modifications in them: > > gcc/config/i386/cygwin.h > gcc/config/i386/mingw-w64.h > gcc/config/i386/mingw32.h > gcc/cp/vtable-class-hierarchy.c > gcc/varasm.c > > libgcc/Makefile.in > libgcc/config.host > > libiberty/obstack.c > > libstdc++-v3/acinclude.m4 > libstdc++-v3/libsupc++/Makefile.am > libstdc++-v3/libsupc++/vtv_stubs.cc I've added Ian Lance Taylor to cc of this mail. Thank you both for the reviews! regards Patrick [-- Attachment #2: vtv_cygmin.patch --] [-- Type: text/x-patch, Size: 38923 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 214408) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,18 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +87,8 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 214408) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,10 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +46,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 214408) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +145,18 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1182,7 +1182,7 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1190,7 +1190,7 @@ vtv_generate_init_routine (void) cgraph_process_new_functions (); - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) assemble_vtv_preinit_initializer (vtv_fndecl); } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2165,6 +2165,33 @@ assemble_variable (tree decl, int top_le DECL_NAME (decl)); in_section = sect; #else + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } + else switch_to_section (sect); #endif } Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 214408) +++ libgcc/Makefile.in (Arbeitskopie) @@ -986,6 +986,7 @@ 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 +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1002,7 +1003,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 214408) +++ libgcc/config.host (Arbeitskopie) @@ -615,6 +615,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -631,6 +634,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -648,6 +654,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -694,6 +703,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libiberty/obstack.c =================================================================== --- libiberty/obstack.c (Revision 214408) +++ libiberty/obstack.c (Arbeitskopie) @@ -20,6 +20,10 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#endif + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -353,7 +357,11 @@ _obstack_free (struct obstack *h, POINTE } else if (obj != 0) /* obj is not in any of the chunks! */ +#if defined (__CYGWIN__) || defined (__MINGW32__) + TerminateProcess(GetCurrentProcess(),0xff); +#else abort (); +#endif } /* This function is used from ANSI code. */ @@ -385,7 +393,11 @@ obstack_free (struct obstack *h, POINTER } else if (obj != 0) /* obj is not in any of the chunks! */ +#if defined (__CYGWIN__) || defined (__MINGW32__) + TerminateProcess(GetCurrentProcess(),0xff); +#else abort (); +#endif } \f int @@ -417,7 +429,11 @@ static void print_and_abort (void) { fputs (_("memory exhausted\n"), stderr); +#if defined (__CYGWIN__) || defined (__MINGW32__) + ExitProcess(obstack_exit_failure); +#else exit (obstack_exit_failure); +#endif } \f #if 0 Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 214408) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then - VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 214408) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -98,9 +98,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 214408) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are built. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -66,6 +99,7 @@ const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, const char*) __attribute__((weak)); #endif +#endif // Stub definitions. extern "C" Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 214408) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 214408) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,29 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + obstack.c: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libiberty/obstack.c $@ + + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +108,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 214408) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 214408) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 214408) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 214408) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,44 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} + +int +mprotect (void *addr, int len, int prot) +{ + DWORD np, op; + + if (prot == 7) + np = 0x40; + else if (prot == 5) + np = 0x20; + else if (prot == 4) + np = 0x10; + else if (prot == 3 || prot == 2) + np = 0x04; + else if (prot == 1) + np = 0x02; + else if (prot == 0) + np = 0x01; + else + return -1; + + if (VirtualProtect (addr, len, np, &op)) + return 0; + else + return -1; +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,8 +204,13 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); @@ -190,7 +237,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 214408) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,12 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +int +mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 214408) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 214408) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,14 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + // ERROR_BAD_FUNCTION_TABLE + TerminateProcess(GetCurrentProcess(), 0x22F); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +175,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +330,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +360,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +430,130 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = + (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + /* Check if we have to get the section name from the COFF string + table. */ + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, + name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, + sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE + - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +700,125 @@ read_section_offset_and_length (struct d } } } +#endif + +#if defined (__CYGWIN__) || defined (__MINGW32__) +/* This function is used to iterate over all loaded modules and searches + for a section called ".vtable_map_vars". The only interaction with + the binary file on disk of the module is to read section names in the + COFF string table. If the module contains a ".vtable_map_vars" section, + read section offset and size from the section header of the loaded module. + Call 'mprotect' on those pages, setting the protection either to + read-only or read-write, depending on what's in data. + The calls to change the protection occur in vtv_unprotect_vtable_vars + and vtv_protect_vtable_vars. */ + +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, + (uintptr_t) hMods[i], + map_sect_name, + *mprotect_flags, + &map_sect_offset, + &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) + / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +923,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +950,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +967,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +984,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1148,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1158,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1168,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1642,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1673,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1683,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 214408) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (log_dir); +#else + mkdir (log_dir, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } [-- Attachment #3: ChangeLog --] [-- Type: text/plain, Size: 4246 bytes --] * 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 for CUSTOM_CRTSTUFF. * 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. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-09-24 22:25 ` Patrick Wollgast @ 2014-09-27 10:50 ` Kai Tietz 2014-10-09 13:56 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Kai Tietz @ 2014-09-27 10:50 UTC (permalink / raw) To: Patrick Wollgast Cc: Jonathan Wakely, cmtice@google.com >> Caroline Tice, bkoz, Kai Tietz, Ian Lance Taylor, GCC Patches, libstdc++ Hi Patrick, the mingw/cygwin part your patch looks fine to me. Nevertheless I have one question regarding to you. Do you have FSF papers for gcc already? As I asked an overseer and he didn't found you on the list. Regards, Kai ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-09-27 10:50 ` Kai Tietz @ 2014-10-09 13:56 ` Patrick Wollgast 2014-10-09 14:47 ` Kai Tietz 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-10-09 13:56 UTC (permalink / raw) To: Kai Tietz, Jonathan Wakely, Caroline Tice, bkoz, iant Cc: GCC Patches, libstdc++ On 27.09.2014 12:50, Kai Tietz wrote: > Hi Patrick, > > the mingw/cygwin part your patch looks fine to me. Nevertheless I > have one question regarding to you. Do you have FSF papers for gcc > already? As I asked an overseer and he didn't found you on the list. > > Regards, > Kai > The papers FSF have been taken care of, and the signed papers have been exchanged. A short recap: Mail with the latest patch and changelog: https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02200.html Approved: * gcc/config/i386/* * libstdc++-v3/* * libvtv/* Not approved: * gcc/cp/vtable-class-hierarchy.c * gcc/varasm.c * libgcc/Makefile.in * libgcc/config.host * libiberty/obstack.c Regards, Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-10-09 13:56 ` Patrick Wollgast @ 2014-10-09 14:47 ` Kai Tietz 2014-10-16 10:23 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Kai Tietz @ 2014-10-09 14:47 UTC (permalink / raw) To: Patrick Wollgast Cc: Jonathan Wakely, Caroline Tice, Benjamin De Kosnik, Ian Lance Taylor, GCC Patches, libstdc++ 2014-10-09 15:52 GMT+02:00 Patrick Wollgast <patrick.wollgast@rub.de>: > On 27.09.2014 12:50, Kai Tietz wrote: >> Hi Patrick, >> >> the mingw/cygwin part your patch looks fine to me. Nevertheless I >> have one question regarding to you. Do you have FSF papers for gcc >> already? As I asked an overseer and he didn't found you on the list. >> >> Regards, >> Kai >> > > The papers FSF have been taken care of, and the signed papers have been > exchanged. > > > A short recap: > > Mail with the latest patch and changelog: > https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02200.html > > Approved: > * gcc/config/i386/* > * libstdc++-v3/* > * libvtv/* > > Not approved: > * gcc/cp/vtable-class-hierarchy.c Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1182,7 +1182,7 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) You need to check that TARGET_PECOFF is defined. Otherwise you break compilation for none i386 targets. DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1190,7 +1190,7 @@ vtv_generate_init_routine (void) cgraph_process_new_functions (); - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) See above. Likewise assemble_vtv_preinit_initializer (vtv_fndecl); } > * gcc/varasm.c Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2165,6 +2165,33 @@ assemble_variable (tree decl, int top_le DECL_NAME (decl)); in_section = sect; #else + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) You need to test, if TARGET_PECOFF is defined! + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, Here it seems to me that you have some whitespace issues, + DECL_NAME (decl)); + in_section = sect; + } + else switch_to_section (sect); #endif > * libgcc/Makefile.in Looks ok to me. > * libgcc/config.host Looks fine to me, too. > * libiberty/obstack.c Why you use instead of C-runtime exit/abort-functions the platform-functions to terminate the process. This looks to me like useless change. For cygwin this might be even wrong in some aspects. What is the reasoning for this change? Another note I have about re-implementation of mprotect in --- libvtv/vtv_malloc.cc. Why you need that? it is already part of libgcc for mingw. And for cygwin this function is part of cygwin's library itself. So why re-implementing it here? > Regards, > Patrick Regards, Kai ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-10-09 14:47 ` Kai Tietz @ 2014-10-16 10:23 ` Patrick Wollgast 2014-10-30 14:51 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-10-16 10:23 UTC (permalink / raw) To: Kai Tietz, Caroline Tice, bkoz, Jonathan Wakely, iant Cc: GCC Patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 6552 bytes --] On 09.10.2014 16:42, Kai Tietz wrote: >> Not approved: >> * gcc/cp/vtable-class-hierarchy.c > > Index: gcc/cp/vtable-class-hierarchy.c > =================================================================== > --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) > +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) > @@ -1182,7 +1182,7 @@ vtv_generate_init_routine (void) > TREE_STATIC (vtv_fndecl) = 1; > TREE_USED (vtv_fndecl) = 1; > DECL_PRESERVE_P (vtv_fndecl) = 1; > - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) > + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) > > You need to check that TARGET_PECOFF is defined. Otherwise you break > compilation for none i386 targets. > > DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; > > gimplify_function_tree (vtv_fndecl); > @@ -1190,7 +1190,7 @@ vtv_generate_init_routine (void) > > cgraph_process_new_functions (); > > - if (flag_vtable_verify == VTV_PREINIT_PRIORITY) > + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) > > See above. Likewise > assemble_vtv_preinit_initializer (vtv_fndecl); > > } > > >> * gcc/varasm.c > > Index: gcc/varasm.c > =================================================================== > --- gcc/varasm.c (Revision 214408) > +++ gcc/varasm.c (Arbeitskopie) > @@ -2165,6 +2165,33 @@ assemble_variable (tree decl, int top_le > DECL_NAME (decl)); > in_section = sect; > #else > + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. > + Therefore the following check is used. > + In case a the target is PE or COFF a comdat group section > + is created, e.g. .vtable_map_vars$foo. The linker places > + everything in .vtable_map_vars at the end. > + > + A fix could be made in > + gcc/config/i386/winnt.c: i386_pe_unique_section. */ > + if (TARGET_PECOFF) > > You need to test, if TARGET_PECOFF is defined! > > + { > + char *name; > + > + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) > + name = ACONCAT ((sect->named.name, "$", > + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); > + else > + name = ACONCAT ((sect->named.name, "$", > + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), > + NULL)); > + > + targetm.asm_out.named_section (name, > + sect->named.common.flags > + | SECTION_LINKONCE, > > Here it seems to me that you have some whitespace issues, > > + DECL_NAME (decl)); > + in_section = sect; > + } > + else > switch_to_section (sect); > #endif > This has been changed in the attached patch. > >> * libgcc/Makefile.in > > Looks ok to me. > >> * libgcc/config.host > > Looks fine to me, too. > >> * libiberty/obstack.c > > Why you use instead of C-runtime exit/abort-functions the > platform-functions to terminate the process. This looks to me like > useless change. For cygwin this might be even wrong in some aspects. > What is the reasoning for this change? > I haven't encountered crashes in obstack.c itself, but there were problems in vtv_rts.cc with abort() on MinGW 32bit. The following stack traces were taken at MinGW 32bit. Most of the time the process had to be stopped in the process manager because a wrong process handle was passed to NtTerminateProcess. This was tested and occurred on Windows 7 64bit and Windows 8.1 64bit. To be sure to avoid this issue the calls have also been exchanged in obstack.c. With abort(), correct process handle, postmortem debugger triggert. ffffffff 00000003 0028fe98 ntdll!NtTerminateProcess+0xc 00000003 77e8f3b0 ffffffff ntdll!RtlExitUserProcess+0x6d 00000003 0028f934 74f85472 KERNEL32!ExitProcessImplementation+0x12 00000003 11e9bfd9 00409000 msvcrt!exit+0x32 00000003 00000001 00000000 msvcrt!flushall+0x2e9 00000003 00010001 00000065 msvcrt!exit+0x11 6efcf294 00000080 0028ffcc msvcrt!abort+0xf3 00560f70 0000000d 00000001 libvtv_0!Z14__fortify_failPKc+0x18 7ffde000 0028ffdc 77568f8b test_std+0x13de 7ffde000 138a1dee 00000000 KERNEL32!BaseThreadInitThunk+0xe ffffffff 7755dad3 00000000 ntdll!__RtlUserThreadStart+0x20 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b With abort(), wrong process handle, NtTerminateProcess returns instead of ending the own process. This case happens most of the time. 00000000 00000003 0028fe98 ntdll!NtTerminateProcess+0x5 00000003 77e8f3b0 ffffffff ntdll!RtlExitUserProcess+0x35 00000003 0028f934 74f85472 KERNEL32!ExitProcessImplementation+0x12 00000003 9f9f5ea3 00409000 msvcrt!exit+0x32 00000003 00000001 00000000 msvcrt!flushall+0x2e9 00000003 00010001 00000040 msvcrt!exit+0x11 6efcf294 00000080 0028ffcc msvcrt!abort+0xf3 00701060 0000001e 00000001 libvtv_0!Z14__fortify_failPKc+0x18 7ffde000 0028ffdc 77568f8b image00400000+0x13de 7ffde000 9defd39c 00000000 KERNEL32!BaseThreadInitThunk+0xe ffffffff 7755dac5 00000000 ntdll!__RtlUserThreadStart+0x20 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b TerminateProcess. Everything's fine on MinGW x86, x86-64 (both gcc 5.0), Cygwin x86-64 (gcc 4.9.0). ffffffff 0000022f 0028feb8 ntdll!NtTerminateProcess+0x5 ffffffff 0000022f 00409000 KERNELBASE!TerminateProcess+0x27 00731060 0000001e 00000001 libvtv_0!Z14__fortify_failPKc+0x2a 7ffde000 0028ffdc 77568f8b image00400000+0x13de 7ffde000 e2645ec6 00000000 KERNEL32!BaseThreadInitThunk+0xe ffffffff 7755dae7 00000000 ntdll!__RtlUserThreadStart+0x20 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b > Another note I have about re-implementation of mprotect in --- > libvtv/vtv_malloc.cc. Why you need that? it is already part of > libgcc for mingw. And for cygwin this function is part of cygwin's > library itself. So why re-implementing it here? > It is already part of libgcc for MinGW, but it can neither be found in the exports of the dll, nor can the function prototype be found in any header files. Therefore I get unknown reference errors if I don't re-implement it. I checked the exports of several compilations for this. * self compiled MinGW * MinGW installed from the Arch Linux repositories * http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-bin_x86_64-linux_20131228.tar.bz2/download If I'm missing something here let me know. [-- Attachment #2: ChangeLog --] [-- Type: text/plain, Size: 4247 bytes --] * 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 for CUSTOM_CRTSTUFF. * 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. [-- Attachment #3: vtv_cygmin.patch --] [-- Type: text/x-patch, Size: 39179 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 214408) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,18 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +87,8 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 214408) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,10 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +46,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 214408) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +145,18 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1182,7 +1182,11 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1190,7 +1194,11 @@ vtv_generate_init_routine (void) cgraph_process_new_functions (); +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif assemble_vtv_preinit_initializer (vtv_fndecl); } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2164,7 +2164,34 @@ assemble_variable (tree decl, int top_le | SECTION_LINKONCE, DECL_NAME (decl)); in_section = sect; -#else +#elif defined (TARGET_PECOFF) + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } + else switch_to_section (sect); #endif } Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 214408) +++ libgcc/Makefile.in (Arbeitskopie) @@ -986,6 +986,7 @@ 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 +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1002,7 +1003,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 214408) +++ libgcc/config.host (Arbeitskopie) @@ -615,6 +615,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -631,6 +634,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -648,6 +654,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -694,6 +703,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libiberty/obstack.c =================================================================== --- libiberty/obstack.c (Revision 214408) +++ libiberty/obstack.c (Arbeitskopie) @@ -20,6 +20,10 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#endif + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -353,7 +357,11 @@ _obstack_free (struct obstack *h, POINTE } else if (obj != 0) /* obj is not in any of the chunks! */ +#if defined (__CYGWIN__) || defined (__MINGW32__) + TerminateProcess(GetCurrentProcess(),0xff); +#else abort (); +#endif } /* This function is used from ANSI code. */ @@ -385,7 +393,11 @@ obstack_free (struct obstack *h, POINTER } else if (obj != 0) /* obj is not in any of the chunks! */ +#if defined (__CYGWIN__) || defined (__MINGW32__) + TerminateProcess(GetCurrentProcess(),0xff); +#else abort (); +#endif } \f int @@ -417,7 +429,11 @@ static void print_and_abort (void) { fputs (_("memory exhausted\n"), stderr); +#if defined (__CYGWIN__) || defined (__MINGW32__) + ExitProcess(obstack_exit_failure); +#else exit (obstack_exit_failure); +#endif } \f #if 0 Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 214408) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then - VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 214408) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -98,9 +98,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 214408) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are built. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -66,6 +99,7 @@ const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, const char*) __attribute__((weak)); #endif +#endif // Stub definitions. extern "C" Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 214408) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 214408) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,29 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + obstack.c: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libiberty/obstack.c $@ + + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +108,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 214408) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 214408) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 214408) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 214408) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,44 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} + +int +mprotect (void *addr, int len, int prot) +{ + DWORD np, op; + + if (prot == 7) + np = 0x40; + else if (prot == 5) + np = 0x20; + else if (prot == 4) + np = 0x10; + else if (prot == 3 || prot == 2) + np = 0x04; + else if (prot == 1) + np = 0x02; + else if (prot == 0) + np = 0x01; + else + return -1; + + if (VirtualProtect (addr, len, np, &op)) + return 0; + else + return -1; +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,8 +204,13 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); @@ -190,7 +237,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 214408) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,12 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +int +mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 214408) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 214408) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,14 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + // ERROR_BAD_FUNCTION_TABLE + TerminateProcess(GetCurrentProcess(), 0x22F); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +175,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +330,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +360,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +430,130 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = + (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + /* Check if we have to get the section name from the COFF string + table. */ + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, + name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, + sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE + - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +700,125 @@ read_section_offset_and_length (struct d } } } +#endif + +#if defined (__CYGWIN__) || defined (__MINGW32__) +/* This function is used to iterate over all loaded modules and searches + for a section called ".vtable_map_vars". The only interaction with + the binary file on disk of the module is to read section names in the + COFF string table. If the module contains a ".vtable_map_vars" section, + read section offset and size from the section header of the loaded module. + Call 'mprotect' on those pages, setting the protection either to + read-only or read-write, depending on what's in data. + The calls to change the protection occur in vtv_unprotect_vtable_vars + and vtv_protect_vtable_vars. */ + +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, + (uintptr_t) hMods[i], + map_sect_name, + *mprotect_flags, + &map_sect_offset, + &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) + / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +923,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +950,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +967,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +984,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1148,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1158,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1168,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1642,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1673,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1683,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 214408) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (log_dir); +#else + mkdir (log_dir, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-10-16 10:23 ` Patrick Wollgast @ 2014-10-30 14:51 ` Patrick Wollgast 2014-11-12 16:23 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-10-30 14:51 UTC (permalink / raw) To: Kai Tietz, Caroline Tice, bkoz, Jonathan Wakely, iant Cc: GCC Patches, libstdc++ Since I haven't heard back for quite a while, I wanted to ask what the current stat of the patch is. Is the patch from the last mail approved ( https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01524.html ), or should the matters discussed further? regards, Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-10-30 14:51 ` Patrick Wollgast @ 2014-11-12 16:23 ` Patrick Wollgast 2014-11-12 17:05 ` Kai Tietz 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-11-12 16:23 UTC (permalink / raw) To: Kai Tietz, Caroline Tice, bkoz, Jonathan Wakely, ian Cc: gcc-patches, libstdc++ Ping for the question below. On 30.10.2014 15:29, Patrick Wollgast wrote: > Since I haven't heard back for quite a while, I wanted to ask what the > current stat of the patch is. > > Is the patch from the last mail approved ( > https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01524.html ), or should > the matters discussed further? > > regards, > Patrick > ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-11-12 16:23 ` Patrick Wollgast @ 2014-11-12 17:05 ` Kai Tietz 2014-11-12 17:47 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Kai Tietz @ 2014-11-12 17:05 UTC (permalink / raw) To: Patrick Wollgast Cc: Caroline Tice, Benjamin De Kosnik, Jonathan Wakely, Ian Lance Taylor, GCC Patches, libstdc++ 014-11-12 17:22 GMT+01:00 Patrick Wollgast <patrick.wollgast@rub.de>: > Ping for the question below. > > On 30.10.2014 15:29, Patrick Wollgast wrote: >> Since I haven't heard back for quite a while, I wanted to ask what the >> current stat of the patch is. >> >> Is the patch from the last mail approved ( >> https://gcc.gnu.org/ml/gcc-patches/2014-10/msg01524.html ), or should >> the matters discussed further? >> >> regards, >> Patrick >> I don't think you have addressed all of the comments I made in the comment, do you? Regards, Kai ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-11-12 17:05 ` Kai Tietz @ 2014-11-12 17:47 ` Patrick Wollgast 2014-11-12 18:45 ` Kai Tietz 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-11-12 17:47 UTC (permalink / raw) To: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, iant Cc: gcc-patches, libstdc++ > > I don't think you have addressed all of the comments I made in the > comment, do you? > > Regards, > Kai > I added the three checks, if TARGET_PECOFF is defined, and fixed the whitespace issues. For the questions regarding C-runtime/Win32 functions I haven't changed anything in the patch but explained why I used those functions. >> Why you use instead of C-runtime exit/abort-functions the >> platform-functions to terminate the process. This looks to me like >> useless change. For cygwin this might be even wrong in some aspects. >> What is the reasoning for this change? >> > > I haven't encountered crashes in obstack.c itself, but there were > problems in vtv_rts.cc with abort() on MinGW 32bit. The following stack > traces were taken at MinGW 32bit. Most of the time the process had to be > stopped in the process manager because a wrong process handle was passed > to NtTerminateProcess. This was tested and occurred on Windows 7 64bit > and Windows 8.1 64bit. To be sure to avoid this issue the calls have > also been exchanged in obstack.c. > > With abort(), correct process handle, postmortem debugger triggert. > > ffffffff 00000003 0028fe98 ntdll!NtTerminateProcess+0xc > 00000003 77e8f3b0 ffffffff ntdll!RtlExitUserProcess+0x6d > 00000003 0028f934 74f85472 KERNEL32!ExitProcessImplementation+0x12 > 00000003 11e9bfd9 00409000 msvcrt!exit+0x32 > 00000003 00000001 00000000 msvcrt!flushall+0x2e9 > 00000003 00010001 00000065 msvcrt!exit+0x11 > 6efcf294 00000080 0028ffcc msvcrt!abort+0xf3 > 00560f70 0000000d 00000001 libvtv_0!Z14__fortify_failPKc+0x18 > 7ffde000 0028ffdc 77568f8b test_std+0x13de > 7ffde000 138a1dee 00000000 KERNEL32!BaseThreadInitThunk+0xe > ffffffff 7755dad3 00000000 ntdll!__RtlUserThreadStart+0x20 > 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b > > With abort(), wrong process handle, NtTerminateProcess returns instead > of ending the own process. This case happens most of the time. > > 00000000 00000003 0028fe98 ntdll!NtTerminateProcess+0x5 > 00000003 77e8f3b0 ffffffff ntdll!RtlExitUserProcess+0x35 > 00000003 0028f934 74f85472 KERNEL32!ExitProcessImplementation+0x12 > 00000003 9f9f5ea3 00409000 msvcrt!exit+0x32 > 00000003 00000001 00000000 msvcrt!flushall+0x2e9 > 00000003 00010001 00000040 msvcrt!exit+0x11 > 6efcf294 00000080 0028ffcc msvcrt!abort+0xf3 > 00701060 0000001e 00000001 libvtv_0!Z14__fortify_failPKc+0x18 > 7ffde000 0028ffdc 77568f8b image00400000+0x13de > 7ffde000 9defd39c 00000000 KERNEL32!BaseThreadInitThunk+0xe > ffffffff 7755dac5 00000000 ntdll!__RtlUserThreadStart+0x20 > 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b > > TerminateProcess. Everything's fine on MinGW x86, x86-64 (both gcc 5.0), > Cygwin x86-64 (gcc 4.9.0). > > ffffffff 0000022f 0028feb8 ntdll!NtTerminateProcess+0x5 > ffffffff 0000022f 00409000 KERNELBASE!TerminateProcess+0x27 > 00731060 0000001e 00000001 libvtv_0!Z14__fortify_failPKc+0x2a > 7ffde000 0028ffdc 77568f8b image00400000+0x13de > 7ffde000 e2645ec6 00000000 KERNEL32!BaseThreadInitThunk+0xe > ffffffff 7755dae7 00000000 ntdll!__RtlUserThreadStart+0x20 > 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b Regarding the question, why I reimplemented mprotect, I also haven't changed anything in the patch but answered the question. >> Another note I have about re-implementation of mprotect in --- >> libvtv/vtv_malloc.cc. Why you need that? it is already part of >> libgcc for mingw. And for cygwin this function is part of cygwin's >> library itself. So why re-implementing it here? >> > > It is already part of libgcc for MinGW, but it can neither be found in > the exports of the dll, nor can the function prototype be found in any > header files. Therefore I get unknown reference errors if I don't > re-implement it. I checked the exports of several compilations for this. > > * self compiled MinGW > * MinGW installed from the Arch Linux repositories > * > http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-bin_x86_64-linux_20131228.tar.bz2/download > > If I'm missing something here let me know. I think this was everything you addressed. Regards, Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-11-12 17:47 ` Patrick Wollgast @ 2014-11-12 18:45 ` Kai Tietz 2014-11-27 9:59 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Kai Tietz @ 2014-11-12 18:45 UTC (permalink / raw) To: Patrick Wollgast Cc: cmtice@google.com >> Caroline Tice, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, Ian Lance Taylor, GCC Patches, libstdc++ 2014-11-12 18:45 GMT+01:00 Patrick Wollgast <patrick.wollgast@rub.de>: >> >> I don't think you have addressed all of the comments I made in the >> comment, do you? >> >> Regards, >> Kai >> > > I added the three checks, if TARGET_PECOFF is defined, and fixed the > whitespace issues. > > For the questions regarding C-runtime/Win32 functions I haven't changed > anything in the patch but explained why I used those functions. > >>> Why you use instead of C-runtime exit/abort-functions the >>> platform-functions to terminate the process. This looks to me like >>> useless change. For cygwin this might be even wrong in some aspects. >>> What is the reasoning for this change? >>> >> >> I haven't encountered crashes in obstack.c itself, but there were >> problems in vtv_rts.cc with abort() on MinGW 32bit. The following stack >> traces were taken at MinGW 32bit. Most of the time the process had to be >> stopped in the process manager because a wrong process handle was passed >> to NtTerminateProcess. This was tested and occurred on Windows 7 64bit >> and Windows 8.1 64bit. To be sure to avoid this issue the calls have >> also been exchanged in obstack.c. >> >> With abort(), correct process handle, postmortem debugger triggert. >> >> ffffffff 00000003 0028fe98 ntdll!NtTerminateProcess+0xc >> 00000003 77e8f3b0 ffffffff ntdll!RtlExitUserProcess+0x6d >> 00000003 0028f934 74f85472 KERNEL32!ExitProcessImplementation+0x12 >> 00000003 11e9bfd9 00409000 msvcrt!exit+0x32 >> 00000003 00000001 00000000 msvcrt!flushall+0x2e9 >> 00000003 00010001 00000065 msvcrt!exit+0x11 >> 6efcf294 00000080 0028ffcc msvcrt!abort+0xf3 >> 00560f70 0000000d 00000001 libvtv_0!Z14__fortify_failPKc+0x18 >> 7ffde000 0028ffdc 77568f8b test_std+0x13de >> 7ffde000 138a1dee 00000000 KERNEL32!BaseThreadInitThunk+0xe >> ffffffff 7755dad3 00000000 ntdll!__RtlUserThreadStart+0x20 >> 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b >> >> With abort(), wrong process handle, NtTerminateProcess returns instead >> of ending the own process. This case happens most of the time. >> >> 00000000 00000003 0028fe98 ntdll!NtTerminateProcess+0x5 >> 00000003 77e8f3b0 ffffffff ntdll!RtlExitUserProcess+0x35 >> 00000003 0028f934 74f85472 KERNEL32!ExitProcessImplementation+0x12 >> 00000003 9f9f5ea3 00409000 msvcrt!exit+0x32 >> 00000003 00000001 00000000 msvcrt!flushall+0x2e9 >> 00000003 00010001 00000040 msvcrt!exit+0x11 >> 6efcf294 00000080 0028ffcc msvcrt!abort+0xf3 >> 00701060 0000001e 00000001 libvtv_0!Z14__fortify_failPKc+0x18 >> 7ffde000 0028ffdc 77568f8b image00400000+0x13de >> 7ffde000 9defd39c 00000000 KERNEL32!BaseThreadInitThunk+0xe >> ffffffff 7755dac5 00000000 ntdll!__RtlUserThreadStart+0x20 >> 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b >> >> TerminateProcess. Everything's fine on MinGW x86, x86-64 (both gcc 5.0), >> Cygwin x86-64 (gcc 4.9.0). >> >> ffffffff 0000022f 0028feb8 ntdll!NtTerminateProcess+0x5 >> ffffffff 0000022f 00409000 KERNELBASE!TerminateProcess+0x27 >> 00731060 0000001e 00000001 libvtv_0!Z14__fortify_failPKc+0x2a >> 7ffde000 0028ffdc 77568f8b image00400000+0x13de >> 7ffde000 e2645ec6 00000000 KERNEL32!BaseThreadInitThunk+0xe >> ffffffff 7755dae7 00000000 ntdll!__RtlUserThreadStart+0x20 >> 004014e0 7ffde000 00000000 ntdll!_RtlUserThreadStart+0x1b TerminateProcess is actually bad, as it doesn't call any of the atexit handlers. You simply nuke the process off. For cygwin this behavior is inacceptable. Why a classical abort, or a classical exit call cause for you that issues? It seems to me more related to some other thing you try to paper over by this. > Regarding the question, why I reimplemented mprotect, I also haven't > changed anything in the patch but answered the question. And this doesn't make it better. It is present in the static part of libgcc. Have you tried to declare it with extern "C" (for C++ case) and simply use it? Cygwin provides its own version too. So there seems to me no real need to re-implement it. >>> Another note I have about re-implementation of mprotect in --- >>> libvtv/vtv_malloc.cc. Why you need that? it is already part of >>> libgcc for mingw. And for cygwin this function is part of cygwin's >>> library itself. So why re-implementing it here? >>> >> >> It is already part of libgcc for MinGW, but it can neither be found in >> the exports of the dll, nor can the function prototype be found in any >> header files. Therefore I get unknown reference errors if I don't >> re-implement it. I checked the exports of several compilations for this. >> >> * self compiled MinGW >> * MinGW installed from the Arch Linux repositories >> * >> > http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-bin_x86_64-linux_20131228.tar.bz2/download >> >> If I'm missing something here let me know. > > I think this was everything you addressed. > > Regards, > Patrick Regards, Kai ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-11-12 18:45 ` Kai Tietz @ 2014-11-27 9:59 ` Patrick Wollgast 2014-12-10 16:37 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-11-27 9:59 UTC (permalink / raw) To: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, iant Cc: gcc-patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 1285 bytes --] On 12.11.2014 19:40, Kai Tietz wrote: > TerminateProcess is actually bad, as it doesn't call any of the atexit > handlers. You simply nuke the process off. For cygwin this behavior > is inacceptable. Why a classical abort, or a classical exit call > cause for you that issues? It seems to me more related to some other > thing you try to paper over by this. > It turns out the test program made some trouble. I rewrote it to the attached program (virtual_func_test_min_AW.cpp). I changed obstack.c and vtv_rts.cc to the C-runtime functions. For testing I used a program just containing an abort and all three tests in the attached test program. The call stack, passed parameters and behavior matched at the crucial parts (tested again on MinGW 32/64bit). > >> Regarding the question, why I reimplemented mprotect, I also haven't >> changed anything in the patch but answered the question. > > And this doesn't make it better. It is present in the static part of > libgcc. Have you tried to declare it with extern "C" (for C++ case) > and simply use it? > Cygwin provides its own version too. So there seems to me no real > need to re-implement it. > You're right. I was stuck with the idea of importing it dynamically, but changed it to extern "C" now. Regards, Patrick [-- Attachment #2: ChangeLog --] [-- Type: text/plain, Size: 4051 bytes --] * 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 for CUSTOM_CRTSTUFF. * 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. * 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 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. [-- Attachment #3: virtual_func_test_min_AW.cpp --] [-- Type: text/x-c++src, Size: 3011 bytes --] #include <iostream> #include <stdio.h> #include <stdlib.h> #include <windows.h> using namespace std; /* * TEST can be defined as 1, 2 or 3. * * TEST == 1: * After the TRIGGER function gets called legitimate, abort is called. * TEST == 2: * After the TRIGGER function gets called legitimate, __fortify_fail is * called manually. * TEST == 3: * The vtable pointer of A is overwritten to point to a fake vtable, * always containing the inject function, after setvals is called and * before TRIGGER is called. VTV should detect this at the call of TRIGGER * and terminate with __fortify_fail. * This simulates an arbitrary write vulnerability overwriting a vtable * pointer. */ #define TEST 1 #if TEST == 2 typedef void (__stdcall *__fortify_fail) (const char * msg); #endif #if TEST == 3 // set pointer size and integer size dependent on architechture #if __x86_64__ /* 64-bit */ const char* arch = "x86_64"; int ptrSize = 8; typedef long long myInt; // 8 byte #else /* 32-bit */ const char* arch = "x86"; int ptrSize = 4; typedef int myInt; // 4 byte #endif // #endif // BASE CLASS class Addition{ protected: // member variables int s1,s2; public: // virtual member function will be implemented in derived class virtual int add(int a,int b){ }; int i; }; // // inherit new class class Add: public Addition{ public: // constructor: /* Add(int a, int b){ s1 = a; s2 = b; }; */ void setvals(int a, int b){ s1 = a; s2 = b; } // implement virtual function virtual int TRIGGER(){ cout<<s1 + s2<<"\n"; }; int j; }; // #if TEST == 3 // use this function in vtable which will be injected void inject(){ printf("%s\n","I've been executed"); } #endif int main(){ // create object of inherited class //Add* A = new Add(4,5); Add* A = new Add; //heap allocation happens here A->setvals(4,5); // add attributes A->i = 6; A->j = 7; #if TEST == 3 myInt vtable_func = (myInt)inject; // create new vtable myInt vtable_new[2] = {vtable_func, vtable_func}; *((myInt *)A) = (myInt)vtable_new; #endif // call instantiated virtual function (legitimate if not TEST 3) A->TRIGGER(); // FREE OBJECT ! delete A; #if TEST == 1 abort(); #elif TEST == 2 HMODULE vtv = GetModuleHandle("libvtv-0.dll"); if (vtv != NULL) { __fortify_fail fortify_fail = (void (__stdcall *) (const char * msg)) GetProcAddress(vtv, "_Z14__fortify_failPKc"); if (fortify_fail != NULL) { fortify_fail("testcall\n"); } else { printf("Failed to get fortify_fail.\n"); } } else { printf("Failed to get vtv.\n"); } #endif } [-- Attachment #4: vtv_cygmin.patch --] [-- Type: text/x-patch, Size: 37425 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 214408) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,18 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +87,8 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 214408) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,10 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +46,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 214408) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +145,18 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1182,7 +1182,11 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1190,7 +1194,11 @@ vtv_generate_init_routine (void) cgraph_process_new_functions (); +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif assemble_vtv_preinit_initializer (vtv_fndecl); } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2164,7 +2164,34 @@ assemble_variable (tree decl, int top_le | SECTION_LINKONCE, DECL_NAME (decl)); in_section = sect; -#else +#elif defined (TARGET_PECOFF) + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } + else switch_to_section (sect); #endif } Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 214408) +++ libgcc/Makefile.in (Arbeitskopie) @@ -986,6 +986,7 @@ 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 +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1002,7 +1003,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 214408) +++ libgcc/config.host (Arbeitskopie) @@ -615,6 +615,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -631,6 +634,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -648,6 +654,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -694,6 +703,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 214408) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then - VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 214408) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -98,9 +98,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 214408) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are built. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -66,6 +99,7 @@ const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, const char*) __attribute__((weak)); #endif +#endif // Stub definitions. extern "C" Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 214408) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 214408) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,29 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + obstack.c: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libiberty/obstack.c $@ + + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +108,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 214408) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 214408) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 214408) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 214408) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,18 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,8 +178,13 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); @@ -190,7 +211,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 214408) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,11 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" int mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 214408) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 214408) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,13 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + abort(); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +174,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +329,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +359,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +429,130 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = + (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + /* Check if we have to get the section name from the COFF string + table. */ + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, + name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, + sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE + - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +699,125 @@ read_section_offset_and_length (struct d } } } +#endif + +#if defined (__CYGWIN__) || defined (__MINGW32__) +/* This function is used to iterate over all loaded modules and searches + for a section called ".vtable_map_vars". The only interaction with + the binary file on disk of the module is to read section names in the + COFF string table. If the module contains a ".vtable_map_vars" section, + read section offset and size from the section header of the loaded module. + Call 'mprotect' on those pages, setting the protection either to + read-only or read-write, depending on what's in data. + The calls to change the protection occur in vtv_unprotect_vtable_vars + and vtv_protect_vtable_vars. */ + +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, + (uintptr_t) hMods[i], + map_sect_name, + *mprotect_flags, + &map_sect_offset, + &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) + / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +922,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +949,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +966,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +983,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1147,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1157,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1167,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1641,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1672,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1682,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 214408) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (log_dir); +#else + mkdir (log_dir, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-11-27 9:59 ` Patrick Wollgast @ 2014-12-10 16:37 ` Patrick Wollgast 2015-01-04 20:10 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2014-12-10 16:37 UTC (permalink / raw) To: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, iant Cc: gcc-patches, libstdc++ Ping. https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html On 27.11.2014 10:42, Patrick Wollgast wrote: > On 12.11.2014 19:40, Kai Tietz wrote: >> TerminateProcess is actually bad, as it doesn't call any of the atexit >> handlers. You simply nuke the process off. For cygwin this behavior >> is inacceptable. Why a classical abort, or a classical exit call >> cause for you that issues? It seems to me more related to some other >> thing you try to paper over by this. >> > > It turns out the test program made some trouble. I rewrote it to the > attached program (virtual_func_test_min_AW.cpp). I changed obstack.c and > vtv_rts.cc to the C-runtime functions. For testing I used a program just > containing an abort and all three tests in the attached test program. > The call stack, passed parameters and behavior matched at the crucial > parts (tested again on MinGW 32/64bit). > >> >>> Regarding the question, why I reimplemented mprotect, I also haven't >>> changed anything in the patch but answered the question. >> >> And this doesn't make it better. It is present in the static part of >> libgcc. Have you tried to declare it with extern "C" (for C++ case) >> and simply use it? >> Cygwin provides its own version too. So there seems to me no real >> need to re-implement it. >> > > You're right. I was stuck with the idea of importing it dynamically, but > changed it to extern "C" now. > > Regards, > Patrick > ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2014-12-10 16:37 ` Patrick Wollgast @ 2015-01-04 20:10 ` Patrick Wollgast 2015-01-08 20:34 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2015-01-04 20:10 UTC (permalink / raw) To: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, iant Cc: gcc-patches, libstdc++ On 10.12.2014 17:37, Patrick Wollgast wrote: > Ping. > > https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html > > On 27.11.2014 10:42, Patrick Wollgast wrote: >> On 12.11.2014 19:40, Kai Tietz wrote: >>> TerminateProcess is actually bad, as it doesn't call any of the atexit >>> handlers. You simply nuke the process off. For cygwin this behavior >>> is inacceptable. Why a classical abort, or a classical exit call >>> cause for you that issues? It seems to me more related to some other >>> thing you try to paper over by this. >>> >> >> It turns out the test program made some trouble. I rewrote it to the >> attached program (virtual_func_test_min_AW.cpp). I changed obstack.c and >> vtv_rts.cc to the C-runtime functions. For testing I used a program just >> containing an abort and all three tests in the attached test program. >> The call stack, passed parameters and behavior matched at the crucial >> parts (tested again on MinGW 32/64bit). >> >>> >>>> Regarding the question, why I reimplemented mprotect, I also haven't >>>> changed anything in the patch but answered the question. >>> >>> And this doesn't make it better. It is present in the static part of >>> libgcc. Have you tried to declare it with extern "C" (for C++ case) >>> and simply use it? >>> Cygwin provides its own version too. So there seems to me no real >>> need to re-implement it. >>> >> >> You're right. I was stuck with the idea of importing it dynamically, but >> changed it to extern "C" now. >> >> Regards, >> Patrick >> ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-04 20:10 ` Patrick Wollgast @ 2015-01-08 20:34 ` Patrick Wollgast 2015-01-12 18:32 ` Caroline Tice 2015-01-14 19:28 ` Ian Lance Taylor 0 siblings, 2 replies; 47+ messages in thread From: Patrick Wollgast @ 2015-01-08 20:34 UTC (permalink / raw) To: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, iant Cc: gcc-patches, libstdc++ A short recap again: Latest patch, changelog and a test program (further information about the program in the mail): https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html Approved: * gcc/config/i386/* * libgcc/* * libstdc++-v3/* * libvtv/* (Some changes made to three of these files. Listed in 'Not approved'.) Not approved: For the following two files I added checks, if TARGET_PECOFF is defined ( https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00815.html ) * gcc/cp/vtable-class-hierarchy.c * gcc/varasm.c Reasons for changes in the following files stated in https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00815.html and in the mail of the latest patch. Removed implementation of mprotect. * libvtv/vtv_malloc.cc Added extern "C" to the prototype of mprotect. * libvtv/vtv_malloc.h Exchanged call to TerminateProcess with call to abort in __fortify_fail. * libvtv/vtv_rts.cc Has been removed from the most recent patch. Just listed for completeness. * libiberty/obstack.c Regards, Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-08 20:34 ` Patrick Wollgast @ 2015-01-12 18:32 ` Caroline Tice 2015-01-14 19:28 ` Ian Lance Taylor 1 sibling, 0 replies; 47+ messages in thread From: Caroline Tice @ 2015-01-12 18:32 UTC (permalink / raw) To: Patrick Wollgast Cc: Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, Ian Lance Taylor, GCC Patches, libstdc++ On Thu, Jan 8, 2015 at 12:33 PM, Patrick Wollgast <patrick.wollgast@rub.de> wrote: > A short recap again: > > Latest patch, changelog and a test program (further information about > the program in the mail): > https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html > > > Approved: > * gcc/config/i386/* > * libgcc/* > * libstdc++-v3/* > * libvtv/* (Some changes made to three of these files. > Listed in 'Not approved'.) > > > Not approved: > For the following two files I added checks, if TARGET_PECOFF is defined > ( https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00815.html ) > * gcc/cp/vtable-class-hierarchy.c > * gcc/varasm.c The changes in gcc/cp/vtable-class-hierarchy.c and gcc/varasm.c both look good to me. However I am not authorized to approve stuff in this part of GCC, so I need someone with global approval rights to look at these changes and give the final OK. > > Reasons for changes in the following files stated in > https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00815.html and in the mail > of the latest patch. > > Removed implementation of mprotect. > * libvtv/vtv_malloc.cc > Added extern "C" to the prototype of mprotect. > * libvtv/vtv_malloc.h > Exchanged call to TerminateProcess with call to abort in __fortify_fail. > * libvtv/vtv_rts.cc The changes in libvtv all look good to me (approved). -- Caroline Tice cmtice@google.com > > Has been removed from the most recent patch. Just listed for completeness. > * libiberty/obstack.c > > > Regards, > Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-08 20:34 ` Patrick Wollgast 2015-01-12 18:32 ` Caroline Tice @ 2015-01-14 19:28 ` Ian Lance Taylor 2015-01-14 21:23 ` Patrick Wollgast 1 sibling, 1 reply; 47+ messages in thread From: Ian Lance Taylor @ 2015-01-14 19:28 UTC (permalink / raw) To: Patrick Wollgast Cc: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 8, 2015 at 12:33 PM, Patrick Wollgast <patrick.wollgast@rub.de> wrote: > A short recap again: > > Latest patch, changelog and a test program (further information about > the program in the mail): > https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html In that patch, the change to varasm.c looks wrong if neither OBJECT_FORMAT_ELF nor TARGET_PECOFF are defined. It looks like you've dropped the switch_to_section call in that case. Ian ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-14 19:28 ` Ian Lance Taylor @ 2015-01-14 21:23 ` Patrick Wollgast 2015-01-14 23:56 ` Ian Lance Taylor 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2015-01-14 21:23 UTC (permalink / raw) To: Ian Lance Taylor Cc: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 644 bytes --] On 14.01.2015 20:00, Ian Lance Taylor wrote: > On Thu, Jan 8, 2015 at 12:33 PM, Patrick Wollgast > <patrick.wollgast@rub.de> wrote: >> A short recap again: >> >> Latest patch, changelog and a test program (further information about >> the program in the mail): >> https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html > > In that patch, the change to varasm.c looks wrong if neither > OBJECT_FORMAT_ELF nor TARGET_PECOFF are defined. It looks like you've > dropped the switch_to_section call in that case. > > Ian > You're right. It should have been '#else' again, instead of 'else' before the switch_to_section call. Regards, Patrick [-- Attachment #2: vtv_cygmin.patch --] [-- Type: text/x-patch, Size: 37408 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 214408) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,18 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +87,8 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 214408) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,10 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +46,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 214408) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +145,18 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1182,7 +1182,11 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1190,7 +1194,11 @@ vtv_generate_init_routine (void) cgraph_process_new_functions (); +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif assemble_vtv_preinit_initializer (vtv_fndecl); } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2164,6 +2164,33 @@ assemble_variable (tree decl, int top_le | SECTION_LINKONCE, DECL_NAME (decl)); in_section = sect; +#elif defined (TARGET_PECOFF) + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } #else switch_to_section (sect); #endif Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 214408) +++ libgcc/Makefile.in (Arbeitskopie) @@ -986,6 +986,7 @@ 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 +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1002,7 +1003,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 214408) +++ libgcc/config.host (Arbeitskopie) @@ -615,6 +615,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -631,6 +634,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -648,6 +654,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -694,6 +703,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 214408) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then - VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 214408) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -98,9 +98,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 214408) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are built. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -66,6 +99,7 @@ const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, const char*) __attribute__((weak)); #endif +#endif // Stub definitions. extern "C" Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 214408) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 214408) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,29 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + obstack.c: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libiberty/obstack.c $@ + + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +108,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 214408) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 214408) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 214408) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 214408) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,18 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,8 +178,13 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); @@ -190,7 +211,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 214408) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,11 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" int mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 214408) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 214408) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,13 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + abort(); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +174,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +329,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +359,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +429,130 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = + (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + /* Check if we have to get the section name from the COFF string + table. */ + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, + name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, + sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE + - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +699,125 @@ read_section_offset_and_length (struct d } } } +#endif + +#if defined (__CYGWIN__) || defined (__MINGW32__) +/* This function is used to iterate over all loaded modules and searches + for a section called ".vtable_map_vars". The only interaction with + the binary file on disk of the module is to read section names in the + COFF string table. If the module contains a ".vtable_map_vars" section, + read section offset and size from the section header of the loaded module. + Call 'mprotect' on those pages, setting the protection either to + read-only or read-write, depending on what's in data. + The calls to change the protection occur in vtv_unprotect_vtable_vars + and vtv_protect_vtable_vars. */ + +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, + (uintptr_t) hMods[i], + map_sect_name, + *mprotect_flags, + &map_sect_offset, + &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) + / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +922,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +949,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +966,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +983,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1147,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1157,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1167,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1641,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1672,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1682,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 214408) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (log_dir); +#else + mkdir (log_dir, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-14 21:23 ` Patrick Wollgast @ 2015-01-14 23:56 ` Ian Lance Taylor 2015-01-15 8:34 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Ian Lance Taylor @ 2015-01-14 23:56 UTC (permalink / raw) To: Patrick Wollgast Cc: Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Wed, Jan 14, 2015 at 12:28 PM, Patrick Wollgast <patrick.wollgast@rub.de> wrote: > On 14.01.2015 20:00, Ian Lance Taylor wrote: >> On Thu, Jan 8, 2015 at 12:33 PM, Patrick Wollgast >> <patrick.wollgast@rub.de> wrote: >>> A short recap again: >>> >>> Latest patch, changelog and a test program (further information about >>> the program in the mail): >>> https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html >> >> In that patch, the change to varasm.c looks wrong if neither >> OBJECT_FORMAT_ELF nor TARGET_PECOFF are defined. It looks like you've >> dropped the switch_to_section call in that case. >> >> Ian >> > > You're right. It should have been '#else' again, instead of 'else' > before the switch_to_section call. OK, the patches to varasm.c and cp/vtable-class-hierarchy.c are OK. Thanks. Ian ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-14 23:56 ` Ian Lance Taylor @ 2015-01-15 8:34 ` Patrick Wollgast 2015-01-15 16:14 ` Ian Lance Taylor 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2015-01-15 8:34 UTC (permalink / raw) To: Ian Lance Taylor, Kai Tietz, cmtice@google.com >> Caroline Tice, bkoz, jwakely@redhat.com >> Jonathan Wakely Cc: gcc-patches, libstdc++ On 15.01.2015 00:52, Ian Lance Taylor wrote: > On Wed, Jan 14, 2015 at 12:28 PM, Patrick Wollgast > <patrick.wollgast@rub.de> wrote: >> On 14.01.2015 20:00, Ian Lance Taylor wrote: >>> On Thu, Jan 8, 2015 at 12:33 PM, Patrick Wollgast >>> <patrick.wollgast@rub.de> wrote: >>>> A short recap again: >>>> >>>> Latest patch, changelog and a test program (further information about >>>> the program in the mail): >>>> https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03368.html >>> >>> In that patch, the change to varasm.c looks wrong if neither >>> OBJECT_FORMAT_ELF nor TARGET_PECOFF are defined. It looks like you've >>> dropped the switch_to_section call in that case. >>> >>> Ian >>> >> >> You're right. It should have been '#else' again, instead of 'else' >> before the switch_to_section call. > > OK, the patches to varasm.c and cp/vtable-class-hierarchy.c are OK. > > Thanks. > > Ian > Thanks to all the reviewers! Is there something I'm still supposed to do, since I don't have write access and this was the last part missing an "OK"? Regards, Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-15 8:34 ` Patrick Wollgast @ 2015-01-15 16:14 ` Ian Lance Taylor 2015-01-15 22:13 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Ian Lance Taylor @ 2015-01-15 16:14 UTC (permalink / raw) To: Patrick Wollgast Cc: Kai Tietz, cmtice@google.com >> Caroline Tice, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast <patrick.wollgast@rub.de> wrote: > Is there something I'm still supposed to do, since I don't have write > access and this was the last part missing an "OK"? Somebody with write access will need to commit the patch for you. You should send a new clean patch including all the changes, along with updated ChangeLog entries. Ian ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-15 16:14 ` Ian Lance Taylor @ 2015-01-15 22:13 ` Patrick Wollgast 2015-01-28 14:04 ` Patrick Wollgast 0 siblings, 1 reply; 47+ messages in thread From: Patrick Wollgast @ 2015-01-15 22:13 UTC (permalink / raw) To: Ian Lance Taylor, Kai Tietz, cmtice@google.com >> Caroline Tice, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely Cc: gcc-patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 2765 bytes --] On 15.01.2015 17:01, Ian Lance Taylor wrote: > On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast > <patrick.wollgast@rub.de> wrote: >> Is there something I'm still supposed to do, since I don't have write >> access and this was the last part missing an "OK"? > > Somebody with write access will need to commit the patch for you. You > should send a new clean patch including all the changes, along with > updated ChangeLog entries. > > Ian > For the clean patch I co'ed the latest version of the trunk again and applied my patch. It applies correctly, except for two changes: patching file libgcc/Makefile.in Hunk #1 succeeded at 995 with fuzz 2 (offset 9 lines). Hunk #2 succeeded at 1020 (offset 17 lines). > # This is a version of crtbegin for -static links. > crtbeginT$(objext): $(srcdir)/crtstuff.c > $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN > -DCRTSTUFFT_O > endif > > ifeq ($(enable_vtable_verify),yes) > # These are used in vtable verification; see comments in source files > for > # more details. I had to move the endif down, since something was added before "ifeq ($(enable_vtable_verify),yes)" inside the if. > # This is a version of crtbegin for -static links. > crtbeginT$(objext): $(srcdir)/crtstuff.c > $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN > -DCRTSTUFFT_O > > # crtoffloadbegin and crtoffloadend contain symbols, that mark the > begin and > # the end of tables with addresses, required for offloading. > crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c > $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN > > crtoffloadend$(objext): $(srcdir)/offloadstuff.c > $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END > endif > > ifeq ($(enable_vtable_verify),yes) > # These are used in vtable verification; see comments in source files > for > # more details. patching file libgcc/config.host Hunk #1 succeeded at 621 (offset 6 lines). Hunk #2 succeeded at 640 (offset 6 lines). Hunk #3 succeeded at 660 (offset 6 lines). Hunk #4 succeeded at 1198 with fuzz 2 (offset 495 lines). > tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" > extra_parts="$extra_parts crtfastmath.o" The last two lines were changed to the following two lines. > tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" > extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" And therefore Hunk #4, which follows these lines, wasn't applied correctly. These two parts were corrected in vtv_cygmin_clean.patch. For convenience I also added vtv_cygmin_unclean.patch, which is the patch from my last mail. Regards, Patrick [-- Attachment #2: ChangeLog --] [-- Type: text/plain, Size: 4051 bytes --] * 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 for CUSTOM_CRTSTUFF. * 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. * 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 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. [-- Attachment #3: vtv_cygmin_clean.patch --] [-- Type: text/x-patch, Size: 37384 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 219676) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,18 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +87,8 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 219676) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,10 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +46,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 219676) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +145,18 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 219676) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1194,7 +1194,11 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1202,7 +1206,11 @@ vtv_generate_init_routine (void) symtab->process_new_functions (); +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif assemble_vtv_preinit_initializer (vtv_fndecl); } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 219676) +++ gcc/varasm.c (Arbeitskopie) @@ -2252,6 +2252,33 @@ assemble_variable (tree decl, int top_le | SECTION_LINKONCE, DECL_NAME (decl)); in_section = sect; +#elif defined (TARGET_PECOFF) + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } #else switch_to_section (sect); #endif Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 219676) +++ libgcc/Makefile.in (Arbeitskopie) @@ -1003,6 +1003,7 @@ crtoffloadbegin$(objext): $(srcdir)/offl crtoffloadend$(objext): $(srcdir)/offloadstuff.c $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1019,7 +1020,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 219676) +++ libgcc/config.host (Arbeitskopie) @@ -621,6 +621,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -637,6 +640,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -654,6 +660,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -700,6 +709,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 219676) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then - VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 219676) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -100,9 +100,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 219676) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are built. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -66,6 +99,7 @@ const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, const char*) __attribute__((weak)); #endif +#endif // Stub definitions. extern "C" Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 219676) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 219676) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,29 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + obstack.c: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libiberty/obstack.c $@ + + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +108,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 219676) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 219676) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 219676) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 219676) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,18 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,8 +178,13 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); @@ -190,7 +211,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 219676) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,11 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" int mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 219676) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 219676) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,13 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + abort(); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +174,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +329,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +359,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +429,130 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = + (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + /* Check if we have to get the section name from the COFF string + table. */ + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, + name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, + sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE + - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +699,125 @@ read_section_offset_and_length (struct d } } } +#endif + +#if defined (__CYGWIN__) || defined (__MINGW32__) +/* This function is used to iterate over all loaded modules and searches + for a section called ".vtable_map_vars". The only interaction with + the binary file on disk of the module is to read section names in the + COFF string table. If the module contains a ".vtable_map_vars" section, + read section offset and size from the section header of the loaded module. + Call 'mprotect' on those pages, setting the protection either to + read-only or read-write, depending on what's in data. + The calls to change the protection occur in vtv_unprotect_vtable_vars + and vtv_protect_vtable_vars. */ + +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, + (uintptr_t) hMods[i], + map_sect_name, + *mprotect_flags, + &map_sect_offset, + &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) + / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +922,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +949,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +966,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +983,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1147,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1157,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1167,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1641,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1672,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1682,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 219676) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (log_dir); +#else + mkdir (log_dir, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } [-- Attachment #4: vtv_cygmin_unclean.patch --] [-- Type: text/x-patch, Size: 37408 bytes --] Index: gcc/config/i386/cygwin.h =================================================================== --- gcc/config/i386/cygwin.h (Revision 214408) +++ gcc/config/i386/cygwin.h (Arbeitskopie) @@ -41,12 +41,18 @@ along with GCC; see the file COPYING3. #define STARTFILE_SPEC "\ %{!shared: %{!mdll: crt0%O%s \ %{pg:gcrt0%O%s}}}\ - %{shared:crtbeginS.o%s;:crtbegin.o%s}" + %{shared:crtbeginS.o%s;:crtbegin.o%s} \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s}\ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Normally, -lgcc is not needed since everything in it is in the DLL, but we @@ -81,6 +87,8 @@ along with GCC; see the file COPYING3. %{pthread: } \ -lcygwin \ %{mwindows:-lgdi32 -lcomdlg32} \ + %{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} \ -ladvapi32 -lshell32 -luser32 -lkernel32" /* To implement C++ function replacement we always wrap the cxx Index: gcc/config/i386/mingw-w64.h =================================================================== --- gcc/config/i386/mingw-w64.h (Revision 214408) +++ gcc/config/i386/mingw-w64.h (Arbeitskopie) @@ -32,7 +32,10 @@ along with GCC; see the file COPYING3. %{!shared:%{!mdll:%{!municode:crt2%O%s}}} \ %{!shared:%{!mdll:%{municode:crt2u%O%s}}} \ %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" /* Enable multilib. */ @@ -43,6 +46,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" #undef SPEC_32 Index: gcc/config/i386/mingw32.h =================================================================== --- gcc/config/i386/mingw32.h (Revision 214408) +++ gcc/config/i386/mingw32.h (Arbeitskopie) @@ -91,6 +91,8 @@ along with GCC; see the file COPYING3. #define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \ "%{" SPEC_PTHREAD2 ": } " \ "%{mwindows:-lgdi32 -lcomdlg32} " \ + "%{fvtable-verify=preinit:-lvtv -lpsapi; \ + fvtable-verify=std:-lvtv -lpsapi} " \ "-ladvapi32 -lshell32 -luser32 -lkernel32" /* Weak symbols do not get resolved if using a Windows dll import lib. @@ -143,12 +145,18 @@ along with GCC; see the file COPYING3. #undef STARTFILE_SPEC #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \ %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \ - crtbegin.o%s" + crtbegin.o%s \ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_start.o%s; \ + fvtable-verify=std:vtv_start.o%s}" #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{!shared:%:if-exists(default-manifest.o%s)}\ + %{fvtable-verify=none:%s; \ + fvtable-verify=preinit:vtv_end.o%s; \ + fvtable-verify=std:vtv_end.o%s} \ crtend.o%s" /* Override startfile prefix defaults. */ Index: gcc/cp/vtable-class-hierarchy.c =================================================================== --- gcc/cp/vtable-class-hierarchy.c (Revision 214408) +++ gcc/cp/vtable-class-hierarchy.c (Arbeitskopie) @@ -1182,7 +1182,11 @@ vtv_generate_init_routine (void) TREE_STATIC (vtv_fndecl) = 1; TREE_USED (vtv_fndecl) = 1; DECL_PRESERVE_P (vtv_fndecl) = 1; +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif DECL_STATIC_CONSTRUCTOR (vtv_fndecl) = 0; gimplify_function_tree (vtv_fndecl); @@ -1190,7 +1194,11 @@ vtv_generate_init_routine (void) cgraph_process_new_functions (); +#if defined (TARGET_PECOFF) + if (flag_vtable_verify == VTV_PREINIT_PRIORITY && !TARGET_PECOFF) +#else if (flag_vtable_verify == VTV_PREINIT_PRIORITY) +#endif assemble_vtv_preinit_initializer (vtv_fndecl); } Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (Revision 214408) +++ gcc/varasm.c (Arbeitskopie) @@ -2164,6 +2164,33 @@ assemble_variable (tree decl, int top_le | SECTION_LINKONCE, DECL_NAME (decl)); in_section = sect; +#elif defined (TARGET_PECOFF) + /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here. + Therefore the following check is used. + In case a the target is PE or COFF a comdat group section + is created, e.g. .vtable_map_vars$foo. The linker places + everything in .vtable_map_vars at the end. + + A fix could be made in + gcc/config/i386/winnt.c: i386_pe_unique_section. */ + if (TARGET_PECOFF) + { + char *name; + + if (TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_NAME (decl)), NULL)); + else + name = ACONCAT ((sect->named.name, "$", + IDENTIFIER_POINTER (DECL_COMDAT_GROUP (DECL_NAME (decl))), + NULL)); + + targetm.asm_out.named_section (name, + sect->named.common.flags + | SECTION_LINKONCE, + DECL_NAME (decl)); + in_section = sect; + } #else switch_to_section (sect); #endif Index: libgcc/Makefile.in =================================================================== --- libgcc/Makefile.in (Revision 214408) +++ libgcc/Makefile.in (Arbeitskopie) @@ -986,6 +986,7 @@ 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 +endif ifeq ($(enable_vtable_verify),yes) # These are used in vtable verification; see comments in source files for @@ -1002,7 +1003,6 @@ vtv_start_preinit$(objext): $(srcdir)/vt 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),) # -x assembler-with-cpp is only needed on case-insensitive filesystem. Index: libgcc/config.host =================================================================== --- libgcc/config.host (Revision 214408) +++ libgcc/config.host (Arbeitskopie) @@ -615,6 +615,9 @@ i[4567]86-wrs-vxworks|i[4567]86-wrs-vxwo ;; i[34567]86-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -631,6 +634,9 @@ i[34567]86-*-cygwin*) ;; x86_64-*-cygwin*) extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h if test x$enable_sjlj_exceptions = xyes; then tmake_eh_file="i386/t-sjlj-eh" @@ -648,6 +654,9 @@ x86_64-*-cygwin*) ;; i[34567]86-*-mingw*) extra_parts="crtbegin.o crtend.o crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi case ${target_thread_file} in win32) tmake_file="$tmake_file i386/t-gthr-win32" @@ -694,6 +703,9 @@ x86_64-*-mingw*) fi tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" extra_parts="$extra_parts crtfastmath.o" + if test x$enable_vtable_verify = xyes; then + extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o" + fi ;; i[34567]86-*-interix[3-9]*) tmake_file="$tmake_file i386/t-interix i386/t-chkstk" Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (Revision 214408) +++ libstdc++-v3/acinclude.m4 (Arbeitskopie) @@ -2321,7 +2321,17 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_RESULT([$enable_vtable_verify]) if test $enable_vtable_verify = yes; then - VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + case ${target_os} in + cygwin*|mingw32*) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="yes" + ;; + *) + VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" + vtv_cygmin="no" + ;; + esac + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else Index: libstdc++-v3/libsupc++/Makefile.am =================================================================== --- libstdc++-v3/libsupc++/Makefile.am (Revision 214408) +++ libstdc++-v3/libsupc++/Makefile.am (Arbeitskopie) @@ -98,9 +98,11 @@ sources = \ vterminate.cc if ENABLE_VTABLE_VERIFY +if !VTV_CYGMIN vtv_sources = \ vtv_stubs.cc endif +endif libsupc___la_SOURCES = $(sources) $(c_sources) $(vtv_sources) libsupc__convenience_la_SOURCES = $(sources) $(c_sources) $(vtv_sources) Index: libstdc++-v3/libsupc++/vtv_stubs.cc =================================================================== --- libstdc++-v3/libsupc++/vtv_stubs.cc (Revision 214408) +++ libstdc++-v3/libsupc++/vtv_stubs.cc (Arbeitskopie) @@ -37,6 +37,39 @@ #include <cstddef> +/* weak symbols on Windows work differently than on Linux. To be able + to switch vtv on and off on Windows two dlls are built. One with + the sources from libvtv, the other from these stubs. Depending on + which dll is placed in the folder of the executable the functions + from libvtv or the stubs functions are used. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" +void +__VLTChangePermission(int); + +void +__VLTRegisterSet(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPair(void**, const void*, std::size_t, + const void*); + +const void* +__VLTVerifyVtablePointer(void**, const void*); + +void +__VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, + void**); + +void +__VLTRegisterPairDebug(void**, const void*, std::size_t, const void*, + const char*, const char*); + +const void* +__VLTVerifyVtablePointerDebug(void**, const void*, const char*, + const char*); +#else // Declare as weak for libsupc++, strong definitions are in libvtv. #if __GXX_WEAK__ extern "C" @@ -66,6 +99,7 @@ const void* __VLTVerifyVtablePointerDebug(void**, const void*, const char*, const char*) __attribute__((weak)); #endif +#endif // Stub definitions. extern "C" Index: libstdc++-v3/src/Makefile.am =================================================================== --- libstdc++-v3/src/Makefile.am (Revision 214408) +++ libstdc++-v3/src/Makefile.am (Arbeitskopie) @@ -25,7 +25,30 @@ include $(top_srcdir)/fragment.am SUBDIRS = c++98 c++11 # Cross compiler support. +if VTV_CYGMIN +toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la +else toolexeclib_LTLIBRARIES = libstdc++.la +endif + +if VTV_CYGMIN +vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ + +libvtv_la_SOURCES = vtv_stubs.cc +libvtv_la_LDFLAGS = $(lt_host_flags) + +libvtv_la_AM_CXXFLAGS = \ + $(glibcxx_compiler_pic_flag) \ + $(XTEMPLATE_FLAGS) \ + -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \ + $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) + +libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \ + $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@ +endif vpath % $(top_srcdir)/src/c++98 vpath % $(top_srcdir)/src/c++11 Index: libvtv/Makefile.am =================================================================== --- libvtv/Makefile.am (Revision 214408) +++ libvtv/Makefile.am (Arbeitskopie) @@ -38,7 +38,11 @@ AM_CXXFLAGS = $(XCFLAGS) AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS) AM_CXXFLAGS += -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end -toolexeclib_LTLIBRARIES = libvtv.la +if VTV_CYGMIN + toolexeclib_LTLIBRARIES = libvtv.la libvtv_stubs.la +else + toolexeclib_LTLIBRARIES = libvtv.la +endif vtv_headers = \ vtv_map.h \ @@ -55,6 +59,11 @@ vtv_sources = \ vtv_utils.cc \ vtv_end.c +vtv_stubs_sources = \ + vtv_start.c \ + vtv_stubs.cc \ + vtv_end.c + libvtv_includedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include # Link in vtv_start and vtv_end. @@ -67,8 +76,29 @@ vtv_end.c: rm -f $@ $(LN_S) $(toplevel_srcdir)/libgcc/vtv_end.c $@ +if VTV_CYGMIN + obstack.c: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libiberty/obstack.c $@ + + vtv_stubs.cc: + rm -f $@ + $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@ +endif + +if VTV_CYGMIN + libvtv_la_LIBADD = -lpsapi + libvtv_la_LDFLAGS = $(lt_host_flags) + libvtv_stubs_la_LDFLAGS = $(lt_host_flags) +endif + if ENABLE_VTABLE_VERIFY +if VTV_CYGMIN + libvtv_la_SOURCES = $(vtv_sources) obstack.c + libvtv_stubs_la_SOURCES = $(vtv_stubs_sources) +else libvtv_la_SOURCES = $(vtv_sources) +endif libvtv_include_HEADERS = $(vtv_headers) else libvtv_la_SOURCES = @@ -78,6 +108,8 @@ endif # Least ordering for dependencies mean linking w/o libstdc++ for as # long as the development of libvtv does not absolutely require it. CXXVTV=$(CC_FOR_TARGET) +CXXLD=$(CC_FOR_TARGET) + LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=compile $(CXXVTV) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) Index: libvtv/configure.ac =================================================================== --- libvtv/configure.ac (Revision 214408) +++ libvtv/configure.ac (Arbeitskopie) @@ -122,6 +122,7 @@ AC_CHECK_TOOL(RANLIB, ranlib, :) # Configure libtool AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL +ACX_LT_HOST_FLAGS AC_SUBST(enable_shared) AC_SUBST(enable_static) @@ -155,4 +156,15 @@ _EOF ]) fi +case "$target_os" in + cygwin*|mingw32*) + vtv_cygmin="yes" + ;; + *) + vtv_cygmin="no" + ;; +esac + +AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_OUTPUT Index: libvtv/configure.tgt =================================================================== --- libvtv/configure.tgt (Revision 214408) +++ libvtv/configure.tgt (Arbeitskopie) @@ -26,6 +26,12 @@ case "${target}" in x86_64-*-linux* | i?86-*-linux*) VTV_SUPPORTED=yes ;; + x86_64-*-cygwin* | i?86-*-cygwin*) + VTV_SUPPORTED=yes + ;; + x86_64-*-mingw* | i?86-*-mingw*) + VTV_SUPPORTED=yes + ;; powerpc*-*-linux*) ;; sparc*-*-linux*) Index: libvtv/vtv_fail.cc =================================================================== --- libvtv/vtv_fail.cc (Revision 214408) +++ libvtv/vtv_fail.cc (Arbeitskopie) @@ -46,7 +46,11 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> + +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <execinfo.h> +#endif + #include <unistd.h> #include "vtv_utils.h" @@ -102,8 +106,10 @@ log_error_message (const char *log_msg, { #define STACK_DEPTH 20 void *callers[STACK_DEPTH]; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); +#endif } } Index: libvtv/vtv_malloc.cc =================================================================== --- libvtv/vtv_malloc.cc (Revision 214408) +++ libvtv/vtv_malloc.cc (Arbeitskopie) @@ -33,7 +33,11 @@ #include <stdlib.h> #include <unistd.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <sys/mman.h> +#endif #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -62,6 +66,18 @@ static void *current_chunk VTV_PROTECTED static size_t current_chunk_size VTV_PROTECTED_VAR = 0; static int malloc_initialized VTV_PROTECTED_VAR = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) +//sysconf(_SC_PAGE_SIZE) port +long sysconf_SC_PAGE_SIZE() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + long pageSize = (long)si.dwPageSize; + return pageSize; + //return 4096; // standard usermode 32bit pagesize in bytes // FIXME +} +#endif + /* The function goes through and counts all the pages we have allocated so far. It returns the page count. */ @@ -162,8 +178,13 @@ obstack_chunk_alloc (size_t size) VTV_DEBUG_ASSERT ((size & (VTV_PAGE_SIZE - 1)) == 0); void *allocated; +#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 VTV_error (); VTV_DEBUG_ASSERT (((unsigned long) allocated & (VTV_PAGE_SIZE - 1)) == 0); @@ -190,7 +211,11 @@ __vtv_malloc_init (void) if (malloc_initialized) return; +#if defined (__CYGWIN__) || defined (__MINGW32__) + if (VTV_PAGE_SIZE != sysconf_SC_PAGE_SIZE()) +#else if (VTV_PAGE_SIZE != sysconf (_SC_PAGE_SIZE)) +#endif VTV_error (); obstack_chunk_size (&vtv_obstack) = VTV_PAGE_SIZE; Index: libvtv/vtv_malloc.h =================================================================== --- libvtv/vtv_malloc.h (Revision 214408) +++ libvtv/vtv_malloc.h (Arbeitskopie) @@ -95,4 +95,11 @@ extern void __vtv_malloc_stats (void); extern void __vtv_malloc_dump_stats (void); extern int __vtv_count_mmapped_pages (void); +#if defined (__CYGWIN__) || defined (__MINGW32__) +extern "C" int mprotect (void *addr, int len, int prot); + + #define PROT_READ 0x1 + #define PROT_WRITE 0x2 +#endif + #endif /* vtv_malloc.h */ Index: libvtv/vtv_map.h =================================================================== --- libvtv/vtv_map.h (Revision 214408) +++ libvtv/vtv_map.h (Arbeitskopie) @@ -26,7 +26,13 @@ #define _VTV_MAP_H 1 #include <string.h> + +#ifdef __MINGW32__ +#include <stdint.h> +#include "vtv_utils.h" +#else #include <vtv_utils.h> +#endif inline uint64_t load8bytes (const void *p) Index: libvtv/vtv_rts.cc =================================================================== --- libvtv/vtv_rts.cc (Revision 214408) +++ libvtv/vtv_rts.cc (Arbeitskopie) @@ -121,12 +121,20 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#include <winternl.h> +#include <psapi.h> +#else #include <execinfo.h> +#endif #include <unistd.h> +#if !defined (__CYGWIN__) && !defined (__MINGW32__) #include <sys/mman.h> -#include <errno.h> #include <link.h> +#endif +#include <errno.h> #include <fcntl.h> #include <limits.h> @@ -143,6 +151,13 @@ #include "vtv-change-permission.h" +#if defined (__CYGWIN__) || defined (__MINGW32__) +// porting: fix link error to libc +void __fortify_fail (const char * msg){ + OutputDebugString(msg); + abort(); +} +#else extern "C" { /* __fortify_fail is a function in glibc that calls __libc_message, @@ -159,6 +174,7 @@ extern "C" { extern void __fortify_fail (const char *) __attribute__((noreturn)); } /* extern "C" */ +#endif /* The following variables are used only for debugging and performance tuning purposes. Therefore they do not need to be "protected". @@ -313,10 +329,17 @@ typedef vtv_set_handle * vtv_set_handle_ struct sect_hdr_data { +#if defined (__CYGWIN__) || defined (__MINGW32__) + uintptr_t dlpi_addr; /* The header address in the INFO record, + passed in from dl_iterate_phdr. */ + uintptr_t mp_low; /* Start address of the .vtable_map_vars + section in memory. */ +#else ElfW (Addr) dlpi_addr; /* The header address in the INFO record, passed in from dl_iterate_phdr. */ ElfW (Addr) mp_low; /* Start address of the .vtable_map_vars section in memory. */ +#endif size_t mp_size; /* Size of the .vtable_map_vars section in memory. */ }; @@ -336,8 +359,13 @@ unsigned int num_cache_entries VTV_PROTE it returns the record for that entry; otherwise it returns NULL. */ +#if defined (__CYGWIN__) || defined (__MINGW32__) +struct sect_hdr_data * +search_cached_file_data (uintptr_t load_addr) +#else struct sect_hdr_data * search_cached_file_data (ElfW (Addr) load_addr) +#endif { unsigned int i; for (i = 0; i < num_cache_entries; ++i) @@ -401,6 +429,130 @@ log_memory_protection_data (char *messag __vtv_add_to_log (log_fd, "%s", message); } +#if defined (__CYGWIN__) || defined (__MINGW32__) +static void +read_section_offset_and_length (char *name, + uintptr_t addr, + const char *sect_name, + int mprotect_flags, + off_t *sect_offset, + WORD *sect_len) +{ + bool found = false; + struct sect_hdr_data *cached_data = NULL; + + /* Check to see if we already have the data for this file. */ + cached_data = search_cached_file_data (addr); + + if (cached_data) + { + *sect_offset = cached_data->mp_low; + *sect_len = cached_data->mp_size; + return; + } + + // check for DOS Header magic bytes + if (*(WORD *)addr == 0x5A4D) + { + int name_len = strlen (sect_name); + int fd = -1; + + /* Attempt to open the binary file on disk. */ + if (strlen (name) == 0) + { + return; + } + else + fd = open (name, O_RDONLY | O_BINARY); + + if (fd != -1) + { + /* Find the section header information in memory. */ + PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)addr; + PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((char *)addr + + pDosHeader->e_lfanew); + PIMAGE_FILE_HEADER pFileHeader = &pNtHeaders->FileHeader; + + DWORD PointerToStringTable = pFileHeader->PointerToSymbolTable + + (pFileHeader->NumberOfSymbols*0x12); + + PIMAGE_SECTION_HEADER sect_hdr = + (PIMAGE_SECTION_HEADER)((char *)&pNtHeaders->OptionalHeader + + pFileHeader->SizeOfOptionalHeader); + + /* Loop through all the section headers, looking for one whose + name is ".vtable_map_vars". */ + + for (int i = 0; i < pFileHeader->NumberOfSections && !found; ++i) + { + char header_name[64]; + + /* Check if we have to get the section name from the COFF string + table. */ + if (sect_hdr[i].Name[0] == '/') + { + if (atoi((const char*)sect_hdr[i].Name+1) == 0) + { + continue; + } + + off_t name_offset = PointerToStringTable + + atoi((const char*)sect_hdr[i].Name+1); + + size_t bytes_read = ReadFromOffset (fd, &header_name, 64, + name_offset); + + VTV_ASSERT (bytes_read > 0); + } + else + { + memcpy (&header_name, sect_hdr[i].Name, + sizeof (sect_hdr[i].Name)); + } + + if (memcmp (header_name, sect_name, name_len) == 0) + { + /* We found the section; get its load offset and + size. */ + *sect_offset = sect_hdr[i].VirtualAddress; + if (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE != 0) + *sect_len = sect_hdr[i].Misc.VirtualSize + VTV_PAGE_SIZE + - (sect_hdr[i].Misc.VirtualSize % VTV_PAGE_SIZE); + else + *sect_len = sect_hdr[i].Misc.VirtualSize; + found = true; + } + } + close (fd); + } + } + + if (*sect_offset != 0 && *sect_len != 0) + { + /* Calculate the page location in memory, making sure the + address is page-aligned. */ + uintptr_t start_addr = addr + *sect_offset; + *sect_offset = start_addr & ~(VTV_PAGE_SIZE - 1); + *sect_len = *sect_len - 1; + + /* Since we got this far, we must not have found these pages in + the cache, so add them to it. NOTE: We could get here either + while making everything read-only or while making everything + read-write. We will only update the cache if we get here on + a read-write (to make absolutely sure the cache is writable + -- also the read-write pass should come before the read-only + pass). */ + if ((mprotect_flags & PROT_WRITE) + && num_cache_entries < MAX_ENTRIES) + { + vtv_sect_info_cache[num_cache_entries].dlpi_addr = addr; + vtv_sect_info_cache[num_cache_entries].mp_low = *sect_offset; + vtv_sect_info_cache[num_cache_entries].mp_size = *sect_len; + num_cache_entries++; + } + } +} +#else static void read_section_offset_and_length (struct dl_phdr_info *info, const char *sect_name, @@ -547,7 +699,125 @@ read_section_offset_and_length (struct d } } } +#endif + +#if defined (__CYGWIN__) || defined (__MINGW32__) +/* This function is used to iterate over all loaded modules and searches + for a section called ".vtable_map_vars". The only interaction with + the binary file on disk of the module is to read section names in the + COFF string table. If the module contains a ".vtable_map_vars" section, + read section offset and size from the section header of the loaded module. + Call 'mprotect' on those pages, setting the protection either to + read-only or read-write, depending on what's in data. + The calls to change the protection occur in vtv_unprotect_vtable_vars + and vtv_protect_vtable_vars. */ + +static int +iterate_modules (void *data) +{ + int * mprotect_flags = (int *) data; + off_t map_sect_offset = 0; + WORD map_sect_len = 0; + char buffer[1024]; + const char *map_sect_name = VTV_PROTECTED_VARS_SECTION; + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + + hProcess = GetCurrentProcess (); + + if (NULL == hProcess) + return 0; + + if (EnumProcessModules (hProcess, hMods, sizeof (hMods), &cbNeeded)) + { + /* Iterate over all loaded modules. */ + for (unsigned int i = 0; i < (cbNeeded / sizeof (HMODULE)); i++) + { + char szModName[MAX_PATH]; + if (GetModuleFileNameExA (hProcess, hMods[i], szModName, + sizeof (szModName))) + { + map_sect_offset = 0; + map_sect_len = 0; + read_section_offset_and_length (szModName, + (uintptr_t) hMods[i], + map_sect_name, + *mprotect_flags, + &map_sect_offset, + &map_sect_len); + + if (debug_functions) + { + snprintf (buffer, sizeof(buffer), + " Looking at load module %s to change permissions to %s\n", + szModName, + (*mprotect_flags & PROT_WRITE) ? "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + } + + /* See if we actually found the section. */ + if (map_sect_offset && map_sect_len) + { + unsigned long long start; + int result; + + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + " (%s): Protecting %p to %p\n", + szModName, + (void *) map_sect_offset, + (void *) (map_sect_offset + map_sect_len)); + log_memory_protection_data (buffer); + } + + /* Change the protections on the pages for the section. */ + + start = get_cycle_count (); + result = mprotect ((void *) map_sect_offset, map_sect_len, + *mprotect_flags); + accumulate_cycle_count (&mprotect_cycles, start); + if (result == -1) + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "Failed called to mprotect for %s error: ", + (*mprotect_flags & PROT_WRITE) ? + "READ/WRITE" : "READ-ONLY"); + log_memory_protection_data (buffer); + perror(NULL); + } + VTV_error(); + } + else + { + if (debug_functions) + { + snprintf (buffer, sizeof (buffer), + "mprotect'ed range [%p, %p]\n", + (void *) map_sect_offset, + (char *) map_sect_offset + map_sect_len); + log_memory_protection_data (buffer); + } + } + increment_num_calls (&num_calls_to_mprotect); + /* num_pages_protected += (map_sect_len + VTV_PAGE_SIZE - 1) + / VTV_PAGE_SIZE; */ + num_pages_protected += (map_sect_len + 4096 - 1) / 4096; + continue; + } + } + } + } + + CloseHandle(hProcess); + + return 0; +} +#else /* This is the callback function used by dl_iterate_phdr (which is called from vtv_unprotect_vtable_vars and vtv_protect_vtable_vars). It attempts to find the binary file on disk for the INFO record @@ -652,6 +922,7 @@ dl_iterate_phdr_callback (struct dl_phdr return 0; } +#endif /* This function explicitly changes the protection (read-only or read-write) on the vtv_sect_info_cache, which is used for speeding up look ups in the @@ -678,7 +949,7 @@ change_protections_on_phdr_cache (int pr char * low_address = (char *) &(vtv_sect_info_cache); size_t cache_size = MAX_ENTRIES * sizeof (struct sect_hdr_data); - low_address = (char *) ((unsigned long) low_address & ~(VTV_PAGE_SIZE - 1)); + low_address = (char *) ((uintptr_t) low_address & ~(VTV_PAGE_SIZE - 1)); if (mprotect ((void *) low_address, cache_size, protection_flag) == -1) VTV_error (); @@ -695,7 +966,11 @@ vtv_unprotect_vtable_vars (void) mprotect_flags = PROT_READ | PROT_WRITE; change_protections_on_phdr_cache (mprotect_flags); +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif } /* Protect all the vtable map vars and other side data that is used @@ -708,7 +983,11 @@ vtv_protect_vtable_vars (void) int mprotect_flags; mprotect_flags = PROT_READ; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_callback, (void *) &mprotect_flags); +#endif change_protections_on_phdr_cache (mprotect_flags); } @@ -868,7 +1147,7 @@ const unsigned long SET_HANDLE_HANDLE_BI static inline bool is_set_handle_handle (void * ptr) { - return ((unsigned long) ptr & SET_HANDLE_HANDLE_BIT) + return ((uintptr_t) ptr & SET_HANDLE_HANDLE_BIT) == SET_HANDLE_HANDLE_BIT; } @@ -878,7 +1157,7 @@ is_set_handle_handle (void * ptr) static inline vtv_set_handle * ptr_from_set_handle_handle (void * ptr) { - return (vtv_set_handle *) ((unsigned long) ptr & ~SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle *) ((uintptr_t) ptr & ~SET_HANDLE_HANDLE_BIT); } /* Given a vtable map variable, PTR, this function sets the bit that @@ -888,7 +1167,7 @@ ptr_from_set_handle_handle (void * ptr) static inline vtv_set_handle_handle set_handle_handle (vtv_set_handle * ptr) { - return (vtv_set_handle_handle) ((unsigned long) ptr | SET_HANDLE_HANDLE_BIT); + return (vtv_set_handle_handle) ((uintptr_t) ptr | SET_HANDLE_HANDLE_BIT); } static inline void @@ -1362,6 +1641,7 @@ __VLTVerifyVtablePointer (void ** set_ha static int page_count_2 = 0; +#if !defined (__CYGWIN__) && !defined (__MINGW32__) static int dl_iterate_phdr_count_pages (struct dl_phdr_info *info, size_t unused __attribute__ ((__unused__)), @@ -1392,6 +1672,7 @@ dl_iterate_phdr_count_pages (struct dl_p return 0; } +#endif static void count_all_pages (void) @@ -1401,7 +1682,11 @@ count_all_pages (void) mprotect_flags = PROT_READ; page_count_2 = 0; +#if defined (__CYGWIN__) || defined (__MINGW32__) + iterate_modules ((void *) &mprotect_flags); +#else dl_iterate_phdr (dl_iterate_phdr_count_pages, (void *) &mprotect_flags); +#endif page_count_2 += __vtv_count_mmapped_pages (); } Index: libvtv/vtv_utils.cc =================================================================== --- libvtv/vtv_utils.cc (Revision 214408) +++ libvtv/vtv_utils.cc (Arbeitskopie) @@ -33,7 +33,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#if defined (__CYGWIN__) || defined (__MINGW32__) +#include <windows.h> +#else #include <execinfo.h> +#endif + #include <unistd.h> #include <errno.h> @@ -64,8 +69,12 @@ __vtv_open_log (const char *name) { char log_name[1024]; char log_dir[512]; +#if defined (__CYGWIN__) || defined (__MINGW32__) + pid_t process_id = GetCurrentProcessId (); +#else uid_t user_id = getuid (); pid_t process_id = getpid (); +#endif char *logs_prefix; bool logs_dir_specified = false; int fd = -1; @@ -74,14 +83,29 @@ __vtv_open_log (const char *name) if (logs_prefix && strlen (logs_prefix) > 0) { logs_dir_specified = true; +#ifdef __MINGW32__ + mkdir (logs_prefix); +#else mkdir (logs_prefix, S_IRWXU); +#endif + snprintf (log_dir, sizeof (log_dir), "%s/vtv_logs", logs_prefix); - mkdir (log_dir, S_IRWXU); +#ifdef __MINGW32__ + mkdir (log_dir); +#else + mkdir (log_dir, S_IRWXU); +#endif +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (log_name, sizeof (log_name), "%s_%d_%s", log_dir, + (unsigned) process_id, name); + fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); +#else snprintf (log_name, sizeof (log_name), "%s/%d_%d_%s", log_dir, (unsigned) user_id, (unsigned) process_id, name); fd = open (log_name, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, S_IRWXU); +#endif } else fd = dup (2); @@ -125,8 +149,12 @@ __vtv_add_to_log (int log_file, const ch va_list ap; va_start (ap, format); +#if defined (__CYGWIN__) || defined (__MINGW32__) + snprintf (output, sizeof (output), "VTV: PID=%ld ", GetCurrentProcessId ()); +#else snprintf (output, sizeof (output), "VTV: PID=%d PPID=%d ", getpid (), getppid ()); +#endif vtv_log_write (log_file, output); vsnprintf (output, sizeof (output), format, ap); vtv_log_write (log_file, output); @@ -151,6 +179,7 @@ __vtv_log_verification_failure (const ch __vtv_add_to_log (vtv_failures_log_fd, "%s", log_msg); +#if !defined (__CYGWIN__) && !defined (__MINGW32__) if (generate_backtrace) { #define STACK_DEPTH 20 @@ -158,4 +187,5 @@ __vtv_log_verification_failure (const ch int actual_depth = backtrace (callers, STACK_DEPTH); backtrace_symbols_fd (callers, actual_depth, vtv_failures_log_fd); } +#endif } ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-15 22:13 ` Patrick Wollgast @ 2015-01-28 14:04 ` Patrick Wollgast 2015-01-29 1:58 ` Caroline Tice 2015-02-02 19:56 ` Patrick Wollgast 0 siblings, 2 replies; 47+ messages in thread From: Patrick Wollgast @ 2015-01-28 14:04 UTC (permalink / raw) To: Ian Lance Taylor, Kai Tietz, cmtice@google.com >> Caroline Tice, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely Cc: gcc-patches, libstdc++ Ping. https://gcc.gnu.org/ml/gcc-patches/2015-01/msg01270.html On 15.01.2015 22:50, Patrick Wollgast wrote: > On 15.01.2015 17:01, Ian Lance Taylor wrote: >> On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast >> <patrick.wollgast@rub.de> wrote: >>> Is there something I'm still supposed to do, since I don't have write >>> access and this was the last part missing an "OK"? >> >> Somebody with write access will need to commit the patch for you. You >> should send a new clean patch including all the changes, along with >> updated ChangeLog entries. >> >> Ian >> > > For the clean patch I co'ed the latest version of the trunk again and > applied my patch. It applies correctly, except for two changes: > > patching file libgcc/Makefile.in > Hunk #1 succeeded at 995 with fuzz 2 (offset 9 lines). > Hunk #2 succeeded at 1020 (offset 17 lines). > >> # This is a version of crtbegin for -static links. >> crtbeginT$(objext): $(srcdir)/crtstuff.c >> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >> -DCRTSTUFFT_O >> endif >> >> ifeq ($(enable_vtable_verify),yes) >> # These are used in vtable verification; see comments in source files >> for >> # more details. > > I had to move the endif down, since something was added before > "ifeq ($(enable_vtable_verify),yes)" inside the if. > >> # This is a version of crtbegin for -static links. >> crtbeginT$(objext): $(srcdir)/crtstuff.c >> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >> -DCRTSTUFFT_O >> >> # crtoffloadbegin and crtoffloadend contain symbols, that mark the >> begin and >> # the end of tables with addresses, required for offloading. >> crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c >> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >> >> crtoffloadend$(objext): $(srcdir)/offloadstuff.c >> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END >> endif >> >> ifeq ($(enable_vtable_verify),yes) >> # These are used in vtable verification; see comments in source files >> for >> # more details. > > > patching file libgcc/config.host > Hunk #1 succeeded at 621 (offset 6 lines). > Hunk #2 succeeded at 640 (offset 6 lines). > Hunk #3 succeeded at 660 (offset 6 lines). > Hunk #4 succeeded at 1198 with fuzz 2 (offset 495 lines). > >> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} > i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" >> extra_parts="$extra_parts crtfastmath.o" > > The last two lines were changed to the following two lines. > >> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} > i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules > i386/t-crtfm i386/t-chkstk" >> extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" > > And therefore Hunk #4, which follows these lines, wasn't applied correctly. > > These two parts were corrected in vtv_cygmin_clean.patch. For > convenience I also added vtv_cygmin_unclean.patch, which is the patch > from my last mail. > > Regards, > Patrick > ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-28 14:04 ` Patrick Wollgast @ 2015-01-29 1:58 ` Caroline Tice 2015-01-29 18:16 ` H.J. Lu ` (2 more replies) 2015-02-02 19:56 ` Patrick Wollgast 1 sibling, 3 replies; 47+ messages in thread From: Caroline Tice @ 2015-01-29 1:58 UTC (permalink / raw) To: Patrick Wollgast Cc: Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ Since all the pieces of this patch have been approved, I will commit it later today (since Patrick does not have commit privileges). -- Caroline Tice cmtice@google.com On Wed, Jan 28, 2015 at 3:31 AM, Patrick Wollgast <patrick.wollgast@rub.de> wrote: > Ping. > > https://gcc.gnu.org/ml/gcc-patches/2015-01/msg01270.html > > On 15.01.2015 22:50, Patrick Wollgast wrote: >> On 15.01.2015 17:01, Ian Lance Taylor wrote: >>> On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast >>> <patrick.wollgast@rub.de> wrote: >>>> Is there something I'm still supposed to do, since I don't have write >>>> access and this was the last part missing an "OK"? >>> >>> Somebody with write access will need to commit the patch for you. You >>> should send a new clean patch including all the changes, along with >>> updated ChangeLog entries. >>> >>> Ian >>> >> >> For the clean patch I co'ed the latest version of the trunk again and >> applied my patch. It applies correctly, except for two changes: >> >> patching file libgcc/Makefile.in >> Hunk #1 succeeded at 995 with fuzz 2 (offset 9 lines). >> Hunk #2 succeeded at 1020 (offset 17 lines). >> >>> # This is a version of crtbegin for -static links. >>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>> -DCRTSTUFFT_O >>> endif >>> >>> ifeq ($(enable_vtable_verify),yes) >>> # These are used in vtable verification; see comments in source files >>> for >>> # more details. >> >> I had to move the endif down, since something was added before >> "ifeq ($(enable_vtable_verify),yes)" inside the if. >> >>> # This is a version of crtbegin for -static links. >>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>> -DCRTSTUFFT_O >>> >>> # crtoffloadbegin and crtoffloadend contain symbols, that mark the >>> begin and >>> # the end of tables with addresses, required for offloading. >>> crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c >>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>> >>> crtoffloadend$(objext): $(srcdir)/offloadstuff.c >>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END >>> endif >>> >>> ifeq ($(enable_vtable_verify),yes) >>> # These are used in vtable verification; see comments in source files >>> for >>> # more details. >> >> >> patching file libgcc/config.host >> Hunk #1 succeeded at 621 (offset 6 lines). >> Hunk #2 succeeded at 640 (offset 6 lines). >> Hunk #3 succeeded at 660 (offset 6 lines). >> Hunk #4 succeeded at 1198 with fuzz 2 (offset 495 lines). >> >>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >> i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" >>> extra_parts="$extra_parts crtfastmath.o" >> >> The last two lines were changed to the following two lines. >> >>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >> i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules >> i386/t-crtfm i386/t-chkstk" >>> extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" >> >> And therefore Hunk #4, which follows these lines, wasn't applied correctly. >> >> These two parts were corrected in vtv_cygmin_clean.patch. For >> convenience I also added vtv_cygmin_unclean.patch, which is the patch >> from my last mail. >> >> Regards, >> Patrick >> ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 1:58 ` Caroline Tice @ 2015-01-29 18:16 ` H.J. Lu 2015-01-29 18:22 ` H.J. Lu 2015-01-29 18:23 ` Caroline Tice 2015-01-29 18:16 ` Matthias Klose 2015-02-09 12:32 ` Thomas Schwinge 2 siblings, 2 replies; 47+ messages in thread From: H.J. Lu @ 2015-01-29 18:16 UTC (permalink / raw) To: Caroline Tice Cc: Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Wed, Jan 28, 2015 at 2:58 PM, Caroline Tice <cmtice@google.com> wrote: > Since all the pieces of this patch have been approved, I will commit > it later today (since Patrick does not have commit privileges). I got configure: error: conditional "VTV_CYGMIN" was never defined. Usually this means the macro was only invoked conditionally. Makefile:12580: recipe for target 'configure-stage1-target-libstdc++-v3' failed make[5]: *** [configure-stage1-target-libstdc++-v3] Error 1 > > -- Caroline Tice > cmtice@google.com > > > > On Wed, Jan 28, 2015 at 3:31 AM, Patrick Wollgast > <patrick.wollgast@rub.de> wrote: >> Ping. >> >> https://gcc.gnu.org/ml/gcc-patches/2015-01/msg01270.html >> >> On 15.01.2015 22:50, Patrick Wollgast wrote: >>> On 15.01.2015 17:01, Ian Lance Taylor wrote: >>>> On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast >>>> <patrick.wollgast@rub.de> wrote: >>>>> Is there something I'm still supposed to do, since I don't have write >>>>> access and this was the last part missing an "OK"? >>>> >>>> Somebody with write access will need to commit the patch for you. You >>>> should send a new clean patch including all the changes, along with >>>> updated ChangeLog entries. >>>> >>>> Ian >>>> >>> >>> For the clean patch I co'ed the latest version of the trunk again and >>> applied my patch. It applies correctly, except for two changes: >>> >>> patching file libgcc/Makefile.in >>> Hunk #1 succeeded at 995 with fuzz 2 (offset 9 lines). >>> Hunk #2 succeeded at 1020 (offset 17 lines). >>> >>>> # This is a version of crtbegin for -static links. >>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>> -DCRTSTUFFT_O >>>> endif >>>> >>>> ifeq ($(enable_vtable_verify),yes) >>>> # These are used in vtable verification; see comments in source files >>>> for >>>> # more details. >>> >>> I had to move the endif down, since something was added before >>> "ifeq ($(enable_vtable_verify),yes)" inside the if. >>> >>>> # This is a version of crtbegin for -static links. >>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>> -DCRTSTUFFT_O >>>> >>>> # crtoffloadbegin and crtoffloadend contain symbols, that mark the >>>> begin and >>>> # the end of tables with addresses, required for offloading. >>>> crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>> >>>> crtoffloadend$(objext): $(srcdir)/offloadstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END >>>> endif >>>> >>>> ifeq ($(enable_vtable_verify),yes) >>>> # These are used in vtable verification; see comments in source files >>>> for >>>> # more details. >>> >>> >>> patching file libgcc/config.host >>> Hunk #1 succeeded at 621 (offset 6 lines). >>> Hunk #2 succeeded at 640 (offset 6 lines). >>> Hunk #3 succeeded at 660 (offset 6 lines). >>> Hunk #4 succeeded at 1198 with fuzz 2 (offset 495 lines). >>> >>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>> i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" >>>> extra_parts="$extra_parts crtfastmath.o" >>> >>> The last two lines were changed to the following two lines. >>> >>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>> i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules >>> i386/t-crtfm i386/t-chkstk" >>>> extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" >>> >>> And therefore Hunk #4, which follows these lines, wasn't applied correctly. >>> >>> These two parts were corrected in vtv_cygmin_clean.patch. For >>> convenience I also added vtv_cygmin_unclean.patch, which is the patch >>> from my last mail. >>> >>> Regards, >>> Patrick >>> -- H.J. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:16 ` H.J. Lu @ 2015-01-29 18:22 ` H.J. Lu 2015-01-29 18:23 ` Caroline Tice 1 sibling, 0 replies; 47+ messages in thread From: H.J. Lu @ 2015-01-29 18:22 UTC (permalink / raw) To: Caroline Tice Cc: Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 9:48 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Wed, Jan 28, 2015 at 2:58 PM, Caroline Tice <cmtice@google.com> wrote: >> Since all the pieces of this patch have been approved, I will commit >> it later today (since Patrick does not have commit privileges). > > I got > > configure: error: conditional "VTV_CYGMIN" was never defined. > Usually this means the macro was only invoked conditionally. > Makefile:12580: recipe for target 'configure-stage1-target-libstdc++-v3' failed > make[5]: *** [configure-stage1-target-libstdc++-v3] Error 1 Somehow vtable verify was disabled on Linux: checking for vtable verify support... no -- H.J. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:16 ` H.J. Lu 2015-01-29 18:22 ` H.J. Lu @ 2015-01-29 18:23 ` Caroline Tice 1 sibling, 0 replies; 47+ messages in thread From: Caroline Tice @ 2015-01-29 18:23 UTC (permalink / raw) To: H.J. Lu Cc: Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ I (sadly) committed this patch in two pieces, one last night and one this morning. In the commit last night, I had forgotten to commit the Makefile.in and configure files that got generated by autoconf and automake. Did you sync your sources before or after the second commit? -- Caroline Tice On Thu, Jan 29, 2015 at 9:48 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Wed, Jan 28, 2015 at 2:58 PM, Caroline Tice <cmtice@google.com> wrote: >> Since all the pieces of this patch have been approved, I will commit >> it later today (since Patrick does not have commit privileges). > > I got > > configure: error: conditional "VTV_CYGMIN" was never defined. > Usually this means the macro was only invoked conditionally. > Makefile:12580: recipe for target 'configure-stage1-target-libstdc++-v3' failed > make[5]: *** [configure-stage1-target-libstdc++-v3] Error 1 > >> >> -- Caroline Tice >> cmtice@google.com >> >> >> >> On Wed, Jan 28, 2015 at 3:31 AM, Patrick Wollgast >> <patrick.wollgast@rub.de> wrote: >>> Ping. >>> >>> https://gcc.gnu.org/ml/gcc-patches/2015-01/msg01270.html >>> >>> On 15.01.2015 22:50, Patrick Wollgast wrote: >>>> On 15.01.2015 17:01, Ian Lance Taylor wrote: >>>>> On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast >>>>> <patrick.wollgast@rub.de> wrote: >>>>>> Is there something I'm still supposed to do, since I don't have write >>>>>> access and this was the last part missing an "OK"? >>>>> >>>>> Somebody with write access will need to commit the patch for you. You >>>>> should send a new clean patch including all the changes, along with >>>>> updated ChangeLog entries. >>>>> >>>>> Ian >>>>> >>>> >>>> For the clean patch I co'ed the latest version of the trunk again and >>>> applied my patch. It applies correctly, except for two changes: >>>> >>>> patching file libgcc/Makefile.in >>>> Hunk #1 succeeded at 995 with fuzz 2 (offset 9 lines). >>>> Hunk #2 succeeded at 1020 (offset 17 lines). >>>> >>>>> # This is a version of crtbegin for -static links. >>>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>>> -DCRTSTUFFT_O >>>>> endif >>>>> >>>>> ifeq ($(enable_vtable_verify),yes) >>>>> # These are used in vtable verification; see comments in source files >>>>> for >>>>> # more details. >>>> >>>> I had to move the endif down, since something was added before >>>> "ifeq ($(enable_vtable_verify),yes)" inside the if. >>>> >>>>> # This is a version of crtbegin for -static links. >>>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>>> -DCRTSTUFFT_O >>>>> >>>>> # crtoffloadbegin and crtoffloadend contain symbols, that mark the >>>>> begin and >>>>> # the end of tables with addresses, required for offloading. >>>>> crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>>> >>>>> crtoffloadend$(objext): $(srcdir)/offloadstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END >>>>> endif >>>>> >>>>> ifeq ($(enable_vtable_verify),yes) >>>>> # These are used in vtable verification; see comments in source files >>>>> for >>>>> # more details. >>>> >>>> >>>> patching file libgcc/config.host >>>> Hunk #1 succeeded at 621 (offset 6 lines). >>>> Hunk #2 succeeded at 640 (offset 6 lines). >>>> Hunk #3 succeeded at 660 (offset 6 lines). >>>> Hunk #4 succeeded at 1198 with fuzz 2 (offset 495 lines). >>>> >>>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>>> i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" >>>>> extra_parts="$extra_parts crtfastmath.o" >>>> >>>> The last two lines were changed to the following two lines. >>>> >>>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>>> i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules >>>> i386/t-crtfm i386/t-chkstk" >>>>> extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" >>>> >>>> And therefore Hunk #4, which follows these lines, wasn't applied correctly. >>>> >>>> These two parts were corrected in vtv_cygmin_clean.patch. For >>>> convenience I also added vtv_cygmin_unclean.patch, which is the patch >>>> from my last mail. >>>> >>>> Regards, >>>> Patrick >>>> > > > > -- > H.J. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 1:58 ` Caroline Tice 2015-01-29 18:16 ` H.J. Lu @ 2015-01-29 18:16 ` Matthias Klose 2015-01-29 18:26 ` Matthias Klose 2015-02-09 12:32 ` Thomas Schwinge 2 siblings, 1 reply; 47+ messages in thread From: Matthias Klose @ 2015-01-29 18:16 UTC (permalink / raw) To: Caroline Tice, Patrick Wollgast Cc: Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 3853 bytes --] r220254 broke bootstrap on the trunk: configure: error: conditional "VTV_CYGMIN" was never defined. Usually this means the macro was only invoked conditionally. Makefile:12932: recipe for target 'configure-stage1-target-libstdc++-v3' failed make[4]: *** [configure-stage1-target-libstdc++-v3] Error 1 trying to build with the attached patch. On 01/28/2015 11:58 PM, Caroline Tice wrote: > Since all the pieces of this patch have been approved, I will commit > it later today (since Patrick does not have commit privileges). > > > -- Caroline Tice > cmtice@google.com > > > > On Wed, Jan 28, 2015 at 3:31 AM, Patrick Wollgast > <patrick.wollgast@rub.de> wrote: >> Ping. >> >> https://gcc.gnu.org/ml/gcc-patches/2015-01/msg01270.html >> >> On 15.01.2015 22:50, Patrick Wollgast wrote: >>> On 15.01.2015 17:01, Ian Lance Taylor wrote: >>>> On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast >>>> <patrick.wollgast@rub.de> wrote: >>>>> Is there something I'm still supposed to do, since I don't have write >>>>> access and this was the last part missing an "OK"? >>>> >>>> Somebody with write access will need to commit the patch for you. You >>>> should send a new clean patch including all the changes, along with >>>> updated ChangeLog entries. >>>> >>>> Ian >>>> >>> >>> For the clean patch I co'ed the latest version of the trunk again and >>> applied my patch. It applies correctly, except for two changes: >>> >>> patching file libgcc/Makefile.in >>> Hunk #1 succeeded at 995 with fuzz 2 (offset 9 lines). >>> Hunk #2 succeeded at 1020 (offset 17 lines). >>> >>>> # This is a version of crtbegin for -static links. >>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>> -DCRTSTUFFT_O >>>> endif >>>> >>>> ifeq ($(enable_vtable_verify),yes) >>>> # These are used in vtable verification; see comments in source files >>>> for >>>> # more details. >>> >>> I had to move the endif down, since something was added before >>> "ifeq ($(enable_vtable_verify),yes)" inside the if. >>> >>>> # This is a version of crtbegin for -static links. >>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>> -DCRTSTUFFT_O >>>> >>>> # crtoffloadbegin and crtoffloadend contain symbols, that mark the >>>> begin and >>>> # the end of tables with addresses, required for offloading. >>>> crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>> >>>> crtoffloadend$(objext): $(srcdir)/offloadstuff.c >>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END >>>> endif >>>> >>>> ifeq ($(enable_vtable_verify),yes) >>>> # These are used in vtable verification; see comments in source files >>>> for >>>> # more details. >>> >>> >>> patching file libgcc/config.host >>> Hunk #1 succeeded at 621 (offset 6 lines). >>> Hunk #2 succeeded at 640 (offset 6 lines). >>> Hunk #3 succeeded at 660 (offset 6 lines). >>> Hunk #4 succeeded at 1198 with fuzz 2 (offset 495 lines). >>> >>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>> i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" >>>> extra_parts="$extra_parts crtfastmath.o" >>> >>> The last two lines were changed to the following two lines. >>> >>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>> i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules >>> i386/t-crtfm i386/t-chkstk" >>>> extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" >>> >>> And therefore Hunk #4, which follows these lines, wasn't applied correctly. >>> >>> These two parts were corrected in vtv_cygmin_clean.patch. For >>> convenience I also added vtv_cygmin_unclean.patch, which is the patch >>> from my last mail. >>> >>> Regards, >>> Patrick >>> [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: libstdc++-configure.diff --] [-- Type: text/x-patch; name="libstdc++-configure.diff", Size: 646 bytes --] --- a/src/libstdc++-v3/acinclude.m4 +++ b/src/libstdc++-v3/acinclude.m4 @@ -2320,6 +2320,8 @@ AC_MSG_CHECKING([for vtable verify support]) AC_MSG_RESULT([$enable_vtable_verify]) + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + if test $enable_vtable_verify = yes; then case ${target_os} in cygwin*|mingw32*) @@ -2331,7 +2333,6 @@ vtv_cygmin="no" ;; esac - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:16 ` Matthias Klose @ 2015-01-29 18:26 ` Matthias Klose 2015-01-29 18:28 ` Jonathan Wakely 2015-01-29 18:30 ` H.J. Lu 0 siblings, 2 replies; 47+ messages in thread From: Matthias Klose @ 2015-01-29 18:26 UTC (permalink / raw) To: Caroline Tice, Patrick Wollgast Cc: Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ that fixes the build failure. ok to commit? 2015-01-29 Matthias Klose <doko@ubuntu.com> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN unconditionally. * configure: Regenerate. On 01/29/2015 06:52 PM, Matthias Klose wrote: > r220254 broke bootstrap on the trunk: > > configure: error: conditional "VTV_CYGMIN" was never defined. > Usually this means the macro was only invoked conditionally. > Makefile:12932: recipe for target 'configure-stage1-target-libstdc++-v3' failed > make[4]: *** [configure-stage1-target-libstdc++-v3] Error 1 > > trying to build with the attached patch. > > On 01/28/2015 11:58 PM, Caroline Tice wrote: >> Since all the pieces of this patch have been approved, I will commit >> it later today (since Patrick does not have commit privileges). >> >> >> -- Caroline Tice >> cmtice@google.com >> >> >> >> On Wed, Jan 28, 2015 at 3:31 AM, Patrick Wollgast >> <patrick.wollgast@rub.de> wrote: >>> Ping. >>> >>> https://gcc.gnu.org/ml/gcc-patches/2015-01/msg01270.html >>> >>> On 15.01.2015 22:50, Patrick Wollgast wrote: >>>> On 15.01.2015 17:01, Ian Lance Taylor wrote: >>>>> On Wed, Jan 14, 2015 at 11:54 PM, Patrick Wollgast >>>>> <patrick.wollgast@rub.de> wrote: >>>>>> Is there something I'm still supposed to do, since I don't have write >>>>>> access and this was the last part missing an "OK"? >>>>> >>>>> Somebody with write access will need to commit the patch for you. You >>>>> should send a new clean patch including all the changes, along with >>>>> updated ChangeLog entries. >>>>> >>>>> Ian >>>>> >>>> >>>> For the clean patch I co'ed the latest version of the trunk again and >>>> applied my patch. It applies correctly, except for two changes: >>>> >>>> patching file libgcc/Makefile.in >>>> Hunk #1 succeeded at 995 with fuzz 2 (offset 9 lines). >>>> Hunk #2 succeeded at 1020 (offset 17 lines). >>>> >>>>> # This is a version of crtbegin for -static links. >>>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>>> -DCRTSTUFFT_O >>>>> endif >>>>> >>>>> ifeq ($(enable_vtable_verify),yes) >>>>> # These are used in vtable verification; see comments in source files >>>>> for >>>>> # more details. >>>> >>>> I had to move the endif down, since something was added before >>>> "ifeq ($(enable_vtable_verify),yes)" inside the if. >>>> >>>>> # This is a version of crtbegin for -static links. >>>>> crtbeginT$(objext): $(srcdir)/crtstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>>> -DCRTSTUFFT_O >>>>> >>>>> # crtoffloadbegin and crtoffloadend contain symbols, that mark the >>>>> begin and >>>>> # the end of tables with addresses, required for offloading. >>>>> crtoffloadbegin$(objext): $(srcdir)/offloadstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_BEGIN >>>>> >>>>> crtoffloadend$(objext): $(srcdir)/offloadstuff.c >>>>> $(crt_compile) $(CRTSTUFF_T_CFLAGS) -c $< -DCRT_END >>>>> endif >>>>> >>>>> ifeq ($(enable_vtable_verify),yes) >>>>> # These are used in vtable verification; see comments in source files >>>>> for >>>>> # more details. >>>> >>>> >>>> patching file libgcc/config.host >>>> Hunk #1 succeeded at 621 (offset 6 lines). >>>> Hunk #2 succeeded at 640 (offset 6 lines). >>>> Hunk #3 succeeded at 660 (offset 6 lines). >>>> Hunk #4 succeeded at 1198 with fuzz 2 (offset 495 lines). >>>> >>>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>>> i386/t-slibgcc-cygming i386/t-mingw32 t-dfprules i386/t-crtfm i386/t-chkstk" >>>>> extra_parts="$extra_parts crtfastmath.o" >>>> >>>> The last two lines were changed to the following two lines. >>>> >>>>> tmake_file="${tmake_file} ${tmake_eh_file} ${tmake_dlldir_file} >>>> i386/t-slibgcc-cygming i386/t-cygming i386/t-mingw32 t-dfprules >>>> i386/t-crtfm i386/t-chkstk" >>>>> extra_parts="$extra_parts crtbegin.o crtend.o crtfastmath.o" >>>> >>>> And therefore Hunk #4, which follows these lines, wasn't applied correctly. >>>> >>>> These two parts were corrected in vtv_cygmin_clean.patch. For >>>> convenience I also added vtv_cygmin_unclean.patch, which is the patch >>>> from my last mail. >>>> >>>> Regards, >>>> Patrick >>>> > ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:26 ` Matthias Klose @ 2015-01-29 18:28 ` Jonathan Wakely 2015-01-29 18:34 ` H.J. Lu 2015-01-29 18:30 ` H.J. Lu 1 sibling, 1 reply; 47+ messages in thread From: Jonathan Wakely @ 2015-01-29 18:28 UTC (permalink / raw) To: Matthias Klose Cc: Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, gcc-patches, libstdc++ On 29/01/15 19:05 +0100, Matthias Klose wrote: >that fixes the build failure. ok to commit? > >2015-01-29 Matthias Klose <doko@ubuntu.com> > > * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN > unconditionally. > * configure: Regenerate. OK, thanks. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:28 ` Jonathan Wakely @ 2015-01-29 18:34 ` H.J. Lu 2015-01-29 18:59 ` H.J. Lu 0 siblings, 1 reply; 47+ messages in thread From: H.J. Lu @ 2015-01-29 18:34 UTC (permalink / raw) To: Jonathan Wakely Cc: Matthias Klose, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:11 AM, Jonathan Wakely <jwakely@redhat.com> wrote: > On 29/01/15 19:05 +0100, Matthias Klose wrote: >> >> that fixes the build failure. ok to commit? >> >> 2015-01-29 Matthias Klose <doko@ubuntu.com> >> >> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN >> unconditionally. >> * configure: Regenerate. > > > OK, thanks. > It is NOT OK. -- H.J. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:34 ` H.J. Lu @ 2015-01-29 18:59 ` H.J. Lu 2015-01-29 19:27 ` H.J. Lu 0 siblings, 1 reply; 47+ messages in thread From: H.J. Lu @ 2015-01-29 18:59 UTC (permalink / raw) To: Jonathan Wakely Cc: Matthias Klose, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Thu, Jan 29, 2015 at 10:11 AM, Jonathan Wakely <jwakely@redhat.com> wrote: >> On 29/01/15 19:05 +0100, Matthias Klose wrote: >>> >>> that fixes the build failure. ok to commit? >>> >>> 2015-01-29 Matthias Klose <doko@ubuntu.com> >>> >>> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN >>> unconditionally. >>> * configure: Regenerate. >> >> >> OK, thanks. >> > > It is NOT OK. > This patch checks vtv_cygmin after it is defined. I will check it in as an obvious fix after testing. -- H.J. --- diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 59df22d..02ca3f3 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -2331,7 +2331,6 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], [ vtv_cygmin="no" ;; esac - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) VTV_PCH_CXXFLAGS="-fvtable-verify=std" VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath -Wl,${toplevel_builddir}/libvtv/.libs" else @@ -2340,6 +2339,8 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], [ VTV_CXXLINKFLAGS= fi + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_SUBST(VTV_CXXFLAGS) AC_SUBST(VTV_PCH_CXXFLAGS) AC_SUBST(VTV_CXXLINKFLAGS) ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:59 ` H.J. Lu @ 2015-01-29 19:27 ` H.J. Lu 0 siblings, 0 replies; 47+ messages in thread From: H.J. Lu @ 2015-01-29 19:27 UTC (permalink / raw) To: Jonathan Wakely Cc: Matthias Klose, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:16 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Thu, Jan 29, 2015 at 10:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Thu, Jan 29, 2015 at 10:11 AM, Jonathan Wakely <jwakely@redhat.com> wrote: >>> On 29/01/15 19:05 +0100, Matthias Klose wrote: >>>> >>>> that fixes the build failure. ok to commit? >>>> >>>> 2015-01-29 Matthias Klose <doko@ubuntu.com> >>>> >>>> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN >>>> unconditionally. >>>> * configure: Regenerate. >>> >>> >>> OK, thanks. >>> >> >> It is NOT OK. >> > > This patch checks vtv_cygmin after it is defined. I will > check it in as an obvious fix after testing. > > > -- > H.J. > --- > diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 > index 59df22d..02ca3f3 100644 > --- a/libstdc++-v3/acinclude.m4 > +++ b/libstdc++-v3/acinclude.m4 > @@ -2331,7 +2331,6 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], [ > vtv_cygmin="no" > ;; > esac > - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) > VTV_PCH_CXXFLAGS="-fvtable-verify=std" > VTV_CXXLINKFLAGS="-L${toplevel_builddir}/libvtv/.libs -Wl,--rpath > -Wl,${toplevel_builddir}/libvtv/.libs" > else > @@ -2340,6 +2339,8 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], [ > VTV_CXXLINKFLAGS= > fi > > + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) > + > AC_SUBST(VTV_CXXFLAGS) > AC_SUBST(VTV_PCH_CXXFLAGS) > AC_SUBST(VTV_CXXLINKFLAGS) This is what I checked in. -- H.J. --- Index: ChangeLog =================================================================== --- ChangeLog (revision 220257) +++ ChangeLog (working copy) @@ -1,3 +1,9 @@ +2015-01-29 H.J. Lu <hongjiu.lu@intel.com> + + * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN + after vtv_cygmin is set. + * configure: Regenerated. + 2015-01-29 Matthias Klose <doko@ubuntu.com> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN Index: acinclude.m4 =================================================================== --- acinclude.m4 (revision 220257) +++ acinclude.m4 (working copy) @@ -2320,8 +2320,6 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_CHECKING([for vtable verify support]) AC_MSG_RESULT([$enable_vtable_verify]) - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) - if test $enable_vtable_verify = yes; then case ${target_os} in cygwin*|mingw32*) @@ -2341,6 +2339,8 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], VTV_CXXLINKFLAGS= fi + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_SUBST(VTV_CXXFLAGS) AC_SUBST(VTV_PCH_CXXFLAGS) AC_SUBST(VTV_CXXLINKFLAGS) Index: configure =================================================================== --- configure (revision 220257) +++ configure (working copy) @@ -17459,15 +17459,6 @@ $as_echo_n "checking for vtable verify s { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_vtable_verify" >&5 $as_echo "$enable_vtable_verify" >&6; } - if test $vtv_cygmin = yes; then - VTV_CYGMIN_TRUE= - VTV_CYGMIN_FALSE='#' -else - VTV_CYGMIN_TRUE='#' - VTV_CYGMIN_FALSE= -fi - - if test $enable_vtable_verify = yes; then case ${target_os} in cygwin*|mingw32*) @@ -17487,6 +17478,15 @@ fi VTV_CXXLINKFLAGS= fi + if test $vtv_cygmin = yes; then + VTV_CYGMIN_TRUE= + VTV_CYGMIN_FALSE='#' +else + VTV_CYGMIN_TRUE='#' + VTV_CYGMIN_FALSE= +fi + + ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:26 ` Matthias Klose 2015-01-29 18:28 ` Jonathan Wakely @ 2015-01-29 18:30 ` H.J. Lu 2015-01-29 18:53 ` Matthias Klose 2015-01-29 19:28 ` Jakub Jelinek 1 sibling, 2 replies; 47+ messages in thread From: H.J. Lu @ 2015-01-29 18:30 UTC (permalink / raw) To: Matthias Klose Cc: Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:05 AM, Matthias Klose <doko@ubuntu.com> wrote: > that fixes the build failure. ok to commit? > > 2015-01-29 Matthias Klose <doko@ubuntu.com> > > * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN > unconditionally. > * configure: Regenerate. > This is wrong. You are checking vtv_cygmin before it is defined. -- H.J. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:30 ` H.J. Lu @ 2015-01-29 18:53 ` Matthias Klose 2015-01-29 19:39 ` Jakub Jelinek 2015-01-29 19:28 ` Jakub Jelinek 1 sibling, 1 reply; 47+ messages in thread From: Matthias Klose @ 2015-01-29 18:53 UTC (permalink / raw) To: H.J. Lu Cc: Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On 01/29/2015 07:12 PM, H.J. Lu wrote: > On Thu, Jan 29, 2015 at 10:05 AM, Matthias Klose <doko@ubuntu.com> wrote: >> that fixes the build failure. ok to commit? >> >> 2015-01-29 Matthias Klose <doko@ubuntu.com> >> >> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN >> unconditionally. >> * configure: Regenerate. >> > > This is wrong. You are checking vtv_cygmin before it is defined. my bad, somebody should obviously build both variants ... now testing this variant. Index: acinclude.m4 =================================================================== --- acinclude.m4 (revision 220257) +++ acinclude.m4 (working copy) @@ -2320,8 +2320,6 @@ AC_MSG_CHECKING([for vtable verify support]) AC_MSG_RESULT([$enable_vtable_verify]) - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) - if test $enable_vtable_verify = yes; then case ${target_os} in cygwin*|mingw32*) @@ -2341,6 +2339,8 @@ VTV_CXXLINKFLAGS= fi + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) + AC_SUBST(VTV_CXXFLAGS) AC_SUBST(VTV_PCH_CXXFLAGS) AC_SUBST(VTV_CXXLINKFLAGS) ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:53 ` Matthias Klose @ 2015-01-29 19:39 ` Jakub Jelinek 2015-01-29 19:55 ` H.J. Lu 0 siblings, 1 reply; 47+ messages in thread From: Jakub Jelinek @ 2015-01-29 19:39 UTC (permalink / raw) To: Matthias Klose Cc: H.J. Lu, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 07:16:17PM +0100, Matthias Klose wrote: > On 01/29/2015 07:12 PM, H.J. Lu wrote: > > On Thu, Jan 29, 2015 at 10:05 AM, Matthias Klose <doko@ubuntu.com> wrote: > >> that fixes the build failure. ok to commit? > >> > >> 2015-01-29 Matthias Klose <doko@ubuntu.com> > >> > >> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN > >> unconditionally. > >> * configure: Regenerate. > >> > > > > This is wrong. You are checking vtv_cygmin before it is defined. > > my bad, somebody should obviously build both variants ... now testing this variant. Even with this patch vtv_cygmin is uninitialized. It will be likely empty string, unless somebody has vtv_cygmin in the environment, but it is better to initialize it, see the patch I've posted. > --- acinclude.m4 (revision 220257) > +++ acinclude.m4 (working copy) > @@ -2320,8 +2320,6 @@ > AC_MSG_CHECKING([for vtable verify support]) > AC_MSG_RESULT([$enable_vtable_verify]) > > - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) > - > if test $enable_vtable_verify = yes; then > case ${target_os} in > cygwin*|mingw32*) > @@ -2341,6 +2339,8 @@ > VTV_CXXLINKFLAGS= > fi > > + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) > + > AC_SUBST(VTV_CXXFLAGS) > AC_SUBST(VTV_PCH_CXXFLAGS) > AC_SUBST(VTV_CXXLINKFLAGS) > Jakub ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 19:39 ` Jakub Jelinek @ 2015-01-29 19:55 ` H.J. Lu 2015-01-29 20:01 ` Jakub Jelinek 0 siblings, 1 reply; 47+ messages in thread From: H.J. Lu @ 2015-01-29 19:55 UTC (permalink / raw) To: Jakub Jelinek Cc: Matthias Klose, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:26 AM, Jakub Jelinek <jakub@redhat.com> wrote: > On Thu, Jan 29, 2015 at 07:16:17PM +0100, Matthias Klose wrote: >> On 01/29/2015 07:12 PM, H.J. Lu wrote: >> > On Thu, Jan 29, 2015 at 10:05 AM, Matthias Klose <doko@ubuntu.com> wrote: >> >> that fixes the build failure. ok to commit? >> >> >> >> 2015-01-29 Matthias Klose <doko@ubuntu.com> >> >> >> >> * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN >> >> unconditionally. >> >> * configure: Regenerate. >> >> >> > >> > This is wrong. You are checking vtv_cygmin before it is defined. >> >> my bad, somebody should obviously build both variants ... now testing this variant. > > Even with this patch vtv_cygmin is uninitialized. It will be likely empty > string, unless somebody has vtv_cygmin in the environment, but it is better > to initialize it, see the patch I've posted. > >> --- acinclude.m4 (revision 220257) >> +++ acinclude.m4 (working copy) >> @@ -2320,8 +2320,6 @@ >> AC_MSG_CHECKING([for vtable verify support]) >> AC_MSG_RESULT([$enable_vtable_verify]) >> >> - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) >> - >> if test $enable_vtable_verify = yes; then >> case ${target_os} in >> cygwin*|mingw32*) >> @@ -2341,6 +2339,8 @@ >> VTV_CXXLINKFLAGS= >> fi >> >> + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) >> + > Or we can just do AM_CONDITIONAL(VTV_CYGMIN, test x$vtv_cygmin = xyes) -- H.J. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 19:55 ` H.J. Lu @ 2015-01-29 20:01 ` Jakub Jelinek 2015-01-29 20:08 ` H.J. Lu 0 siblings, 1 reply; 47+ messages in thread From: Jakub Jelinek @ 2015-01-29 20:01 UTC (permalink / raw) To: H.J. Lu Cc: Matthias Klose, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:28:17AM -0800, H.J. Lu wrote: > >> --- acinclude.m4 (revision 220257) > >> +++ acinclude.m4 (working copy) > >> @@ -2320,8 +2320,6 @@ > >> AC_MSG_CHECKING([for vtable verify support]) > >> AC_MSG_RESULT([$enable_vtable_verify]) > >> > >> - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) > >> - > >> if test $enable_vtable_verify = yes; then > >> case ${target_os} in > >> cygwin*|mingw32*) > >> @@ -2341,6 +2339,8 @@ > >> VTV_CXXLINKFLAGS= > >> fi > >> > >> + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) > >> + > > > > Or we can just do > > AM_CONDITIONAL(VTV_CYGMIN, test x$vtv_cygmin = xyes) Or that, but that is not what you've checked in. Some shells will be upset about test $vtv_cygmin = yes when $vtv_cygmin expands to empty string. Jakub ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 20:01 ` Jakub Jelinek @ 2015-01-29 20:08 ` H.J. Lu 0 siblings, 0 replies; 47+ messages in thread From: H.J. Lu @ 2015-01-29 20:08 UTC (permalink / raw) To: Jakub Jelinek Cc: Matthias Klose, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:30 AM, Jakub Jelinek <jakub@redhat.com> wrote: > On Thu, Jan 29, 2015 at 10:28:17AM -0800, H.J. Lu wrote: >> >> --- acinclude.m4 (revision 220257) >> >> +++ acinclude.m4 (working copy) >> >> @@ -2320,8 +2320,6 @@ >> >> AC_MSG_CHECKING([for vtable verify support]) >> >> AC_MSG_RESULT([$enable_vtable_verify]) >> >> >> >> - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) >> >> - >> >> if test $enable_vtable_verify = yes; then >> >> case ${target_os} in >> >> cygwin*|mingw32*) >> >> @@ -2341,6 +2339,8 @@ >> >> VTV_CXXLINKFLAGS= >> >> fi >> >> >> >> + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) >> >> + >> > >> >> Or we can just do >> >> AM_CONDITIONAL(VTV_CYGMIN, test x$vtv_cygmin = xyes) > > Or that, but that is not what you've checked in. > Some shells will be upset about test $vtv_cygmin = yes when > $vtv_cygmin expands to empty string. > Yes, I got checking for vtable verify support... no /export/gnu/import/git/sources/gcc/libstdc++-v3/configure: line 17481: test: =: unary operator expected At least it doesn't stop bootstrap. Either fix is fine with me. -- H.J. ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 18:30 ` H.J. Lu 2015-01-29 18:53 ` Matthias Klose @ 2015-01-29 19:28 ` Jakub Jelinek 1 sibling, 0 replies; 47+ messages in thread From: Jakub Jelinek @ 2015-01-29 19:28 UTC (permalink / raw) To: H.J. Lu Cc: Matthias Klose, Caroline Tice, Patrick Wollgast, Kai Tietz, Benjamin De Kosnik, jwakely@redhat.com >> Jonathan Wakely, gcc-patches, libstdc++ On Thu, Jan 29, 2015 at 10:12:38AM -0800, H.J. Lu wrote: > On Thu, Jan 29, 2015 at 10:05 AM, Matthias Klose <doko@ubuntu.com> wrote: > > that fixes the build failure. ok to commit? > > > > 2015-01-29 Matthias Klose <doko@ubuntu.com> > > > > * acinclude.m4 (GLIBCXX_ENABLE_VTABLE_VERIFY): Define VTV_CYGMIN > > unconditionally. > > * configure: Regenerate. > > > > This is wrong. You are checking vtv_cygmin before it is defined. Yeah, I'd say we need something like: 2015-01-29 Jakub Jelinek <jakub@redhat.com> * acinclude.m4 (VTV_CYGMIN): Move AM_CONDITIONAL after vtv_cygmin definition. Set vtv_cygmin to no even if $enable_vtable_verify is not yet. * configure: Regenerated. --- libstdc++-v3/acinclude.m4 2015-01-29 19:19:19.305782787 +0100 +++ libstdc++-v3/acinclude.m4 2015-01-29 19:21:13.244854829 +0100 @@ -2320,17 +2320,15 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_MSG_CHECKING([for vtable verify support]) AC_MSG_RESULT([$enable_vtable_verify]) - AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) - + vtv_cygmin=no if test $enable_vtable_verify = yes; then case ${target_os} in cygwin*|mingw32*) VTV_CXXFLAGS="-fvtable-verify=std -Wl,-lvtv,-u_vtable_map_vars_start,-u_vtable_map_vars_end" - vtv_cygmin="yes" + vtv_cygmin=yes ;; *) VTV_CXXFLAGS="-fvtable-verify=std -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end" - vtv_cygmin="no" ;; esac VTV_PCH_CXXFLAGS="-fvtable-verify=std" @@ -2344,6 +2342,7 @@ AC_DEFUN([GLIBCXX_ENABLE_VTABLE_VERIFY], AC_SUBST(VTV_CXXFLAGS) AC_SUBST(VTV_PCH_CXXFLAGS) AC_SUBST(VTV_CXXLINKFLAGS) + AM_CONDITIONAL(VTV_CYGMIN, test $vtv_cygmin = yes) GLIBCXX_CONDITIONAL(ENABLE_VTABLE_VERIFY, test $enable_vtable_verify = yes) ]) Jakub ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-29 1:58 ` Caroline Tice 2015-01-29 18:16 ` H.J. Lu 2015-01-29 18:16 ` Matthias Klose @ 2015-02-09 12:32 ` Thomas Schwinge 2 siblings, 0 replies; 47+ messages in thread From: Thomas Schwinge @ 2015-02-09 12:32 UTC (permalink / raw) To: Caroline Tice, Patrick Wollgast Cc: Kai Tietz, Benjamin De Kosnik, jwakely, gcc-patches, libstdc++ [-- Attachment #1: Type: text/plain, Size: 5379 bytes --] Hi! On Wed, 28 Jan 2015 14:58:04 -0800, Caroline Tice <cmtice@google.com> wrote: > Since all the pieces of this patch have been approved, I will commit > it later today (since Patrick does not have commit privileges). (This happened in r220232 and r220254.) I'm seeing: [...] checking dynamic linker characteristics... (cached) GNU/Linux ld.so checking how to hardcode library paths into programs... immediate /scratch/tschwing/nvidiak20-2/gcc/trunk-big/source-gcc/libvtv/configure: line 15491: ACX_LT_HOST_FLAGS: command not found configure: updating cache ./config.cache configure: creating ./config.status [...] As obvious, I committed the following in r220535: commit a9983ab2160733f677d3d0e78b60d1a1659addd0 Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Mon Feb 9 11:41:22 2015 +0000 libvtv: autoreconf. libvtv/ * Makefile.in: Regenerate. * aclocal.m4: Likewise. * configure: Likewise. * testsuite/Makefile.in: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220535 138bc75d-0d04-0410-961f-82ee72b054a4 --- libvtv/ChangeLog | 7 +++++++ libvtv/Makefile.in | 2 ++ libvtv/aclocal.m4 | 1 + libvtv/configure | 28 +++++++++++++++++++++++++--- libvtv/testsuite/Makefile.in | 2 ++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git libvtv/ChangeLog libvtv/ChangeLog index 7dd9f09..dd8d2a4 100644 --- libvtv/ChangeLog +++ libvtv/ChangeLog @@ -1,3 +1,10 @@ +2015-02-09 Thomas Schwinge <thomas@codesourcery.com> + + * Makefile.in: Regenerate. + * aclocal.m4: Likewise. + * configure: Likewise. + * testsuite/Makefile.in: Likewise. + 2015-01-29 Caroline Tice <cmtice@google.com> Committing VTV Cywin/Ming patch for Patrick Wollgast diff --git libvtv/Makefile.in libvtv/Makefile.in index 098ee88..bc472fd 100644 --- libvtv/Makefile.in +++ libvtv/Makefile.in @@ -46,6 +46,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ $(top_srcdir)/../config/depstand.m4 \ $(top_srcdir)/../config/lead-dot.m4 \ $(top_srcdir)/../config/libstdc++-raw-cxx.m4 \ + $(top_srcdir)/../config/lthostflags.m4 \ $(top_srcdir)/../config/multi.m4 \ $(top_srcdir)/../config/override.m4 \ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ @@ -257,6 +258,7 @@ libvtv_builddir = @libvtv_builddir@ libvtv_srcdir = @libvtv_srcdir@ localedir = @localedir@ localstatedir = @localstatedir@ +lt_host_flags = @lt_host_flags@ mandir = @mandir@ mkdir_p = @mkdir_p@ multi_basedir = @multi_basedir@ diff --git libvtv/aclocal.m4 libvtv/aclocal.m4 index 5478f2b..cb5eb67 100644 --- libvtv/aclocal.m4 +++ libvtv/aclocal.m4 @@ -1007,6 +1007,7 @@ m4_include([../config/acx.m4]) m4_include([../config/depstand.m4]) m4_include([../config/lead-dot.m4]) m4_include([../config/libstdc++-raw-cxx.m4]) +m4_include([../config/lthostflags.m4]) m4_include([../config/multi.m4]) m4_include([../config/override.m4]) m4_include([../ltoptions.m4]) diff --git libvtv/configure libvtv/configure index 64b6f75..a7211b8 100755 --- libvtv/configure +++ libvtv/configure @@ -608,6 +608,7 @@ XCFLAGS libtool_VERSION enable_static enable_shared +lt_host_flags CXXCPP OTOOL64 OTOOL @@ -12129,7 +12130,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12132 "configure" +#line 12133 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12235,7 +12236,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12238 "configure" +#line 12239 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -15488,7 +15489,28 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu # Only expand once: -ACX_LT_HOST_FLAGS + + + +case $host in + *-cygwin* | *-mingw*) + # 'host' will be top-level target in the case of a target lib, + # we must compare to with_cross_host to decide if this is a native + # or cross-compiler and select where to install dlls appropriately. + if test -n "$with_cross_host" && + test x"$with_cross_host" != x"no"; then + lt_host_flags='-no-undefined -bindir "$(toolexeclibdir)"'; + else + lt_host_flags='-no-undefined -bindir "$(bindir)"'; + fi + ;; + *) + lt_host_flags= + ;; +esac + + + diff --git libvtv/testsuite/Makefile.in libvtv/testsuite/Makefile.in index ba28e74..c8fd48c 100644 --- libvtv/testsuite/Makefile.in +++ libvtv/testsuite/Makefile.in @@ -41,6 +41,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ $(top_srcdir)/../config/depstand.m4 \ $(top_srcdir)/../config/lead-dot.m4 \ $(top_srcdir)/../config/libstdc++-raw-cxx.m4 \ + $(top_srcdir)/../config/lthostflags.m4 \ $(top_srcdir)/../config/multi.m4 \ $(top_srcdir)/../config/override.m4 \ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \ @@ -167,6 +168,7 @@ libvtv_builddir = @libvtv_builddir@ libvtv_srcdir = @libvtv_srcdir@ localedir = @localedir@ localstatedir = @localstatedir@ +lt_host_flags = @lt_host_flags@ mandir = @mandir@ mkdir_p = @mkdir_p@ multi_basedir = @multi_basedir@ Grüße, Thomas [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 472 bytes --] ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [Ping] Port of VTV for Cygwin and MinGW 2015-01-28 14:04 ` Patrick Wollgast 2015-01-29 1:58 ` Caroline Tice @ 2015-02-02 19:56 ` Patrick Wollgast 1 sibling, 0 replies; 47+ messages in thread From: Patrick Wollgast @ 2015-02-02 19:56 UTC (permalink / raw) To: Kai Tietz, cmtice@google.com >> Caroline Tice; +Cc: gcc-patches Hi, after the missed bug at Linux with no VTV I checked everything again on the trunk. I saw that I erroneously wrote in the changelog for libvtv/aclocal.m4 regenerate and deleted the change from the patch. The only change I made there in my working directory was the following. Index: libvtv/aclocal.m4 =================================================================== --- libvtv/aclocal.m4 (Revision 220306) +++ libvtv/aclocal.m4 (Arbeitskopie) @@ -1006,6 +1006,7 @@ AC_SUBST([am__untar]) m4_include([../config/acx.m4]) m4_include([../config/depstand.m4]) m4_include([../config/lead-dot.m4]) +m4_include([../config/lthostflags.m4]) m4_include([../config/libstdc++-raw-cxx.m4]) m4_include([../config/multi.m4]) m4_include([../config/override.m4]) And then autoconf/automake again. Something I missed during my last test, since Cygwin with gcc 4.9 and the patch bootstrapped fine, is the following. One of the last changes to the patch was to remove the implementation of mprotect in libvtv/ (copied from the MinGW port from libgcc2.c), because libgcc2.c implements it for MinGW, and cygwin1.dll implements it for Cygwin. However, PAGE_SIZE/PAGESIZE returns 0x10000 on Cygwin on a 64bit PC/VM (don't have a 32bit PC/VM but I assume that the value would be 0x1000 there). On Linux 64bit it returns 0x1000 and on Windows 64bit with SYSTEM_INFO/dwPageSize also returns 0x1000. This causes mprotect of Cygwin to fail for libvtv, since the passed address is checked for alignment with PAGE_SIZE/PAGESIZE. The solutions I come up with are: - Set VTV_PAGE_SIZE to 0x10000 on Cygwin with 64bit PCs/VMs. But this would set more than the desired section to be read/write. Practically the whole dll would be writable for the .vtable_map_vars section to be writable. Therefore I don't recommend this solution. The changes would be in include/vtv-change-permission.h, and various other files where sizes have to be changed. - Add the mprotect implementation from libgcc2.c again for Cygwin in libvtv/. In libgcc2.c it isn't build for Cygwin. The changes would just be in libvtv/. I'd prefer this solution. Patrick ^ permalink raw reply [flat|nested] 47+ messages in thread
end of thread, other threads:[~2015-02-09 12:32 UTC | newest] Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-08-28 11:04 Port of VTV for Cygwin and MinGW Patrick Wollgast 2014-09-11 4:12 ` [Ping] " Patrick Wollgast [not found] ` <CABtf2+RU7frwOXOX2FF8Tmfc6ssrpfFVj1Vuue4cZt19FpSWtQ@mail.gmail.com> 2014-09-12 22:44 ` Caroline Tice 2014-09-18 22:24 ` Patrick Wollgast 2014-09-23 6:16 ` Caroline Tice 2014-09-23 10:22 ` Jonathan Wakely 2014-09-24 22:25 ` Patrick Wollgast 2014-09-27 10:50 ` Kai Tietz 2014-10-09 13:56 ` Patrick Wollgast 2014-10-09 14:47 ` Kai Tietz 2014-10-16 10:23 ` Patrick Wollgast 2014-10-30 14:51 ` Patrick Wollgast 2014-11-12 16:23 ` Patrick Wollgast 2014-11-12 17:05 ` Kai Tietz 2014-11-12 17:47 ` Patrick Wollgast 2014-11-12 18:45 ` Kai Tietz 2014-11-27 9:59 ` Patrick Wollgast 2014-12-10 16:37 ` Patrick Wollgast 2015-01-04 20:10 ` Patrick Wollgast 2015-01-08 20:34 ` Patrick Wollgast 2015-01-12 18:32 ` Caroline Tice 2015-01-14 19:28 ` Ian Lance Taylor 2015-01-14 21:23 ` Patrick Wollgast 2015-01-14 23:56 ` Ian Lance Taylor 2015-01-15 8:34 ` Patrick Wollgast 2015-01-15 16:14 ` Ian Lance Taylor 2015-01-15 22:13 ` Patrick Wollgast 2015-01-28 14:04 ` Patrick Wollgast 2015-01-29 1:58 ` Caroline Tice 2015-01-29 18:16 ` H.J. Lu 2015-01-29 18:22 ` H.J. Lu 2015-01-29 18:23 ` Caroline Tice 2015-01-29 18:16 ` Matthias Klose 2015-01-29 18:26 ` Matthias Klose 2015-01-29 18:28 ` Jonathan Wakely 2015-01-29 18:34 ` H.J. Lu 2015-01-29 18:59 ` H.J. Lu 2015-01-29 19:27 ` H.J. Lu 2015-01-29 18:30 ` H.J. Lu 2015-01-29 18:53 ` Matthias Klose 2015-01-29 19:39 ` Jakub Jelinek 2015-01-29 19:55 ` H.J. Lu 2015-01-29 20:01 ` Jakub Jelinek 2015-01-29 20:08 ` H.J. Lu 2015-01-29 19:28 ` Jakub Jelinek 2015-02-09 12:32 ` Thomas Schwinge 2015-02-02 19:56 ` Patrick Wollgast
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).