Segfault when building with gcc 7
We recently switched nixpkgs to gcc 7, and now our perl cross-builds fail with:
./miniperl_top make_patchnum.pl Attempt to free unreferenced scalar: SV 0x7c38a0. Attempt to free unreferenced scalar: SV 0x7a4338 at /build/perl-5.24.3/lib/strict.pm line 38. make: *** [Makefile:202: lib/Config_git.pl] Segmentation fault
Note that switching back to gcc 6 for miniperl itself fixes it
Can you post xconfig.sh and maybe also config.log from this build somewhere?
No segfaults for me on x86_64 host with gcc 7.2.1, and valgrind reports nothing. make_patchnum.pl is the first script it runs with miniperl and that line must be the first attempt to free anything.
Sure, here's a build log, xconfig.sh, and config.log https://gist.github.com/shlevy/ade184d2b0f2ff59f17e55e74e97ccfb. It's extra verbose to show all the extra flags we pass to our compiler.
This is for riscv64-unknown-linux-gnu, but I got a similar result for aarch64-unknown-linux-gnu.
Ok I think I got it. GCC 4.9 and above needs -fwrapv to build perl. The fix wasn't applied properly to gcc-7.x, and perl-cross failed to detect gcc version in your hardened setup anyway. This only matters for -O2 and above, in particular -Os builds work just fine.
If possible, please try this branch: https://github.com/arsv/perl-cross/tree/nix (or just apply https://github.com/arsv/perl-cross/commit/07208bc1707b8be3ea170c62c59120020cf0f87f on top of the version you're using)
The underlying issue: https://rt.perl.org/Public/Bug/Display.html?id=121505
Great, that worked! Do we need that patch for non-cross-compiled perl? https://github.com/NixOS/nixpkgs/pull/35670/commits/b45fb438b12c9bf5893124c639adabce47d5e96e
Probably not. Unless you use perl-cross for native builds, which doesn't seem to be the case.
Mainline Configure from perl-5.24 should be able to handle gcc-7, no changes are needed there. https://github.com/Perl/perl5/blob/f12a20dd7713aa2d7a302b66ce8be168e5ab4fec/Configure#L4741-L4755
If unsure, check config.sh for -fwrapv in ccflags.
I'm still seeing this with perl 5.24.1 cross compiled with perl-cross 1.9 via a gentoo ebuild. Are there any other possible fixes for this? "-fwrapv" is in my cflags.
Same exact segfault? Can you post xconfig.sh and config.log somewhere?
There's also -fno-strict-aliasing, but if -fwrapv is there the other one should be as well. Check also for -O3 or any standalone -f-something, especially if the target is unusual. Maybe try building it with -O0 or -Os.
I had this problem back in February. I think I stumbled across this report, worked around it, then forgot about it until just now when I ran into it again. I can confirm that I usually use -O3 but -fwrapv and -O2 doesn't work either. -O0 does. This is for m68k-linux-gnu, which is relatively obscure.
Current defaults are -fwrapv -fno-strict-aliasing. I skimmed over the mainline Configure, it does not look like they are passing anything else either. If you did not pass -fno-strict-aliasing, try adding it, aliasing issues can easily cause crashes.
-O3 -fwrapv -fno-strict-aliasing does indeed work. I can't remember if I ever checked the detection mechanism. I'll let you know if I find anything.
Oh hai @chewi, fancy seeing you here.
Just reporting that under cross compile, the built perl still segfaults this way w/ perl 5.30.3 w/ cross 1.3.4 & GCC 10.
This caused a significant amount of "fun" for building a scratch VM for m68k as it means autoconf and friends like to fail :)
Fortunately, with enough brute force, natively building perl under emulation was achievable, and didn't suffer this problem.
For issues like this, it would be really nice to have config.sh from the failing cross build, and also the one from a successful build if available. It's very difficult to tell what's going on otherwise.
Given the rest of this issue, the first thing I would be looking for is which compiler flags were actually used for either build.