Bug 12196 - Illegal instruction in "duma" when built with -O2
Summary: Illegal instruction in "duma" when built with -O2
Status: RESOLVED MOVED
Alias: None
Product: buildroot
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-06 08:31 UTC by Aleksey
Modified: 2024-06-15 14:50 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments
Duma core dump test (45.17 KB, application/octet-stream)
2019-12-09 10:53 UTC, Aleksey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksey 2019-09-06 08:31:59 UTC
Duma package build is incorrect. Following original GNUmakefile, it should be build with -O0, but buildroot make it with -O2, that leads to the "Illegal instruction" problem with my program for ARM cpu. This can be fixed by adding "CFLAGS+=-O0 \" into the DUMA_BUILD_CMDS definition in duma.mk.
Comment 1 Thomas Petazzoni 2019-09-11 13:30:37 UTC
THanks for your bug report. However, the real question is why is duma failing in -O2 ? Rather than forcing -O0, it seems much more relevant to understand why it does not work when compiled in -O2.

Could you get a core dump, and see on which instruction it crashes ? Which ARM processor are you using ?
Comment 2 Aleksey 2019-09-17 08:32:41 UTC
Its a specific debug tool, that works on low level, so, I think, author of the duma has a reason to use -O0 in original GNUmakefile.

However, we can try to understand this reason.
Unfortunately I was unable to get core dump in buildroot environment. How can I do it?

As for the CPU, its a Marvell SOC. I have the following options in the configuration:

BR2_ARCH="arm"
BR2_ENDIAN="LITTLE"
BR2_GCC_TARGET_ABI="aapcs-linux"
BR2_GCC_TARGET_CPU="marvell-pj4"
BR2_GCC_TARGET_FPU="vfpv3-d16"
BR2_GCC_TARGET_FLOAT_ABI="softfp"
BR2_GCC_TARGET_MODE="arm"
Comment 3 Thomas Petazzoni 2019-11-27 20:40:08 UTC
Run "ulimit -c unlimited" before starting duma, and you will get a core dump.

Which Marvell processor are you using ?
Comment 4 Aleksey 2019-12-09 10:53:37 UTC
Created attachment 8306 [details]
Duma core dump test
Comment 5 Aleksey 2019-12-09 10:55:02 UTC
It's on the Marvell Poncat3 SOC CPU. Program text:

#include <stdio.h>

int main()
{
        char *a;

        a = malloc(1024);
        a = realloc((void*)a, 2048);
        free(a);
        return 0;
}
Comment 6 Arnout Vandecappelle 2019-12-13 22:34:30 UTC
Really weird... This is the disassembly around the faulting instruction:

   0xb6e04694 <+672>:   b       0xb6e046dc <__gettextparse+744>
   0xb6e04698 <+676>:   b       0xb6e046dc <__gettextparse+744>
=> 0xb6e0469c <+680>:   b       0xb6e04ab8 <__gettextparse+1732>
   0xb6e046a0 <+684>:   b       0xb6e04a94 <__gettextparse+1696>
   0xb6e046a4 <+688>:   b       0xb6e049fc <__gettextparse+1544>
   0xb6e046a8 <+692>:   b       0xb6e049e4 <__gettextparse+1520>


So it's in the middle of a switch table, simple relative branch instruction 0xea000105. The instructions that it jumps to all look pretty normal as well.

However, duma does do weird things with the code. It is possible that the real fault is hidden by some exception handling within duma itself... gdb isn't able to print a proper backtrace, so that could be an indication...
Comment 7 Yann E. MORIN 2024-06-15 14:50:24 UTC
Thank you for your report.

The issue tracker for the Buildroot project has been moved to
the Gitlab.com issue tracker:
    https://gitlab.com/buildroot.org/buildroot/-/issues

We are taking this opportunity to close old issues in this old
tracker. If you believe your issue is still relevant, please
open one in the new issue tracker.

Thank you!