Bug 483711 - -m32 flag breaks Valgrind
Summary: -m32 flag breaks Valgrind
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.16.1
Platform: unspecified Unspecified
: NOR crash
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-15 23:33 UTC by railway_bylaws.0b
Modified: 2024-03-16 17:16 UTC (History)
2 users (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 railway_bylaws.0b 2024-03-15 23:33:30 UTC
SUMMARY

I wanted to debug 32bit compiled code on my x86-64 container (Docker) installed on my ARM64 machine, but unfortunately, after compiling with gcc and the appropriate flags (-m32, -g), I get the following error message from valgrind:

==961== Memcheck, a memory error detector
==961== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==961== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==961== Command: ./test
==961==

valgrind: m_scheduler/scheduler.c:1704 (vgPlain_scheduler): the 'impossible' happened.
valgrind: VG_(scheduler), phase 3: run_innerloop detected host state invariant failure

host stacktrace:
==961==    at 0x5803EF67: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/memcheck-x86-linux)
==961==    by 0x5803F090: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/memcheck-x86-linux)
==961==    by 0x5803F184: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/memcheck-x86-linux)
==961==    by 0x5809FEF0: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/memcheck-x86-linux)
==961==    by 0x580F5F22: ??? (in /usr/lib/x86_64-linux-gnu/valgrind/memcheck-x86-linux)

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable (lwpid 961)
==961==    at 0x40023FD: handle_preload_list (rtld.c:902)
==961==    by 0x4005541: dl_main (rtld.c:1735)
==961==    by 0x401A055: _dl_sysdep_start (dl-sysdep.c:252)
==961==    by 0x4001FEC: _dl_start_final (rtld.c:485)
==961==    by 0x4001FEC: _dl_start (rtld.c:575)
==961==    by 0x40010BA: ??? (in /lib/i386-linux-gnu/ld-2.31.so)
client stack range: [0x3F7FF000 0x3F800FFF] client SP: 0x3F7FFA20
valgrind stack range: [0x22FA6000 0x230A5FFF] top usage: 5676 of 1048576

This doesn't happen whenever I compile without the -m32 flag. I have tried to replicate the issue with both ubuntu and debian and the issue persists.
I have read the documentation to find anything pointing me to the right direction but I haven't found anything helpful, I am afraid this is a bug unfortunately.

STEPS TO REPRODUCE
(Given you are inside a Docker container)
1. Compile any .c file using gcc and the -m32 flag
2. Run valgrind

OBSERVED RESULT
the "impossible" happened

EXPECTED RESULT
Successful debugging session
Comment 1 Paul Floyd 2024-03-16 10:53:03 UTC
3.16.1 is fairly old, can you try something more recent?

Docker doesn't seem to be a good environment for running Valgrind. I've never used it but I keep hearing of problems. I don't think that Docker does a good enough job of virtualizaton. Valgrind works better either on a real OS or on full virtualization systems like VirtualBox and VMware.
Comment 2 railway_bylaws.0b 2024-03-16 15:53:17 UTC
Of course, I have just repeated the same steps with ver 3.22.0, but unfortunately the outcome remains the same, albeit a bit more detailed.


==10121== Command: ./test
==10121==

valgrind: m_scheduler/scheduler.c:1730 (vgPlain_scheduler): the 'impossible' happened.
valgrind: VG_(scheduler), phase 3: run_innerloop detected host state invariant failure

host stacktrace:
==10121==    at 0x5803B997: show_sched_status_wrk (m_libcassert.c:407)
==10121==    by 0x5803BAD0: report_and_quit (m_libcassert.c:478)
==10121==    by 0x5803BBC4: vgPlain_assert_fail (m_libcassert.c:544)
==10121==    by 0x580951C8: vgPlain_scheduler (scheduler.c:1757)
==10121==    by 0x580E615E: thread_wrapper (syswrap-linux.c:102)
==10121==    by 0x580E615E: run_a_thread_NORETURN (syswrap-linux.c:155)

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable (lwpid 10121)
==10121==    at 0x40023FD: handle_preload_list (rtld.c:902)
==10121==    by 0x4005541: dl_main (rtld.c:1735)
==10121==    by 0x401A055: _dl_sysdep_start (dl-sysdep.c:252)
==10121==    by 0x4001FEC: _dl_start_final (rtld.c:485)
==10121==    by 0x4001FEC: _dl_start (rtld.c:575)
==10121==    by 0x40010BA: ??? (in /lib/i386-linux-gnu/ld-2.31.so)
client stack range: [0x3F7FF000 0x3F800FFF] client SP: 0x3F7FFA60
valgrind stack range: [0x2326F000 0x2336EFFF] top usage: 6792 of 1048576


I know containerization poses some challenges, but I am trying to work with as little disk space as possible.
Comment 3 railway_bylaws.0b 2024-03-16 15:55:38 UTC
(In reply to railway_bylaws.0b from comment #2)
> Of course, I have just repeated the same steps with ver 3.22.0, but
> unfortunately the outcome remains the same, albeit a bit more detailed.
> 
> 
> ==10121== Command: ./test
> ==10121==
> 
> valgrind: m_scheduler/scheduler.c:1730 (vgPlain_scheduler): the 'impossible'
> happened.
> valgrind: VG_(scheduler), phase 3: run_innerloop detected host state
> invariant failure
> 
> host stacktrace:
> ==10121==    at 0x5803B997: show_sched_status_wrk (m_libcassert.c:407)
> ==10121==    by 0x5803BAD0: report_and_quit (m_libcassert.c:478)
> ==10121==    by 0x5803BBC4: vgPlain_assert_fail (m_libcassert.c:544)
> ==10121==    by 0x580951C8: vgPlain_scheduler (scheduler.c:1757)
> ==10121==    by 0x580E615E: thread_wrapper (syswrap-linux.c:102)
> ==10121==    by 0x580E615E: run_a_thread_NORETURN (syswrap-linux.c:155)
> 
> sched status:
>   running_tid=1
> 
> Thread 1: status = VgTs_Runnable (lwpid 10121)
> ==10121==    at 0x40023FD: handle_preload_list (rtld.c:902)
> ==10121==    by 0x4005541: dl_main (rtld.c:1735)
> ==10121==    by 0x401A055: _dl_sysdep_start (dl-sysdep.c:252)
> ==10121==    by 0x4001FEC: _dl_start_final (rtld.c:485)
> ==10121==    by 0x4001FEC: _dl_start (rtld.c:575)
> ==10121==    by 0x40010BA: ??? (in /lib/i386-linux-gnu/ld-2.31.so)
> client stack range: [0x3F7FF000 0x3F800FFF] client SP: 0x3F7FFA60
> valgrind stack range: [0x2326F000 0x2336EFFF] top usage: 6792 of 1048576
> 
> 
> I know containerization poses some challenges, but I am trying to work with
> as little disk space as possible.

I forgot to stress that the issue only presents itself when compiling with the -m32 flag, valgrind behaves as expected otherwise, even in a containerized environment.
Comment 4 Paul Floyd 2024-03-16 16:54:45 UTC
Can you provide an exe that reproduces the problem?

As far as I know none of the Valgrind developers use Docker, and x86 isn't actively supported, so there's not much chance of this being fixed.

It might help if you could build Valgrind from source and get a proper stacktrace from Valgrind. Many Linux packagers have decided that they know better than the Valgrind developers and they strip the Valgrind bninaries.
Comment 5 Mark Wielaard 2024-03-16 17:16:05 UTC
Various x86_64 (amd64) builders on builder.sourceware.org are docker based. I think valgrind works fine under a linux container/docker setup. But none of them run x86 (32bit).

The comments around the assert read:

      case VG_TRC_INVARIANT_FAILED:
         /* This typically happens if, after running generated code,
            it is detected that host CPU settings (eg, FPU/Vector
            control words) are not as they should be.  Vex's code
            generation specifies the state such control words should
            be in on entry to Vex-generated code, and they should be
            unchanged on exit from it.  Failure of this assertion
            usually means a bug in Vex's code generation. */
         //{ UInt xx;
         //  __asm__ __volatile__ (
         //     "\t.word 0xEEF12A10\n"  // fmrx r2,fpscr
         //     "\tmov %0, r2" : "=r"(xx) : : "r2" );
         //  VG_(printf)("QQQQ new fpscr = %08x\n", xx);
         //}
         vg_assert2(0, "VG_(scheduler), phase 3: "
                       "run_innerloop detected host "
                       "state invariant failure", trc);