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

Segfault in package using Nemo with MP integers #790

Closed
defeo opened this issue Feb 16, 2020 · 7 comments
Closed

Segfault in package using Nemo with MP integers #790

defeo opened this issue Feb 16, 2020 · 7 comments

Comments

@defeo
Copy link

defeo commented Feb 16, 2020

This simple module causes a segfault when in a Julia package (not if it is included in the REPL, though, so it's likely related to compilation):

module Bug

import Nemo: ZZ

export x

x = ZZ(2)^62

end # module

to trigger the segfault, load Bug and try to display x:

julia> using Bug

Welcome to Nemo version 0.16.2

Nemo comes with absolutely no warranty whatsoever


julia> x

signal (11): Segmentation fault
in expression starting at REPL[3]:0
__gmpz_size at /usr/bin/../lib/libgmp.so (unknown line)
fmpz_get_str at /workspace/srcdir/flint2/fmpz/get_str.c:34
base at /home/defeo/.julia/packages/Nemo/LBWHq/src/flint/fmpz.jl:1551
dec at /home/defeo/.julia/packages/Nemo/LBWHq/src/flint/fmpz.jl:1537 [inlined]
string at /home/defeo/.julia/packages/Nemo/LBWHq/src/flint/fmpz.jl:228 [inlined]
show at /home/defeo/.julia/packages/Nemo/LBWHq/src/flint/fmpz.jl:230 [inlined]
show at ./multimedia.jl:47
...[output truncated]

if I change the definition to x = ZZ(2)^61, the segfault goes away.

Using Nemo v0.16.2 in Julia 1.3.1 on Arch. I'm copying Manifest.toml for completeness.

# This file is machine-generated - editing it directly is not advised

[[AbstractAlgebra]]
deps = ["InteractiveUtils", "LinearAlgebra", "Markdown", "Random", "SparseArrays", "Test"]
git-tree-sha1 = "941d2cfb0fab4e6bb976bbe576f56f724e5a8d20"
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
version = "0.8.0"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BinaryProvider]]
deps = ["Libdl", "SHA"]
git-tree-sha1 = "5b08ed6036d9d3f0ee6369410b830f8873d4024c"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.8"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Nemo]]
deps = ["AbstractAlgebra", "BinaryProvider", "InteractiveUtils", "Libdl", "LinearAlgebra", "Markdown", "Random", "Test"]
git-tree-sha1 = "bdef7f0f78397fb75beef92fd9ad6cee5c448942"
uuid = "2edaba10-b0f1-5616-af89-8c11ac63239a"
version = "0.16.2"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
@defeo
Copy link
Author

defeo commented Feb 16, 2020

Is it normal that it tries to link to system GMP? I just updated the Arch GMP package, may it be related?
How do I trigger a recompilation? build Nemo does nothing.

@wbhart
Copy link
Contributor

wbhart commented Feb 16, 2020

You'll have to disable precompilation if you want to access x. Once it is precompiled, the original x is long gone and you just have an invalid pointer.

As for the system GMP, no it should not be linking against that. I'm not sure why it would be doing that. We use the Julia binary builder for GMP.

@defeo
Copy link
Author

defeo commented Feb 16, 2020

I see BigInts can be precompiled. So, was that a design choice from your side, or is it that only native Julia types can be precompiled?

@wbhart
Copy link
Contributor

wbhart commented Feb 16, 2020

I'm not sure what you mean by "BigInt's can be precompiled". Does this same example work with Julia BigInt's? If it does, they must have done something tricky to make that work. As far as I know, any C object that is created during precompilation is not saved anywhere. When you refer to it after precompilation, it's just gone.

I genuinely don't know how to make that work.

@thofma
Copy link
Member

thofma commented Feb 17, 2020

For a long time it was not possible to precompile them, but it was fixed, see JuliaLang/julia#15722.
I think they just serialize/deserialize it together with the rest of the precompiled code.

@thofma
Copy link
Member

thofma commented Feb 17, 2020

I guess you know this already, but the workaround is to put it into the __init__() function of the module.

@defeo
Copy link
Author

defeo commented Feb 17, 2020

Does this same example work with Julia BigInt's?

It does.

I guess you know this already, but the workaround is to put it into the __init__() function of the module.

I'm still not a Julia expert, I didn't know about __init__(). Thanks!

Anyway, I think this can be closed. If there's a motivation to write serializers/deserialezers, a different issue should be open. Thank you both!

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

No branches or pull requests

3 participants