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

--- Comment #1 from Paul Floyd <pjfl...@wanadoo.fr> ---
First a quick overview of Valgrind startup.

Each tool has 3 parts
- the tool exe e.g. memcheck-amd64-freebsd
- core preload vgpreload_core-amd64-freebsd.so
- tool preload e.g. vgpreload_memcheck-amd64-freebsd.so

Despite those shared libraries the tool does not link with anything. Generally
the way that it 'links' with anything is to parse the debuginfo as files get
mmap'd and then redirect any interesting functions. The tool is running when
the preloads and the guest and dependent shared libraries get loaded so it can
trigger from mmap system calls to do the debuginfo parsing,

The exception to that is the tool itself. Obviously it can't trigger anything
from its own mmap to memory. Instead it uses /proc (on Solaris and Linux) and
sysctl KERN_PROC_VMMAP on FreeBSD. In order for the debuginfo parsing to be
triggered it needs to see that a "standard" ELF binary has been loaded.
Normally that means 3 ELF PT_LOAD segments for binaries built with GNU bfd-ld
(RO, RX and RW) and 4 segments for binaries built with LLVM lld (RO, RX and
2xRW). The RO is ignored so really what it is looking for is either RX+RW or
RX+2xRW. Since the Valgrind tools do not link with anything they don't have the
extra RW PT_LOAD stuff like GOT-PLT. If it doesn't see that last RW segment
there's no debuginfo reading and things start to go wrong.

>From what I see 14/15 now have some optimization that allows the RW PT_LOAD to
be marked as swap rather than mmap'd into memory. I've tried poking around, but
I can't see anything in places I consider likely (rtld, mmap, lld).  Details
below.

Here's the output for 13.2

paulf> objdump -p .in_place/memcheck-amd64-freebsd

.in_place/memcheck-amd64-freebsd:     file format elf64-x86-64-freebsd

Program Header:
    PHDR off    0x0000000000000040 vaddr 0x0000000038000040 paddr
0x0000000038000040 align 2**3
         filesz 0x0000000000000188 memsz 0x0000000000000188 flags r--
    LOAD off    0x0000000000000000 vaddr 0x0000000038000000 paddr
0x0000000038000000 align 2**12
         filesz 0x00000000000c44ac memsz 0x00000000000c44ac flags r--
    LOAD off    0x00000000000c44b0 vaddr 0x00000000380c54b0 paddr
0x00000000380c54b0 align 2**12
         filesz 0x00000000001af7cf memsz 0x00000000001af7cf flags r-x
    LOAD off    0x0000000000273c80 vaddr 0x0000000038275c80 paddr
0x0000000038275c80 align 2**12
         filesz 0x0000000000000a90 memsz 0x00000000025dd010 flags rw-
EH_FRAME off    0x0000000000093180 vaddr 0x0000000038093180 paddr
0x0000000038093180 align 2**2
         filesz 0x00000000000069fc memsz 0x00000000000069fc flags r--
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr
0x0000000000000000 align 2**0
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
    NOTE off    0x00000000000001c8 vaddr 0x00000000380001c8 paddr
0x00000000380001c8 align 2**2
         filesz 0x0000000000000030 memsz 0x0000000000000030 flags r--

And for 14.0

paulf@freebsd:~/valgrind $ objdump -p .in_place/memcheck-amd64-freebsd

.in_place/memcheck-amd64-freebsd:       file format elf64-x86-64

Program Header:
    PHDR off    0x0000000000000040 vaddr 0x0000000038000040 paddr
0x0000000038000040 align 2**3
         filesz 0x0000000000000188 memsz 0x0000000000000188 flags r--
    LOAD off    0x0000000000000000 vaddr 0x0000000038000000 paddr
0x0000000038000000 align 2**12
         filesz 0x00000000000c26fc memsz 0x00000000000c26fc flags r--
    LOAD off    0x00000000000c2700 vaddr 0x00000000380c3700 paddr
0x00000000380c3700 align 2**12
         filesz 0x00000000001acbaf memsz 0x00000000001acbaf flags r-x
    LOAD off    0x000000000026f2b0 vaddr 0x00000000382712b0 paddr
0x00000000382712b0 align 2**12
         filesz 0x0000000000000a90 memsz 0x00000000025dcfe0 flags rw-
EH_FRAME off    0x00000000000939a0 vaddr 0x00000000380939a0 paddr
0x00000000380939a0 align 2**2
         filesz 0x00000000000069ec memsz 0x00000000000069ec flags r--
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr
0x0000000000000000 align 2**64
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
    NOTE off    0x00000000000001c8 vaddr 0x00000000380001c8 paddr
0x00000000380001c8 align 2**2
         filesz 0x0000000000000030 memsz 0x0000000000000030 flags r--


On 14
procstat -v gives

  PID              START                END PRT  RES PRES REF SHD FLAG TP PATH
 4649         0x38000000         0x380c3000 r--  195 2544   2   0 CN--- vn
/home/paulf/valgrind/memcheck/memcheck-amd64-freebsd
 4649         0x380c3000         0x38271000 r-x  430 2544   2   0 CN--- vn
/home/paulf/valgrind/memcheck/memcheck-amd64-freebsd
 4649         0x38271000         0x3a84f000 rw-   10   10   1   0 ----- sw
 4649        0x838821000        0x858801000 ---    0    0   0   0 ----- gd
 4649        0x858801000        0x858821000 rw-    1    1   1   0 ---D- sw
 4649        0x85947a000        0x85947b000 r-x    1    1  25   0 ----- ph
 4649     0x7ffffffff000     0x800000000000 ---    0    0   0   0 ----- gd


This is the line that seems to be the problem:

 4649         0x38271000         0x3a84f000 rw-   10   10   1   0 ----- sw

The RW PT_LOAD is marked as swap.

The procstat -v output for 13.2 is

paulf> procstat -v 5310
  PID              START                END PRT  RES PRES REF SHD FLAG TP PATH
 5310         0x38000000         0x380c5000 r--  197 2552   3   0 CN--- vn
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd
 5310         0x380c5000         0x38275000 r-x  432 2552   3   0 CN--- vn
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd
 5310         0x38275000         0x38276000 rw-    1 2552   3   0 CN--- vn
/usr/home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd
 5310         0x38276000         0x3a853000 rw-   11   11   1   0 ----- df
 5310        0x838cd8000        0x858cb8000 ---    0    0   0   0 ----- gd
 5310        0x858cb8000        0x858cd8000 rw-    2    2   1   0 ---D- df
 5310     0x7ffffffff000     0x800000000000 r-x    1    1  88   0 ----- ph

But "none" works OK.

paulf@freebsd:~/valgrind $ procstat -v 7622
  PID              START                END PRT  RES PRES REF SHD FLAG  TP PATH
 7622         0x38000000         0x380ab000 r--  171 2168   9   1 CN--- vn
/home/paulf/valgrind/none/none-amd64-freebsd
 7622         0x380ab000         0x38218000 r-x  365    0   1   0 C---- vn
/home/paulf/valgrind/none/none-amd64-freebsd
 7622         0x38218000         0x38219000 rw-    1 2168   9   1 CN--- vn
/home/paulf/valgrind/none/none-amd64-freebsd
 7622         0x38219000         0x397dd000 rw-    1    1   1   0 ----- sw 
 7622     0x7fffdffff000     0x7ffffffdf000 ---    0    0   0   0 ----- gd 
 7622     0x7ffffffdf000     0x7ffffffff000 rw-    1    1   1   0 ---D- sw 
 7622     0x7ffffffff000     0x800000000000 r-x    1    1  26   0 ----- ph

So it looks like the rw map simply isn't loaded.

Some ktraces
  7601 valgrind NAMI  "/home/paulf/valgrind/./.in_place/memcheck-amd64-freebsd"
  7601 memcheck-amd64-free RET   execve JUSTRETURN
  7601 memcheck-amd64-free CALL 
__sysctlbyname(0x3803ec36,0x24,0x3a384518,0x3a384520,0,0)
  7601 memcheck-amd64-free SCTL  "security.bsd.unprivileged_proc_debug"
  7601 memcheck-amd64-free RET   __sysctlbyname 0
  7601 memcheck-amd64-free CALL  getpid
  7601 memcheck-amd64-free RET   getpid 7601/0x1db1
  7601 memcheck-amd64-free CALL 
__sysctl(0x3a3843d0,0x4,0x39782a70,0x3a3843c0,0,0)
  7601 memcheck-amd64-free SCTL  "kern.proc.vmmap.7601"
  7601 memcheck-amd64-free RET   __sysctl 0
  7601 memcheck-amd64-free CALL 
mmap(0x1002001000,0x400000,0x7<PROT_READ|PROT_WRITE|PROT_EXEC>,0x1012<MAP_PRIVATE|MAP_FIXED|MAP_ANON>,0xfffffffffffff
fff,0)
  7601 memcheck-amd64-free RET   mmap 68753035264/0x1002001000

and

  7597 valgrind NAMI  "/home/paulf/valgrind/./.in_place/none-amd64-freebsd"
  7597 none-amd64-freebsd RET   execve JUSTRETURN
  7597 none-amd64-freebsd CALL 
__sysctlbyname(0x3803688d,0x24,0x39312da8,0x39312db0,0,0)
  7597 none-amd64-freebsd SCTL  "security.bsd.unprivileged_proc_debug"
  7597 none-amd64-freebsd RET   __sysctlbyname 0
  7597 none-amd64-freebsd CALL  getpid
  7597 none-amd64-freebsd RET   getpid 7597/0x1dad
  7597 none-amd64-freebsd CALL 
__sysctl(0x39312c60,0x4,0x38711300,0x39312c50,0,0)
  7597 none-amd64-freebsd SCTL  "kern.proc.vmmap.7597"
  7597 none-amd64-freebsd RET   __sysctl 0
  7597 none-amd64-freebsd CALL 
mmap(0x1002001000,0x400000,0x7<PROT_READ|PROT_WRITE|PROT_EXEC>,0x1012<MAP_PRIVATE|MAP_FIXED|MAP_ANON>,0xffffffffffffff
ff,0)
  7597 none-amd64-freebsd RET   mmap 68753035264/0x1002001000

Not very interesting.

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

Reply via email to