bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
14.86k stars 1.93k forks source link

SIGBUS on ARM cortex-A9 #1427

Open septag opened 6 years ago

septag commented 6 years ago

I get SIGBUS crashes on old android hardware (nexus 7 2012 - Arm cortex-a9), newer hardware works fine, I guess older arm CPUs don't have un-aligned access support in hardware so it raises SIGBUS.

here's the callstack:

(bgfx::RenderDraw::clear()+79)
(bgfx::EncoderImpl::discard()+6)
(bgfx::EncoderImpl::EncoderImpl()+258)
(bgfx::Context::init(bgfx::Init const&)+656)

I have checked RenderDraw structure, and re-ordered the variables and inserted padding, but still I got sigbus on random runs. finally what fixed it was removing the cache line alignment from the structure declaration and the crashes are gone.
I can't seem to understand what caused the problem, as I guess I lack enough knowledge on this matter, can you figure out what was the problem ?

FYI compiling with NDK + clang (v5.0.300080) compile flags:

-g -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11  -Wno-switch -fno-rtti -fno-exceptions -Os -DNDEBUG     -fPIC 

thanks

bkaradzic commented 6 years ago

That callstack doesn't make sense.

Issue getting fixed by removing cache line alignment also makes no sense.

You'll have to investigate more and provide more info about it.

septag commented 6 years ago

It doesn't make sense to me either, there is no pointers to unaligned memory and the compiler should take care of it automatically. I just don't seem to understand it and caused me headaches to trace it. The problem also arises only in release build (-Os), which I can't debug easily. seems like it happens when it tries to write to some RenderDraw variable on RenderDraw::clear I'll try to investigate more and get back to you ...