Bug 1467952

Summary: valgrind: Mask CPUID support in HWCAP on aarch64
Product: Red Hat Developer Toolset Reporter: Mark Wielaard <mjw>
Component: valgrindAssignee: Mark Wielaard <mjw>
Status: CLOSED ERRATA QA Contact: Miloš Prchlík <mprchlik>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: DTS 7.0 RHEL 7CC: fweimer, jakub, kanderso, mbenitez, mcermak, mnewsome, mprchlik, noloader, ohudlick, qe-baseos-tools-bugs
Target Milestone: alpha   
Target Release: 7.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: devtoolset-7-valgrind-3.13.0-4 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1464085 Environment:
Last Closed: 2017-10-24 09:46:30 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1464085, 1464211    
Bug Blocks:    

Description Mark Wielaard 2017-07-05 15:21:27 UTC
+++ This bug was initially created as a clone of Bug #1464085 +++

valgrind currently does not know anything about the CPUID flag added to the HWCAP auxv entry in kernel 4.11.  It passes this flag through to applications, but it will then choke when the application uses it, like this:

ARM64 front end: branch_etc
disInstr(arm64): unhandled instruction 0xD5380000
disInstr(arm64): 1101'0101 0011'1000 0000'0000 0000'0000
==924== valgrind: Unrecognised instruction at address 0x11f548.
==924==    at 0x11F548: init_cpu_features (cpu-features.c:32)
==924==    by 0x11F548: dl_platform_init (dl-machine.h:241)
==924==    by 0x11F548: _dl_sysdep_start (dl-sysdep.c:231)
==924==    by 0x10981B: _dl_start_final (rtld.c:412)
==924==    by 0x109AAB: _dl_start (rtld.c:520)

This is from a newer glibc (not the one in Red Hat Enterprise Linux).  The crashing instruction is the mrs in the glibc startup code:

  if (hwcap & HWCAP_CPUID)
    {
      register uint64_t id = 0;
      asm volatile ("mrs %0, midr_el1" : "=r"(id));
      cpu_features->midr_el1 = id;
    }
  else
    cpu_features->midr_el1 = 0;

Perhaps valgrind should mask all the HWCAP bits it knows nothing about.

--- Additional comment from Florian Weimer on 2017-06-22 12:21:40 EDT ---

Workaround: Run with “LD_HWCAP_MASK=1”.

--- Additional comment from Mark Wielaard on 2017-06-23 06:55:45 EDT ---

The upstream bug is https://bugs.kde.org/show_bug.cgi?id=381556
arm64: Handle feature registers access on 4.11 Linux kernel or later

Fedora valgrind-3.13.0-3.fc27 contains a workaround, see bug https://bugzilla.redhat.com/show_bug.cgi?id=1464211

Comment 2 Mark Wielaard 2017-07-05 15:33:12 UTC
Note that this is nor urgent till there is a glibc update that relies on the auxv HWCAP setting on arm64. But programs on arm64 might check the HWCAP themselves and then use some instructions that valgrind doesn't support.

Easiest to see what the HWCAP is with/without valgrind is to run:

LD_SHOW_AUXV=1 valgrind -q /bin/true | grep HWCAP

Which will show the auxv twice, once for valgrind itself, then for /bin/true running under valgrind.

Comment 4 Miloš Prchlík 2017-09-02 09:45:06 UTC
Verified with build devtoolset-7-valgrind-3.13.0-4.el7.

Comment 6 errata-xmlrpc 2017-10-24 09:46:30 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:3011

Comment 7 Jeffrey Walton 2019-04-29 03:23:01 UTC
Also see https://bugzilla.redhat.com/show_bug.cgi?id=1464211 . It looks like a similar issue report filed about a month earlier.