MAKETHIN - memory access outside program range
Closed this issue · 9 comments
Hi,
I started using cpymad yesterday and ran into the following problem.
When running a makethin command on a simple fodo lattice I get the following output:
makethin: style chosen : teapot
makethin: slicing sequence : ring
+++ memory access outside program range, fatal +++
I do not have this problem on my laptop (opensuse leap 15.1) but seems to happen on debian:buster.
I have attached a zip file that contains a dockerfile for setting up the environment, the fodo sequence file, the python script and madx file for testing it with madx downloaded from CERN webpage.
To reproduce:
make build
make run # start container
madx < thintest.madx # works
python3 script.py # fails with memory error
Thanks in advance for the help.
Tom
recreate_mem_error.zip
Hi,
thanks for reporting the issue!
I can reproduce the crash with cpymad 1.6.0 and stripped your code down to the following minimal example (no docker/make/etc required):
from cpymad.madx import Madx
madx = Madx()
madx.call(file="minimal.madx")
And MAD-X:
seq: sequence, l=2, refer=center;
q1: quadrupole, l=1, at=1;
endsequence;
beam;
use, sequence=seq;
select, flag=MAKETHIN, class=quadrupole;
makethin, sequence=seq;
The error goes away when dropping the q1:
label.
Further investigation pending (no promises when I will have time)
I can reproduce with 1.6 but not with 1.5.0 that works regularly.
A simple back trace from gdb showed me
#1 0x00007fffe4337332 in std::ctype<char>::_M_widen_init() const () from ...cpymad/libmadx.cpython-37m-x86_64-linux-gnu.so
...
#49 0x00007fffe41f0708 in expr_from_value_2(double) [clone .28632] () from ....cpymad/libmadx.cpython-37m-x86_64-linux-gnu.so
Could it be due to -fvisibility=hidden and -flto
?
Could be due to -flto
(in which case it might be a latent bug in MAD-X), but not -fvisibility=hidden
(which was already used in previous releases)
Good call about -flto
! I can confirm that replacing -flto
by -fno-lto
in .github/build/manylinux1/cpymad.sh
makes the problem disappear. I suggest we do a quick bugfix release with this change. Can you patch this in your PR @rdemaria?
I suspect this could be due to a dormant bug in MAD-X that is hidden due to compiler specifics, and in order to truly fix this, one might start by compiling MAD-X with -fsanitize=address
and fix everything that shows up. Also when compiling MAD-X there are several compiler warnings that hint toward memory issues, which should be addressed eventually. However, all of this will likely take considerable effort...
Hope this is fixed in the new release v1.6.1
which should be available in a few minutes. Please let us know if you still have problems after updating @tomerten.
I work with @tomerten and can confirm that the memory error does not occur with v1.6.1. Thanks!
Hi all,
Also on my side everything is now working. Thank you for the quick response and solution.