Bug 488514 - Android OS (Termux) `valgrind /bin/ls` gives `Unrecognised instruction at address X`
Summary: Android OS (Termux) `valgrind /bin/ls` gives `Unrecognised instruction at add...
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: unspecified
Platform: Android Other
: NOR normal
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-15 01:55 UTC by Swudu Susuwu
Modified: 2024-06-16 03:31 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Swudu Susuwu 2024-06-15 01:55:34 UTC
SUMMARY

For almost all terminals which compile sources, valgrind has lots of uses.
But with Android OS (Termux is the closest this has to Bash/Ash), valgrind always outputs Unrecognized instruction at address X

STEPS TO REPRODUCE
```
Welcome to Termux!

Docs:       https://termux.dev/docs
~ $ valgrind /bin/ls
```

OBSERVED RESULT
```
==14222== Memcheck, a memory error detector
==14222== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==14222== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==14222== Command: /bin/ls
==14222==
ARM64 front end: load_store
disInstr(arm64): unhandled instruction 0x38BFC109
disInstr(arm64): 0011'1000 1011'1111 1100'0001 0000'1001
==14222== valgrind: Unrecognised instruction at address 0x4073170.
==14222==    at 0x4073170: __dl__Z26__libc_safe_arc4random_bufPvm (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x4078377: __dl___libc_init_main_thread_late (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x410665F: __dl__ZL29__linker_init_post_relocationR19KernelArgumentBlockR6soinfo (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x41065CB: __dl___linker_init (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x4048007: __dl__start (in /apex/com.android.runtime/bin/linker64)
==14222== Your program just tried to execute an instruction that Valgrind
==14222== did not recognise.  There are two possible reasons for this.
==14222== 1. Your program has a bug and erroneously jumped to a non-code
==14222==    location.  If you are running Memcheck and you just saw a
==14222==    warning about a bad jump, it's probably your program's fault.
==14222== 2. The instruction is legitimate but Valgrind doesn't handle it,
==14222==    i.e. it's Valgrind's fault.  If you think this is the case or
==14222==    you are not sure, please let us know and we'll try to fix it.
==14222== Either way, Valgrind will now raise a SIGILL signal which will
==14222== probably kill your program.
==14222==
==14222== Process terminating with default action of signal 4 (SIGILL)
==14222==  Illegal opcode at address 0x4073170
==14222==    at 0x4073170: __dl__Z26__libc_safe_arc4random_bufPvm (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x4078377: __dl___libc_init_main_thread_late (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x410665F: __dl__ZL29__linker_init_post_relocationR19KernelArgumentBlockR6soinfo (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x41065CB: __dl___linker_init (in /apex/com.android.runtime/bin/linker64)
==14222==    by 0x4048007: __dl__start (in /apex/com.android.runtime/bin/linker64)
==14222==
==14222== HEAP SUMMARY:
==14222==     in use at exit: 0 bytes in 0 blocks
==14222==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==14222==
==14222== All heap blocks were freed -- no leaks are possible
==14222==
==14222== For lists of detected and suppressed errors, rerun with: -s
==14222== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction
~ $
```

STEPS TO REPRODUCE
```
~ $ cat a.cxx
int main(int, const char **) {
        return 0;
}
~ $ clang++ a.cxx
~ $ ./a.out
~ $ valgrind ./a.out
```
OBSERVED RESULT
```
==8263== Memcheck, a memory error detector
==8263== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==8263== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==8263== Command: ./a.out
==8263==
ARM64 front end: load_store
disInstr(arm64): unhandled instruction 0x38BFC109
disInstr(arm64): 0011'1000 1011'1111 1100'0001 0000'1001
==8263== valgrind: Unrecognised instruction at address 0x4073170.
==8263==    at 0x4073170: __dl__Z26__libc_safe_arc4random_bufPvm (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x4078377: __dl___libc_init_main_thread_late (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x410665F: __dl__ZL29__linker_init_post_relocationR19KernelArgumentBlockR6soinfo (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x41065CB: __dl___linker_init (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x4048007: __dl__start (in /apex/com.android.runtime/bin/linker64)
==8263== Your program just tried to execute an instruction that Valgrind
==8263== did not recognise.  There are two possible reasons for this.
==8263== 1. Your program has a bug and erroneously jumped to a non-code
==8263==    location.  If you are running Memcheck and you just saw a
==8263==    warning about a bad jump, it's probably your program's fault.
==8263== 2. The instruction is legitimate but Valgrind doesn't handle it,
==8263==    i.e. it's Valgrind's fault.  If you think this is the case or
==8263==    you are not sure, please let us know and we'll try to fix it.
==8263== Either way, Valgrind will now raise a SIGILL signal which will
==8263== probably kill your program.
==8263==
==8263== Process terminating with default action of signal 4 (SIGILL)
==8263==  Illegal opcode at address 0x4073170
==8263==    at 0x4073170: __dl__Z26__libc_safe_arc4random_bufPvm (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x4078377: __dl___libc_init_main_thread_late (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x410665F: __dl__ZL29__linker_init_post_relocationR19KernelArgumentBlockR6soinfo (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x41065CB: __dl___linker_init (in /apex/com.android.runtime/bin/linker64)
==8263==    by 0x4048007: __dl__start (in /apex/com.android.runtime/bin/linker64)
==8263==
==8263== HEAP SUMMARY:
==8263==     in use at exit: 0 bytes in 0 blocks
==8263==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==8263==
==8263== All heap blocks were freed -- no leaks are possible
==8263==
==8263== For lists of detected and suppressed errors, rerun with: -s
==8263== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction
~ $
```

EXPECTED RESULT
```
==8263== Memcheck, a memory error detector
==8263== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==8263== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==8263== Command: ./a.out
==8263==
ARM64 front end: load_store
==8263== HEAP SUMMARY:
==8263==     in use at exit: 0 bytes in 0 blocks
==8263==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==8263==
==8263== All heap blocks were freed -- no leaks are possible
==8263==
==8263== For lists of detected and suppressed errors, rerun with: -s
==8263== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
~ $
```

SOFTWARE/OS VERSIONS
```~ $ termux-info
Welcome to Termux!

Docs:       https://termux.dev/docs
Donate:     https://termux.dev/donate
Community:  https://termux.dev/community

Working with packages:

 - Search:  pkg search <query>
 - Install: pkg install <package>
 - Upgrade: pkg upgrade

Subscribing to additional repositories:

 - Root:    pkg install root-repo
 - X11:     pkg install x11-repo

For fixing any repository issues,
try 'termux-change-repo' command.

Report issues at https://termux.dev/issues
~/SubStack $ vim ~/todo
~/SubStack $ termux-info
Termux Variables:
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=30205
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages.termux.dev/apt/termux-main stable main
Updatable packages:
All packages up to date
termux-tools version:
1.42.4
Android version:
14
Kernel build information:
Linux localhost 5.10.189-android13-4-00012-g1217bb583cc5-ab11174560 #1 SMP PREEMPT Mon Dec 4 18:59:42 UTC 2023 aarch64 Android
Device manufacturer:
Google
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
~/SubStack $
```

ADDITIONAL INFORMATION
https://github.com/ivosh/valgrind/issues/2
Comment 1 Swudu Susuwu 2024-06-15 02:17:08 UTC
Termux devops: "[Is _Valgrind_'s issue to fix this]" https://github.com/termux/termux-packages/issues/20534#issuecomment-2167371271
Comment 2 Paul Floyd 2024-06-15 05:44:07 UTC
This looks like

ldaprb w9, [x8]

which isn't supported (arm64 doesn't have much support of ARM 8.3)
Comment 3 Paul Floyd 2024-06-15 05:57:32 UTC
As a workaround, if you target something like ARM8.2 (-march=armv8.2 maybe) then does it work?
Comment 4 Swudu Susuwu 2024-06-15 13:08:28 UTC
(In reply to Paul Floyd from comment #3)
> As a workaround, if you target something like ARM8.2 (-march=armv8.2 maybe)
> then does it work?

```
~ $ g++ -march=armv8.2 ~/a.cxx
g++: error: unsupported argument 'armv8.2' to option '-march='
```
Comment 5 Swudu Susuwu 2024-06-15 13:16:35 UTC
```
~ $ g++ -march=armv8.2-a ~/a.cxx
~ $ ./a.out
~ $ valgrind ./a.out
==19668== Memcheck, a memory error detector
==19668== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==19668== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==19668== Command: ./a.out
==19668==
ARM64 front end: load_store
disInstr(arm64): unhandled instruction 0x38BFC109
disInstr(arm64): 0011'1000 1011'1111 1100'0001 0000'1001
==19668== valgrind: Unrecognised instruction at address 0x4073170.
==19668==    at 0x4073170: __dl__Z26__libc_safe_arc4random_bufPvm (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x4078377: __dl___libc_init_main_thread_late (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x410665F: __dl__ZL29__linker_init_post_relocationR19KernelArgumentBlockR6soinfo (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x41065CB: __dl___linker_init (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x4048007: __dl__start (in /apex/com.android.runtime/bin/linker64)
==19668== Your program just tried to execute an instruction that Valgrind
==19668== did not recognise.  There are two possible reasons for this.
==19668== 1. Your program has a bug and erroneously jumped to a non-code
==19668==    location.  If you are running Memcheck and you just saw a
==19668==    warning about a bad jump, it's probably your program's fault.
==19668== 2. The instruction is legitimate but Valgrind doesn't handle it,
==19668==    i.e. it's Valgrind's fault.  If you think this is the case or
==19668==    you are not sure, please let us know and we'll try to fix it.
==19668== Either way, Valgrind will now raise a SIGILL signal which will
==19668== probably kill your program.
==19668==
==19668== Process terminating with default action of signal 4 (SIGILL)
==19668==  Illegal opcode at address 0x4073170
==19668==    at 0x4073170: __dl__Z26__libc_safe_arc4random_bufPvm (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x4078377: __dl___libc_init_main_thread_late (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x410665F: __dl__ZL29__linker_init_post_relocationR19KernelArgumentBlockR6soinfo (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x41065CB: __dl___linker_init (in /apex/com.android.runtime/bin/linker64)
==19668==    by 0x4048007: __dl__start (in /apex/com.android.runtime/bin/linker64)
==19668==
==19668== HEAP SUMMARY:
==19668==     in use at exit: 0 bytes in 0 blocks
==19668==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==19668==
==19668== All heap blocks were freed -- no leaks are possible
==19668==
==19668== For lists of detected and suppressed errors, rerun with: -s
==19668== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Illegal instruction
~ $
```
Must figure out how to rebuild `crt1.o` (other than empty `main()`, all this should have is `_start`) to 8.2?