Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc: specify LDFLAGS_FOR_TARGET and --with-boot-ldflags, disable dynamicbase for compiler #6907

Merged

Conversation

jeremyd2019
Copy link
Member

@jeremyd2019 jeremyd2019 commented Sep 1, 2020

Related to #6899 (sharing the first commit with it), but with a less-hacky solution to disabling dynamicbase for the compiler itself while leaving it enabled for the runtime libraries. Note that this depends on the binutils from #6906 for the --disable-dynamicbase flag (draft until that's live so CI can build successfully).

Results can be divided into 3 sets:

Binaries that respect LDFLAGS or --with-boot-ldflags (LDFLAGS applies to stage1, --with-boot-ldflags to later stages):

./mingw-w64-i686-gcc/mingw32/bin/c++.exe
./mingw-w64-i686-gcc/mingw32/bin/cc.exe
./mingw-w64-i686-gcc/mingw32/bin/cpp.exe
./mingw-w64-i686-gcc/mingw32/bin/g++.exe
./mingw-w64-i686-gcc/mingw32/bin/gcc-ar.exe
./mingw-w64-i686-gcc/mingw32/bin/gcc-nm.exe
./mingw-w64-i686-gcc/mingw32/bin/gcc-ranlib.exe
./mingw-w64-i686-gcc/mingw32/bin/gcc.exe
./mingw-w64-i686-gcc/mingw32/bin/gcov-tool.exe
./mingw-w64-i686-gcc/mingw32/bin/gcov.exe
./mingw-w64-i686-gcc/mingw32/bin/i686-w64-mingw32-c++.exe
./mingw-w64-i686-gcc/mingw32/bin/i686-w64-mingw32-g++.exe
./mingw-w64-i686-gcc/mingw32/bin/i686-w64-mingw32-gcc-10.2.0.exe
./mingw-w64-i686-gcc/mingw32/bin/i686-w64-mingw32-gcc-ar.exe
./mingw-w64-i686-gcc/mingw32/bin/i686-w64-mingw32-gcc-nm.exe
./mingw-w64-i686-gcc/mingw32/bin/i686-w64-mingw32-gcc-ranlib.exe
./mingw-w64-i686-gcc/mingw32/bin/i686-w64-mingw32-gcc.exe
./mingw-w64-i686-gcc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/cc1.exe
./mingw-w64-i686-gcc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/cc1plus.exe
./mingw-w64-i686-gcc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/collect2.exe
./mingw-w64-i686-gcc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/lto-wrapper.exe
./mingw-w64-i686-gcc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/lto1.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatbind.exe
./mingw-w64-i686-gcc-ada/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/gnat1.exe
./mingw-w64-i686-gcc-fortran/mingw32/bin/gfortran.exe
./mingw-w64-i686-gcc-fortran/mingw32/bin/i686-w64-mingw32-gfortran.exe
./mingw-w64-i686-gcc-fortran/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/f951.exe
./mingw-w64-i686-gcc-objc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/cc1obj.exe
./mingw-w64-i686-gcc-objc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/cc1objplus.exe

Binaries that respect LDFLAGS_FOR_TARGET:

./mingw-w64-i686-gcc/mingw32/lib/bfd-plugins/liblto_plugin-0.dll (with 1c41e8e)
./mingw-w64-i686-gcc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/install-tools/fixincl.exe
./mingw-w64-i686-gcc/mingw32/lib/gcc/i686-w64-mingw32/10.2.0/liblto_plugin-0.dll (with 1c41e8e)
./mingw-w64-i686-gcc-ada/mingw32/bin/gnat.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatchop.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatclean.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatdll.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatfind.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatkr.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatlink.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatls.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatmake.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatname.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatprep.exe
./mingw-w64-i686-gcc-ada/mingw32/bin/gnatxref.exe
./mingw-w64-i686-gcc-libgfortran/mingw32/bin/libgfortran-5.dll
./mingw-w64-i686-gcc-libs/mingw32/bin/libatomic-1.dll
./mingw-w64-i686-gcc-libs/mingw32/bin/libgcc_s_dw2-1.dll (due to new patch)
./mingw-w64-i686-gcc-libs/mingw32/bin/libgomp-1.dll
./mingw-w64-i686-gcc-libs/mingw32/bin/libquadmath-0.dll
./mingw-w64-i686-gcc-libs/mingw32/bin/libssp-0.dll
./mingw-w64-i686-gcc-libs/mingw32/bin/libstdc++-6.dll
./mingw-w64-i686-gcc-objc/mingw32/bin/libobjc-4.dll

Binaries that don't respect either, and use binutils defaults ☹️ :

./mingw-w64-i686-gcc-ada/mingw32/bin/libgnarl-10.dll
./mingw-w64-i686-gcc-ada/mingw32/bin/libgnat-10.dll

@jeremyd2019 jeremyd2019 force-pushed the gcc_set_ldflags_for_target_disable_dynamicbase branch 2 times, most recently from bbde80a to 1c41e8e Compare September 4, 2020 00:42
@jeremyd2019 jeremyd2019 marked this pull request as ready for review September 4, 2020 04:34
@jeremyd2019
Copy link
Member Author

Well, it builds. I'm going to try building python with this, since it is known to use lto, but hopefully others (especially with x86_64) will put these through their paces a bit too.

@jeremyd2019
Copy link
Member Author

I was able to build python both on my i686 tablet, and I also fired up a 64-bit windows virtual machine and built python on x86_64. Both completed without issue.

msys2#6932 and msys2#6907 show packages
have issues with the new default base addresses, so add an option to
change back to the old defaults during the transition.
and --with-boot-ldflags.  Allows these flags to affect binaries produced
post-stage1.  Add LDFLAGS to linking of shared libgcc.
GCC's precompiled header mechanism is not compatible with ASLR, so GCC
itself needs dynamicbase to be disabled, but the runtime libraries would
still benefit from having it set, so only disable dynamicbase for GCC
itself.
Works around segfaults while compiling libgcc (and probably other, hard
to diagnose creashes).  But don't set image-base on lto-plugin.  In
fact, go ahead and let it use the target ldflags instead, while
replicating the other flags it was getting before.
@jeremyd2019 jeremyd2019 force-pushed the gcc_set_ldflags_for_target_disable_dynamicbase branch from 1c41e8e to 49df9cf Compare September 8, 2020 06:12
@jeremyd2019
Copy link
Member Author

jeremyd2019 commented Sep 8, 2020

From discussion on #6932 (comment), I added a command line option to binutils to switch default image bases back to their original 'low' values, and changed my gcc flags to use that instead of specifying the 'magic value' 0x400000. The binutils patch might reasonably be its own pull request, but I merged it into this one for CI's benefit.

@lazka lazka merged commit fe0f700 into msys2:master Sep 10, 2020
@jeremyd2019 jeremyd2019 deleted the gcc_set_ldflags_for_target_disable_dynamicbase branch September 10, 2020 16:55
lazka added a commit to lazka/MINGW-packages that referenced this pull request Apr 22, 2022
* The new release includes https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=2e4e16f75e637d6486d0fdbb8c6ab13701238a55
  which looks like it should disable dynamicbase where required
* All the flags we wanted to inject via LDFLAGS are the default in binutils for some time now

Ideally this cleanup should not change anything.

For context where this was introduced:
msys2#6907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants