Crash on reentering footprint viewer

Bug #1840088 reported by Timothy Pearson on 2019-08-13
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
KiCad
Critical
shawn

Bug Description

Using KiCad 5.1.4 I can reliably cause a crash / SIGFPE by:

1.) Creating (or opening) a project with a single BGA part in the schematic, with an assigned BGA footprint from the Pretty library (e.g. BG121).

2.) Opening the footprint assignment tool

3.) Opening the footprint viewer

4.) Opening the 3D view from the footprint viewer

5.) Closing the 3D view and the footprint viewer

6.) Opening the footprint viewer again

Backtrace:

Thread 1 "kicad" received signal SIGFPE, Arithmetic exception.
__libc_femergeenv_ppc (new_mask=18446744073709031423, old_mask=18446744073709551360, envp=<synthetic pointer>) at ../sysdeps/powerpc/fpu/fenv_private.h:120
120 ../sysdeps/powerpc/fpu/fenv_private.h: No such file or directory.
(gdb) bt
#0 __libc_femergeenv_ppc (new_mask=18446744073709031423, old_mask=18446744073709551360, envp=<synthetic pointer>) at ../sysdeps/powerpc/fpu/fenv_private.h:120
#1 libc_feresetround_ppc (envp=<synthetic pointer>) at ../sysdeps/powerpc/fpu/fenv_private.h:135
#2 libc_feresetround_ppc_ctx (ctx=<synthetic pointer>) at ../sysdeps/powerpc/fpu/fenv_private.h:212
#3 __cos (x=<optimized out>) at ../sysdeps/ieee754/dbl-64/s_sin.c:276
#4 0x00007fffd19f6cbc in MATRIX3x3<double>::SetRotation (this=<optimized out>, aAngle=0) at ./include/math/matrix3x3.h:251
#5 KIGFX::GAL::ComputeWorldScreenMatrix (this=<optimized out>) at ./common/gal/graphics_abstraction_layer.cpp:189
#6 0x00007fffd1962c0c in KIGFX::VIEW::SetScale (this=0x19b5c9f0, aScale=<optimized out>, aAnchor=...) at ./common/view/view.cpp:590
#7 0x00007fffd1973394 in KIGFX::VIEW::SetScale (this=<optimized out>, aScale=<optimized out>) at ./include/view/view.h:252
#8 COMMON_TOOLS::ZoomFitScreen (this=<optimized out>, aEvent=...) at ./common/tool/common_tools.cpp:258
#9 0x00007fffd197519c in std::__invoke_impl<int, int (COMMON_TOOLS::*&)(TOOL_EVENT const&), COMMON_TOOLS*&, TOOL_EVENT const&> (__f=<optimized out>, __t=<optimized out>,
    __args=...) at /usr/bin/../lib/gcc/powerpc64le-linux-gnu/8/../../../../include/c++/8/bits/invoke.h:73
#10 std::__invoke<int (COMMON_TOOLS::*&)(TOOL_EVENT const&), COMMON_TOOLS*&, TOOL_EVENT const&> (__fn=<optimized out>, __args=..., __args=...)
    at /usr/bin/../lib/gcc/powerpc64le-linux-gnu/8/../../../../include/c++/8/bits/invoke.h:95
#11 std::_Bind<int (COMMON_TOOLS::*(COMMON_TOOLS*, std::_Placeholder<1>))(TOOL_EVENT const&)>::__call<int, TOOL_EVENT const&, 0ul, 1ul>(std::tuple<TOOL_EVENT const&>&&, std::_Index_tuple<0ul, 1ul>) (this=<optimized out>, __args=...) at /usr/bin/../lib/gcc/powerpc64le-linux-gnu/8/../../../../include/c++/8/functional:400
#12 std::_Bind<int (COMMON_TOOLS::*(COMMON_TOOLS*, std::_Placeholder<1>))(TOOL_EVENT const&)>::operator()<TOOL_EVENT const&, int>(TOOL_EVENT const&) (this=<optimized out>,
    __args=...) at /usr/bin/../lib/gcc/powerpc64le-linux-gnu/8/../../../../include/c++/8/functional:482
#13 std::_Function_handler<int (TOOL_EVENT const&), std::_Bind<int (COMMON_TOOLS::*(COMMON_TOOLS*, std::_Placeholder<1>))(TOOL_EVENT const&)> >::_M_invoke(std::_Any_data const&, TOOL_EVENT const&) (__functor=..., __args=...) at /usr/bin/../lib/gcc/powerpc64le-linux-gnu/8/../../../../include/c++/8/bits/std_function.h:282
#14 0x00007fffd19866e4 in std::function<int (TOOL_EVENT const&)>::operator()(TOOL_EVENT const&) const (this=<optimized out>, __args=...)
    at /usr/bin/../lib/gcc/powerpc64le-linux-gnu/8/../../../../include/c++/8/bits/std_function.h:687
#15 COROUTINE<int, TOOL_EVENT const&>::callerStub (aData=<optimized out>) at ./include/tool/coroutine.h:331
#16 0x00007fffd19e1f70 in make_fcontext () from /usr/bin/_cvpcb.kiface
#17 0x00007fffd19866e4 in std::function<int (TOOL_EVENT const&)>::operator()(TOOL_EVENT const&) const (this=<optimized out>, __args=...)
    at /usr/bin/../lib/gcc/powerpc64le-linux-gnu/8/../../../../include/c++/8/bits/std_function.h:687
#18 COROUTINE<int, TOOL_EVENT const&>::callerStub (aData=<optimized out>) at ./include/tool/coroutine.h:331
#19 0x00007fffd19e1f70 in make_fcontext () from /usr/bin/_cvpcb.kiface
(gdb)

Seth Hillbrand (sethh) wrote :

Hmm... This looks like context switching badness. We should not have floating point exceptions enabled. Somehow this was enabled between calls. My guess would be that we aren't storing the fp registers between context switches.

shawn (shawnanastasio) wrote :

I've discovered the issue - the libcontext code for ppc64 should not be saving/restoring FPSCR as doing so is a violation of the ELFv2 ABI and is completely unnecessary (though not a violation) of the ELFv1 ABI. Attached is a patch that fixes this.

Seth Hillbrand (sethh) wrote :

Thanks shawn! I note that boost has also removed the register saving in their upstream asm, so I'm inclined to push this if it fixes the issue for you.

Unfortunately, we don't have an established PPC64 test machine and I can't get this crash using KEMU. @Timothy, do you compile yourself or do you get your packages from a source?

shawn (shawnanastasio) wrote :

Hi Seth. Strange to hear that you can't reproduce in QEMU. Are you running a little endian distro?
As far as I can see this only affects the ELFv2 ABI so most big endian distros aren't affected.

Also worth nothing that I was able to reproduce simply by opening the PCB Layout Editor in
an empty project.

Timothy Pearson (kb9vqf) wrote :

I both compiled and used the Debian packages, no difference (both crashed). Compiling the same sources with Shawn's patch completely resolved the issue for me.

Changed in kicad:
status: New → Fix Committed
Seth Hillbrand (sethh) wrote :

Sounds good. Thank you for testing.

Patch has been pushed. @shawn, thank you for the rapid fix!

Changed in kicad:
milestone: none → 5.1.5
Changed in kicad:
importance: Undecided → Critical
Seth Hillbrand (sethh) on 2019-08-22
Changed in kicad:
assignee: nobody → shawn (shawnanastasio)
Changed in kicad:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers