https://bugs.kde.org/show_bug.cgi?id=360571

            Bug ID: 360571
           Summary: Error about the Android Runtime reading below the
                    stack pointer on ARM
           Product: valgrind
           Version: 3.11.0
          Platform: Android
                OS: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: memcheck
          Assignee: jsew...@acm.org
          Reporter: anton.kiri...@linaro.org

The Android Runtime (ART) uses reads below the stack pointer (combined with a
guard memory region) to detect stack overflow, and as a result when an
application is run in the virtual machine, Valgrind outputs a lot of warnings
such as:

==29768== Invalid read of size 4
==29768==    at 0x739AEBE0: ??? (in
/data/dalvik-cache/arm/system@framew...@boot.oat)
==29768==  Address 0xfe96fdb0 is on thread 1's stack
==29768==  8192 bytes below stack pointer
==29768==

The assembly language code that is emitted by ART at the beginning of each
method, and that causes the warning, looks like this:

sub r12, sp, #8192
ldr.w r12, [r12, #0]

The --workaround-gcc296-bugs command-line parameter is supposed to help, but it
has some problems - it forces Valgrind to ignore memory accesses that are up to
1 KB below SP, but on ARM the distance is 8 KB.

I have seen the issue with a build of the master branch of the Android Open
Source Project, but is reproducible on older versions as well (e.g. the 6.0
release).

Reproducible: Always

Steps to Reproduce:
1. Install Valgrind on the Android device as documented in the README.android
file; assume that the installation directory is /data/local/tmp/valgrind.
2. Get an APK or a DEX file; let its name be Test.dex, and let the name of the
class containing the main() method be Test as well.
3. adb push Test.dex /data/local/tmp
4. adb shell /data/local/tmp/valgrind/bin/valgrind --workaround-gcc296-bugs
dalvikvm -cp /data/local/tmp/Test.dex Test

Actual Results:  
Warnings similar to the one above are displayed.

Expected Results:  
No warnings of that type are shown.

Currently, the workaround that I have been using is manually patching the
Valgrind source code (in particular, the VG_GCC296_BUG_STACK_SLOP constant in
memcheck/mc_errors.c), but a better solution is to introduce a way to configure
that value at runtime. Furthermore, I'd like to suggest an addition to the
README.android file - mentioning that people who want to run apps in the
virtual machine with Valgrind should use the --workaround-gcc296-bugs
parameter. Finally, that argument should perhaps be renamed to something more
accurate.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to