Open SwuduSusuwu opened 3 months ago
~ $ valgrind /bin/ls
==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
~ $
The unrecognised instruction
messages have been an issue for many years. I am under the impression that valgrind barely supports android, and I guess newer android versions might have made the situation even worse. You might have a better time using clang's memory sanitizer
Cool, wish for best with Clang's sanitizer.
If no go, must wrap free/malloc/realloc? (Did this with a C project years ago, as a valgrind
emu (Android did not have Termux, Terminal IDE did not have valgrind
); did canaries too, to show buffler overruns/underruns):
Wraps for function calls/returns allowed to produce stackstraces, but valgrind
shows stackstraces, can use whatever already produces stackstraces? The most use was from the stackstraces.
Perhaps just use intercept SIGILL with signal()
to output stackstraces from OS?
For references: valgrind
Bugzilla issue is https://bugs.kde.org/show_bug.cgi?id=488514
Project is cross platform thus want to support g++
/ clang++
.
Searches for how to have -fsanitize
compatible across g++
/ clang++
found this: https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind
Sanitizers:
Clang/GCC option:
-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment
Copy snippet
For LLDB/GDB and to prevent very short stack traces and usually false leaks detection:
$ export ASAN_OPTIONS=abort_on_error=1:fast_unwind_on_malloc=0:detect_leaks=0 UBSAN_OPTIONS=print_stacktrace=1
Copy snippet
Fix false memory leak reporting when using [glib2](https://en.wikipedia.org/wiki/GLib):
$ export G_SLICE=always-malloc G_DEBUG=gc-friendly
Copy snippet
Clang option to catch uninitialized memory reads: -fsanitize=memory. That option cannot be combined with -fsanitize=address.
rpmbuild *.spec files should additionally use: -Wp,-U_FORTIFY_SOURCE.
-fsanitize
is success.
Would "Close with comment" except, unlike valgrind
, must recompile (requires sources) to do this.
What to do for executables? How to match valgrind /bin/ls
without recompiling ls
?
The
unrecognised instruction
messages have been an issue for many years. I am under the impression that valgrind barely supports android, and I guess newer android versions might have made the situation even worse. You might have a better time using clang's memory sanitizer
Speaking as the main Valgrind contributor these days the problem is that we don't have enough developers. IBM/RedHat contributes a fair bit (good news if you are using an s390 mainframe).
In this case it's an arm64 issue, not specific to Android. I've only recently started trying to catch up with unsupported arm64 opcodes. It's still going to take me a while to get to this.
Problem description
For almost all terminals which compile sources,
valgrind
has lots of uses. But with Termux, valgrind always outputsUnrecognized instruction at address X
What steps will reproduce the bug?
What is the expected behavior?
Without errors, executes this
System information
Can not update to Termux 0.120.0, can someone with 0.120.0 test this?