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

Workaround for GMP crash on Cygwin (regression introduced by PR #3434) #3435

Merged
merged 5 commits into from
May 4, 2019

Conversation

embray
Copy link
Contributor

@embray embray commented May 2, 2019

Description

Adds ENSURE_BAG which on the relevant platform (Cygwin 64-bit, at least) simply zero-fills the contents of a bag before using it.

This is perhaps a naive attempt and I'm not sure it covers every possible case, but it does at least fix the test case from #3434 using Bernoulli().

Needs proper documentation, but I'll add that if/when this approach is approved.

Text for release notes

Fixed crash on 64-bit Cygwin that could occur in some integer operations.

Checklist for pull request reviewers

  • proper formatting

If your code contains kernel C code, run clang-format on it; the
simplest way is to use git clang-format, e.g. like this (don't
forget to commit the resulting changes):

git clang-format $(git merge-base master)
  • usage of relevant labels

    1. either release notes: not needed or release notes: to be added
    2. at least one of the labels bug or enhancement or new feature
    3. for changes meant to be backported to stable-4.X add the backport-to-4.X label
    4. consider adding any of the labels build system, documentation, kernel, library, tests
  • runnable tests

  • adequate pull request title

  • well formulated text for release notes

  • relevant documentation updates

  • sensible comments in the code

…memory is

really committed by the OS for a new bag.

Call ENSURE_BAG on new bags created in integer.c if they might be
passed as an argument to a GMP function.
@embray
Copy link
Contributor Author

embray commented May 2, 2019

(Rebased on current master branch; mine was quite a bit behind it seems.)

@coveralls
Copy link

coveralls commented May 2, 2019

Coverage Status

Coverage increased (+0.05%) to 85.038% when pulling 95a011a on embray:cygwin/issue-3434 into 7ab3b05 on gap-system:master.

@ChrisJefferson
Copy link
Contributor

Thanks. I like this PR. While we might be able to make it more efficient (by only touching each page), I'd like to keep it simple, as Cygwin is already poorly tested, and this is a very subtle issue.

Once it is fixed in GMP, we might want to think about how to selectively enable it, or require the up to date version.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Thank you! I have some minor change requests. But overall, this seems very sensible to me.

src/gasman.h Outdated Show resolved Hide resolved
@embray
Copy link
Contributor Author

embray commented May 3, 2019

Thanks. I like this PR. While we might be able to make it more efficient (by only touching each page), I'd like to keep it simple, as Cygwin is already poorly tested, and this is a very subtle issue.

This is actually what I tried first, but as you previously suspected it was trickier than I had expected to get the compiler to not just optimize it away. E.g. volatile had basically not effect with a local variable. I'm sure it can be done but I didn't want to spend a lot of time messing with it.

@embray
Copy link
Contributor Author

embray commented May 3, 2019

Once it is fixed in GMP, we might want to think about how to selectively enable it, or require the up to date version.

Well, so far at least one of the GMP developers has been supportive of the idea: https://gmplib.org/list-archives/gmp-bugs/2019-May/004544.html GMP has some good version macros so it would be easy to disable based on a version check if/when fixed. I should probably look into how to check if GMP is actually MPIR, because MPIR actually doesn't have this problem as far as I can tell. In MPIR they rewrote everything to use the YASM assembler, which has implicit support for adding the stack unwinding metadata on Windows.

@fingolfin fingolfin added regression A bug that only occurs in the branch, not in a release release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: kernel labels May 3, 2019
@fingolfin
Copy link
Member

Editorial note: Since this is a fix for a recent regression that was in no GAP release, there is no need for release notes.

@codecov
Copy link

codecov bot commented May 3, 2019

Codecov Report

Merging #3435 into master will decrease coverage by 2.72%.
The diff coverage is 88.88%.

@@            Coverage Diff             @@
##           master    #3435      +/-   ##
==========================================
- Coverage    80.2%   77.47%   -2.73%     
==========================================
  Files         695      692       -3     
  Lines      342574   340498    -2076     
==========================================
- Hits       274750   263810   -10940     
- Misses      67824    76688    +8864
Impacted Files Coverage Δ
src/gasman.h 67.44% <0%> (-25.42%) ⬇️
src/integer.c 97.52% <100%> (-1.02%) ⬇️
src/modules.h 16.66% <0%> (-83.34%) ⬇️
lib/contfrac.gi 31.42% <0%> (-67.15%) ⬇️
src/saveload.c 3.27% <0%> (-64.93%) ⬇️
src/libgap-api.c 0% <0%> (-62.58%) ⬇️
src/cyclotom.h 50% <0%> (-50%) ⬇️
src/records.h 50% <0%> (-50%) ⬇️
src/gapstate.h 42.85% <0%> (-42.86%) ⬇️
src/vec8bit.h 51.78% <0%> (-42.86%) ⬇️
... and 230 more

@embray
Copy link
Contributor Author

embray commented May 3, 2019

That said, would there be any objection to backporting this and #3335 to the 4.10-stable branch? If so for some reason that's fine. I just wondered.

@fingolfin
Copy link
Member

@embray at this point, I am not sure there will be any further release in the 4.10 line; we plan to release GAP 4.11 in May.

@embray
Copy link
Contributor Author

embray commented May 3, 2019

Ah, ok. Fair enough.

@fingolfin fingolfin changed the title Proposed workaround for #3434 Workaround for GMP crash on Cygwin (regression introduced by PR #3434) May 3, 2019
@ChrisJefferson
Copy link
Contributor

Thanks again for tracking this down.

@slel
Copy link

slel commented Aug 8, 2019

@ChrisJefferson @fingolfin could this be backported in GAP 4.10
so it becomes part of GAP 4.10.3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression A bug that only occurs in the branch, not in a release release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants