The ld
in binutils has historically had a few issues with PE binaries, there’s a good summary in this thread.
One issue in particular was ld
stripping the .reloc
section out of PE binaries, even though it’s required for functioning ASLR. This was reported by a Tor developer in 2014 and they have been patching their own binutils ever since. However their patch only made it into binutils at the start of this year. It adds an --enable-reloc-section
flag, which is turned on by default if you are using --dynamic-base
. In the mean time this issue has also been worked around by other projects, such as FFmpeg, see this commit.
I have checked our recent supported Windows release binaries, and they do contain a .reloc
section. From what I understand, we are using all the right compile/linker flags, including -pie
& -fPIE
, and have never run into the crashing/entrypoint issues that other projects might have seen.
One other thing worth noting here, it how Debian/Ubuntu patch the binutils that they distribute, because that’s what we end up using in our gitian builds.
In the binutils-mingw-w64 in Bionic (18.04), which we currently use in gitian, PE hardening options/security flags are enabled by default. See the changelog and the relevant commit.
However in Focal (20.04), this has now been reversed. PE hardening options are no-longer the default. See the changelog and relevant commit, which cites same .reloc issue mentioned here.
Given that we explicitly specify/opt-in to everything that we want to use, the defaults aren’t necessarily an issue for us. However I think it highlights the importance of continuing to be explicit about what we want, and not falling-back or relying on upstream.
This was also prompted by the possibility of us doing link time garbage collection, see #18579 & #18605. It seemed some sanity checks would be worthwhile in-case the linker goes haywire while garbage collecting.
I think Guix is going to bring great benefits when dealing with these kinds of issues. Carl you might have something to say in that regard.