HomePhabricator

[CMAKE] Prevent linker segfault with recent MinGw version

Description

[CMAKE] Prevent linker segfault with recent MinGw version

Summary:
This is a follow-up to D11227. When testing for the linker flags, cmake builds an .exe with dummy content and check it succeeds. This is causing an issue due to the bug https://sourceware.org/bugzilla/show_bug.cgi?id=26588: the test fails because the linker segfaults. Disabling the the section relocation fixes the issue, however the option must only be set for versions on MinGw that support it (otherwise that dumb linker will error out rather than ignoring the unknown option like any other linker would).
This diff tests for the section relocation option support first, then disables it explicitely for each flag under test. This disable has no impact on the final executable and only applies to the dummy code snippet that is used to test for flag support.

This allows also for explicitely setting the --enable-reloc-section if supported, rather than relying on the linker defaults which tend to change over time. Note that this is supposed to be redundant because --dynamicbase implies --enable-reloc-section.

Depends on D11227 for the test plan (otherwise bitcoin-cli won't build at all).

Test Plan:
On Debian 10 (old MinGw) and 11 (recent MinGw):

cmake -GNinja .. \
  -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/Win64.cmake \
  -DBUILD_BITCOIN_SEEDER=OFF
ninja security-check-bitcoin-cli

Run the gitian windows build.

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D11229

Details

Provenance
FabienAuthored on Mar 18 2022, 17:38
FabienPushed on Mar 19 2022, 20:56
Reviewer
Restricted Project
Differential Revision
D11229: [CMAKE] Prevent linker segfault with recent MinGw version
Parents
rABC5c427a98b4e1: build: fix ASLR for bitcoin-cli on Windows
Branches
Unknown
Tags
Unknown