Bug: broken libgcc for ARM thumb
The libgcc.a in /usr/local/arm/gcc-7.2.0/lib/gcc/arm-epos-eabi/7.2.0/thumb/libgcc.a has several functions that seems to be ARM (not thumb) and causes the processor in Cortex-M3 machines to misbehave. The bug can be reproduced in any Cortex-M3 with this simple test:
#include <utility/ostream.h> using namespace EPOS; OStream cout; int main() { unsigned long long a = 1234; cout << "a=" << a << endl; return 0; }
which produces a call to libgcc's __udivdi3 (for uul software handling), which, in turn, calls __clzdi2, a non-thumb function. Since Cortex-M3 are thumb-only machines, this ARM mode code wreaks havoc.
The problem was also reported here and here, apparently without a solution.
I see two alternatives: fight with compilation flags to recompile gcc and lead it to produce a correct libgcc (not sure if this is possible) or patch the ligcc.a by hand (i.e. extract all object files, look for non-thumb ones, recompile them by hand with -mthumb, and repacking the lib).