Bug 502830 - Valgrind memcheck on marvell-cn10xxx: illegal instruction
Summary: Valgrind memcheck on marvell-cn10xxx: illegal instruction
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: vex (other bugs)
Version First Reported In: 3.24.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-15 10:40 UTC by Bo Sun
Modified: 2025-09-08 18:46 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
the source code of example (104 bytes, text/x-c++src)
2025-04-15 10:40 UTC, Bo Sun
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bo Sun 2025-04-15 10:40:11 UTC
Created attachment 180283 [details]
the source code of example

SUMMARY
Valgrind memcheck on marvell-cn10xxx: illegal instruction

STEPS TO REPRODUCE
1. compile the example the parameters below: 
-mcpu=neoverse-n2 -mbranch-protection=standard -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security example.cpp -o example
2. valgrind --tool=memcheck ./example

OBSERVED RESULT
==1223== Memcheck, a memory error detector
==1223== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==1223== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==1223== Command: ./example
==1223== 
ARM64 front end: branch_etc
disInstr(arm64): unhandled instruction 0xD65F0BFF
disInstr(arm64): 1101'0110 0101'1111 0000'1011 1111'1111
==1223== valgrind: Unrecognised instruction at address 0x4014be8.
==1223==    at 0x4014BE8: _dl_sysdep_parse_arguments (dl-sysdep.c:97)
==1223==    by 0x4014D1B: _dl_sysdep_start (dl-sysdep.c:107)
==1223==    by 0x40162BF: _dl_start_final (rtld.c:496)
==1223==    by 0x40162BF: _dl_start (rtld.c:581)
==1223==    by 0x401A193: (below main) (dl-start.S:32)
==1223== Your program just tried to execute an instruction that Valgrind
==1223== did not recognise.  There are two possible reasons for this.
==1223== 1. Your program has a bug and erroneously jumped to a non-code
==1223==    location.  If you are running Memcheck and you just saw a
==1223==    warning about a bad jump, it's probably your program's fault.
==1223== 2. The instruction is legitimate but Valgrind doesn't handle it,
==1223==    i.e. it's Valgrind's fault.  If you think this is the case or
==1223==    you are not sure, please let us know and we'll try to fix it.
==1223== Either way, Valgrind will now raise a SIGILL signal which will
==1223== probably kill your program.
==1223== 
==1223== Process terminating with default action of signal 4 (SIGILL): dumping core
==1223==  Illegal opcode at address 0x4014BE8
==1223==    at 0x4014BE8: _dl_sysdep_parse_arguments (dl-sysdep.c:97)
==1223==    by 0x4014D1B: _dl_sysdep_start (dl-sysdep.c:107)
==1223==    by 0x40162BF: _dl_start_final (rtld.c:496)
==1223==    by 0x40162BF: _dl_start (rtld.c:581)
==1223==    by 0x401A193: (below main) (dl-start.S:32)
==1223== 
==1223== HEAP SUMMARY:
==1223==     in use at exit: 0 bytes in 0 blocks
==1223==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==1223== 
==1223== All heap blocks were freed -- no leaks are possible
==1223== 
==1223== For lists of detected and suppressed errors, rerun with: -s
==1223== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction (core dumped)


EXPECTED RESULT
==902567== Memcheck, a memory error detector
==902567== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==902567== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==902567== Command: ./example
==902567== 
Hello
==902567== 
==902567== HEAP SUMMARY:
==902567==     in use at exit: 0 bytes in 0 blocks
==902567==   total heap usage: 2 allocs, 2 frees, 73,728 bytes allocated
==902567== 
==902567== All heap blocks were freed -- no leaks are possible
==902567== 
==902567== For lists of detected and suppressed errors, rerun with: -s
==902567== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


SOFTWARE/OS VERSIONS
Linux:
Linux marvell-cn10xxx 6.6.85-yocto-standard+ #1 SMP PREEMPT Tue Apr 15 17:44:38 CST 2025 aarch64 GNU/Linux

ADDITIONAL INFORMATION
~# lscpu
Architecture:             aarch64
  CPU op-mode(s):         32-bit, 64-bit
  Byte Order:             Little Endian
CPU(s):                   24
  On-line CPU(s) list:    0-23
Vendor ID:                ARM
  Model name:             Neoverse-N2
    Model:                0
    Thread(s) per core:   1
    Core(s) per cluster:  24
    Socket(s):            -
    Cluster(s):           1
    Stepping:             r0p0
    CPU(s) scaling MHz:   100%
    CPU max MHz:          2100.0000
    CPU min MHz:          500.0000
    BogoMIPS:             2000.00
    Flags:                fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit 
                          uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
Comment 1 Paul Floyd 2025-04-15 13:35:23 UTC
Does it work the the minimal options to compile and link the exe?

It looks like the problem is in ld.so. Otherwise I doubt that we support neoverse-n2.
Comment 2 Bo Sun 2025-04-16 05:47:17 UTC
(In reply to Paul Floyd from comment #1)
> Does it work the the minimal options to compile and link the exe?
> 
> It looks like the problem is in ld.so. Otherwise I doubt that we support
> neoverse-n2.

I tried the following options, but I encountered the same issues:
1. --sysroot=/PATH/TO/sysroots
2. -mcpu=neoverse-n2 --sysroot=/PATH/TO/sysroots

Regarding your question about Neoverse N2, can you confirm if Valgrind supports it?
I found on the official site that "ARM64/Linux: supported for ARMv8." However, I'm unsure about ARMv9 (Neoverse N2).
Comment 3 Mark Wielaard 2025-04-16 12:18:38 UTC
(In reply to Bo from comment #2)
> Regarding your question about Neoverse N2, can you confirm if Valgrind
> supports it?
> I found on the official site that "ARM64/Linux: > (In reply to Paul Floyd from comment #1)
> > Does it work the the minimal options to compile and link the exe?
> > 
> > It looks like the problem is in ld.so. Otherwise I doubt that we support
> > neoverse-n2.
> 
> I tried the following options, but I encountered the same issues:
> 1. --sysroot=/PATH/TO/sysroots
> 2. -mcpu=neoverse-n2 --sysroot=/PATH/TO/sysroots
> supported for ARMv8."
> However, I'm unsure about ARMv9 (Neoverse N2).

No, valgrind doesn't support ARMv9. It supports ARMv8.1 (and some 8.2 and 8.3) instructions.
You should figure out what the actual instruction is that needs support:

disInstr(arm64): unhandled instruction 0xD65F0BFF
disInstr(arm64): 1101'0110 0101'1111 0000'1011 1111'1111
==1223== valgrind: Unrecognised instruction at address 0x4014be8.
==1223==    at 0x4014BE8: _dl_sysdep_parse_arguments (dl-sysdep.c:97)

Probably easiest to disassemble ld.so and look what the instruction is at that address/line.

Also please try dropping -mcpu=neoverse-n2 from your glibc/ld.so build and see if that works.
Comment 4 Bo Sun 2025-04-18 09:52:27 UTC
(In reply to Mark Wielaard from comment #3)
> (In reply to Bo from comment #2)
> > Regarding your question about Neoverse N2, can you confirm if Valgrind
> > supports it?
> > I found on the official site that "ARM64/Linux: > (In reply to Paul Floyd from comment #1)
> > > Does it work the the minimal options to compile and link the exe?
> > > 
> > > It looks like the problem is in ld.so. Otherwise I doubt that we support
> > > neoverse-n2.
> > 
> > I tried the following options, but I encountered the same issues:
> > 1. --sysroot=/PATH/TO/sysroots
> > 2. -mcpu=neoverse-n2 --sysroot=/PATH/TO/sysroots
> > supported for ARMv8."
> > However, I'm unsure about ARMv9 (Neoverse N2).
> 
> No, valgrind doesn't support ARMv9. It supports ARMv8.1 (and some 8.2 and
> 8.3) instructions.
> You should figure out what the actual instruction is that needs support:
> 
> disInstr(arm64): unhandled instruction 0xD65F0BFF
> disInstr(arm64): 1101'0110 0101'1111 0000'1011 1111'1111
> ==1223== valgrind: Unrecognised instruction at address 0x4014be8.
> ==1223==    at 0x4014BE8: _dl_sysdep_parse_arguments (dl-sysdep.c:97)
> 
> Probably easiest to disassemble ld.so and look what the instruction is at
> that address/line.
> 
> Also please try dropping -mcpu=neoverse-n2 from your glibc/ld.so build and
> see if that works.

Thanks for the reply.
I believe I found the reason: the instruction causing the issue is "retaa", which is an instruction introduced in ARMv8.3-A.