perl-cross icon indicating copy to clipboard operation
perl-cross copied to clipboard

Segfault when building with gcc 7

Open shlevy opened this issue 7 years ago • 13 comments

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

shlevy avatar Feb 25 '18 05:02 shlevy

Note that switching back to gcc 6 for miniperl itself fixes it

shlevy avatar Feb 25 '18 05:02 shlevy

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.

arsv avatar Feb 25 '18 08:02 arsv

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.

shlevy avatar Feb 25 '18 13:02 shlevy

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

arsv avatar Feb 26 '18 11:02 arsv

Great, that worked! Do we need that patch for non-cross-compiled perl? https://github.com/NixOS/nixpkgs/pull/35670/commits/b45fb438b12c9bf5893124c639adabce47d5e96e

shlevy avatar Feb 26 '18 12:02 shlevy

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.

arsv avatar Feb 26 '18 13:02 arsv

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.

fsparrow avatar Nov 13 '18 13:11 fsparrow

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.

arsv avatar Nov 13 '18 18:11 arsv

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.

chewi avatar Dec 03 '19 15:12 chewi

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.

arsv avatar Dec 04 '19 14:12 arsv

-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.

chewi avatar Dec 04 '19 22:12 chewi

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.

kentfredric avatar Oct 19 '20 02:10 kentfredric

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.

arsv avatar Oct 19 '20 11:10 arsv