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

Always set -fwrapv in the gcc compiler flags on Win32. #18781

Closed
wants to merge 1 commit into from

Conversation

nwc10
Copy link
Contributor

@nwc10 nwc10 commented May 10, 2021

We need this because we are unfortunately relying on the behaviour of signed
integer overflow. This is undefined behaviour in C (which gcc's optimiser
likes to take advantage of) unless we use this flag.

Previously we had used it conditionally based on gcc version, but that code
failed to consider gcc versions greater than 9. We realise that the flag is
actually present from the minimum gcc that we support, so we should simply
add it always. Fixes #18739.

@nwc10
Copy link
Contributor Author

nwc10 commented May 10, 2021

If this builds and passes tests on Win32 (and my wording is good fail), please could someone fast-forward blead with this.

Do we actually have anything smoking gcc on win32?

@nwc10 nwc10 requested review from tonycoz and steve-m-hay May 10, 2021 08:14
We need this because we are unfortunately relying on the behaviour of signed
integer overflow. This is undefined behaviour in C (which gcc's optimiser
likes to take advantage of) unless we use this flag.

Previously we had used it conditionally based on gcc version, but that code
failed to consider gcc versions greater than 9. We realise that the flag is
actually present from the minimum gcc that we support, so we should simply
add it always. Fixes #18739.
@nwc10 nwc10 force-pushed the smoke-me/win32-fwrapv-always branch from 9fefecc to 3ca197b Compare May 10, 2021 08:17
@nwc10
Copy link
Contributor Author

nwc10 commented May 10, 2021

Sigh, I shouldn't do this on a fast machine that doesn't have a spell checker locally.

@sisyphus
Copy link
Contributor

It's fine for me.
I've just applied the patch to GNUmakefile manually by simply removing the 3 lines of code that your patch removed.
LGTM and tests fine with a couple of mingw-w64 compilers (namely gcc-9.3.0 and gcc-10.3.0).
I don't see the point in testing any more rigorously than that - but I can if you like.

I haven't tested to see that -fwrapv doesn't get added when MSVC is used, but it's quite apparent from the code that -fwrapv is not added when CC is 'cl'.
In any case, it seems that 'cl' would simply ignore that flag (and tell us so).

Cheers,
Rob

Copy link
Contributor

@steve-m-hay steve-m-hay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry a little about the comment that Zefram added on #13690 that -fwrapv is broken prior to 4.3: #13690 (comment)
I will try to test this with earlier (www.mingw.org) gccs, but I just found that it doesn't currently build anyway (SE_PRIVILEGE_REMOVED, RRF_RT_REG_DWORD and KEY_WOW64_64KEY are undeclared... - presumably happening since commit edfcb93).
Also, there is a typo in the comments: "addeed".

@nwc10
Copy link
Contributor Author

nwc10 commented May 10, 2021

I worry a little about the comment that Zefram added on #13690 that -fwrapv is broken prior to 4.3: #13690 (comment)
I will try to test this with earlier (www.mingw.org) gccs, but I just found that it doesn't currently build anyway (SE_PRIVILEGE_REMOVED, RRF_RT_REG_DWORD and KEY_WOW64_64KEY are undeclared... - presumably happening since commit edfcb93).
Also, there is a typo in the comments: "addeed".

Pants! Thanks. I guess I should drag that commit down onto a machine with a spell checker and see what else I goofed.

In 9 days we will celebrate the 13th anniversary of the gcc 4.2.4 release - the question @rjbs asked on the PSC call was whether we are really concerned with supporting a compiler that old. Does 4.2 even compile "hello world" on post NT 4 systems? I'm not really familiar with how compatible Win32 manages to be, but is supporting this about as relevant as trying to support running on Unix on mixed endian hardware?

@steve-m-hay
Copy link
Contributor

In 9 days we will celebrate the 13th anniversary of the gcc 4.2.4 release - the question @rjbs asked on the PSC call was whether we are really concerned with supporting a compiler that old. Does 4.2 even compile "hello world" on post NT 4 systems? I'm not really familiar with how compatible Win32 manages to be, but is supporting this about as relevant as trying to support running on Unix on mixed endian hardware?

The build of 5.34.0 RC1 is also broken. I've just posted to p5p to ask the question should we drop support for www.mingw.org compilers, given how flakey they seem to be: We only had 3.4.5-5.3.0 working anyway; all the later ones already had other issues.

(Yes, gcc-3.4.5 does build a perfectly runnable "hello world" C program on Windows 10.)

@Tux
Copy link
Contributor

Tux commented May 10, 2021

I do not have HP-UX 10.20 anymore. That system died in a poof of orange smoke, but it had gcc-3.4.6 and no way to build anything newer. Which means that anyone still using HP-UX 10.20, the most recent available gcc compiler is 3.4.6 (as I was the only one making gcc available for 10.20)
I do have HP-UX 11.11, but it is powered off currently. It still has GNU gcc-4.6.1 and no way to build anything newer. 4.6.1 is newer than 4.2.4, so that should by no means be a blocker.
The HP-UX 11.23 box won't boot due to disk failure. It had 4.6.1
The HP-UX 11.31 runs gcc 4.7.2 and I got no further in any attempt to build a more recent gcc (I tried several times)

The AIX box that p5p has access to runs gcc-4.2.4 and I have exactly NULL tuits to even try to build a more recent gcc on it

@nwc10
Copy link
Contributor Author

nwc10 commented May 10, 2021

This was only relevant for Win32.

For *nix, it seems that Configure handles all this nicely already:

# gcc 4.9 by default does some optimizations that break perl.
# see ticket 121505.
#
# The -fwrapv disables those optimizations (and probably others,) so
# for gcc 4.9 (and later, since the optimizations probably won't go
# away), add -fwrapv unless the user requests -fno-wrapv, which
# disables -fwrapv, or if the user requests -fsanitize=undefined,
# which turns the overflows -fwrapv ignores into runtime errors.
case "$gccversion" in
4.[3-9].*|4.[1-9][0-9]*|[5-9].*|[1-9][0-9]*)
    case "$ccflags" in
    *-fno-wrapv*|*-fsanitize=undefined*|*-fwrapv*) ;;
    *) ccflags="$ccflags -fwrapv" ;;
    esac
esac

so I don't think we need to worry about old gcc for anything that builds with Configure - for *nix "it ain't broken, so don't fix it".

@sisyphus
Copy link
Contributor

sisyphus commented May 10, 2021 via email

@xenu
Copy link
Member

xenu commented May 10, 2021

I worry a little about the comment that Zefram added on #13690 that -fwrapv is broken prior to 4.3:

I tried to find anything about this in google, but to no avail. Anyway, I'm not aware of any valid reasons to use such an old gcc version on Windows. We really should revise our supported compiler/OS version list.

Comment on lines -586 to -594
# If you are using GCC, 4.3 or later by default we add the -fwrapv option.
# See https://github.com/Perl/perl5/issues/13690
#
GCCWRAPV := $(shell if "$(GCCVER1)"=="4" (if "$(GCCVER2)" geq "3" echo define) else if "$(GCCVER1)" geq "5" (echo define))
# Previously, if you were using GCC, 4.3 or later we addeed the -fwrapv option.
# See https://github.com/Perl/perl5/issues/13690 and 18739
# However, as documented in README.win32 our minimum Win32 gcc version is 3.4.5.
# As that supports -fwrapv it's both simpler and more correct to unconditionally
# add it to the flags:

ifeq ($(GCCWRAPV),define)
BUILDOPT += -fwrapv
MINIBUILDOPT += -fwrapv
endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the switch should remain, so you can do gmake GCCWRAPV=undef to test building without -fwrapv.

The ideal is that we eventually remove the -fwrapv entirely, being able to test without it easily is desirable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points, and I'd not thought of this. Agree, this is better than what I did.

Given that I don't have access to a Win32 system to test this, and I think that you do, and I think that testing the non-default case requires doing something interactively

  1. Could you implement this and test that it works
  2. Push it to a branch to replace mine, so that (at least one of) @steve-m-hay @xenu or @sisyphus can check it (better than me)
  3. If someone else says yes and no-one says no, it goes to blead.

I feel like I'm turning into a project manager and it's not an enjoyable thought. :-/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #18782 (which @sisyphus has found it looks like)

@sisyphus
Copy link
Contributor

sisyphus commented May 11, 2021 via email

@nwc10
Copy link
Contributor Author

nwc10 commented May 12, 2021

Oooh, this is actually my PR. So I don't feel bad in rejecting it and saying #18782 is better.

@nwc10 nwc10 closed this May 12, 2021
@nwc10 nwc10 deleted the smoke-me/win32-fwrapv-always branch May 12, 2021 08:20
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.

[Win32] "-fwrapv" disappears from ccflags with gcc version 10.
6 participants