Package: valgrind
Version: 1:3.10.0-4
Severity: important
Tags: patch

Hi,

So after encountering #777669, I moved to another machine which uses 16K
pages. This time it got another error:

> $ valgrind -d /bin/true
> --461:1:debuglog DebugLog system started by Stage 1, level 1 logging requested
> --461:1:launcher no tool requested, defaulting to 'memcheck'
> --461:1:launcher selected platform 'mips32-linux'
> --461:1:launcher launching /usr/lib/valgrind/memcheck-mips32-linux
> --461:1:debuglog DebugLog system started by Stage 2 (main), level 1 logging 
> requested
> --461:1:main     Welcome to Valgrind version 3.10.0 debug logging
> --461:1:main     Checking current stack is plausible
> --461:1:main     Checking initial stack was noted
> --461:1:main     Starting the address space manager
> --461:1:main     Address space manager is running
> --461:1:main     Starting the dynamic memory manager
> --461:1:mallocfr newSuperblock at 0x41C0C000 (pszB 4194288)  owner 
> VALGRIND/core
> --461:1:mallocfr deferred_reclaimSuperblock at 0x41C0C000 (pszB 4194288)  
> (prev 0x0) owner VALGRIND/core
> --461:1:main     Dynamic memory manager is running
> --461:1:main     Initialise m_debuginfo
> --461:1:main     VG_(libdir) = /usr/lib/valgrind
> --461:1:main     Getting launcher's name ...
> --461:1:main     ... /usr/bin/valgrind.bin
> --461:1:main     Get hardware capabilities ...
> --461:1:mallocfr deferred_reclaimSuperblock at 0x41C0C000 (pszB 4194288)  
> (prev 0x41C0C000) owner VALGRIND/core
> --461:1:machine  hwcaps = 0x10040
> --461:1:cache    Could not autodetect cache info
> --461:1:main     ... arch = MIPS32, hwcaps = MIPS-baseline
> --461:1:main     Getting the working directory at startup
> --461:1:main     ... /home/jcowgill
> --461:1:main     Split up command line
> --461:1:main     (early_) Process Valgrind's command line options
> --461:1:main     Create initial image
> --461:1:initimg  Loading client
> valgrind: mmap(0x400000, 32768) failed in UME with error 22 (Invalid 
> argument).
> valgrind: this can be caused by executables with very large text, data or bss 
> segments.

I tracked this down to the new(ish) .MIPS.abiflags section still being
loaded at the normal 0x00400000 address instead of the higher 0x38000000
address.

> $ readelf -l /usr/lib/valgrind/memcheck-mips32-linux 
> 
> Elf file type is EXEC (Executable file)
> Entry point 0x38118950
> There are 8 program headers, starting at offset 52
> 
> Program Headers:
>   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
>   ABIFLAGS       0x000138 0x00400138 0x00400138 0x00018 0x00018 R   0x8
>   REGINFO        0x010000 0x38000000 0x38000000 0x00018 0x00018 R   0x4
>   LOAD           0x000000 0x00400000 0x00400000 0x00150 0x00150 R   0x10000
>   LOAD           0x010000 0x38000000 0x38000000 0x4b15e0 0x4b15e0 R E 0x10000
>   LOAD           0x4c1f8c 0x384c1f8c 0x384c1f8c 0x0d9b4 0x115e320 RW  0x10000
>   NOTE           0x010018 0x38000018 0x38000018 0x00024 0x00024 R   0x4
>   GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x10
>   GNU_RELRO      0x4c1f8c 0x384c1f8c 0x384c1f8c 0x02074 0x02074 R   0x1
> 
>  Section to Segment mapping:
>   Segment Sections...
>    00     .MIPS.abiflags 
>    01     .reginfo 
>    02     .MIPS.abiflags 
>    03     .reginfo .note.gnu.build-id .text .rodata .eh_frame 
>    04     .data.rel.ro .data .got .sbss .bss 
>    05     .note.gnu.build-id 
>    06     
>    07     .data.rel.ro

I've attached a patch which fixes this by disabling the mips linker
workarounds when using -Ttext-section which handles all of this.

After this valgrind works on mips!

Thanks,
James
--- a/coregrind/link_tool_exe_linux.in
+++ b/coregrind/link_tool_exe_linux.in
@@ -76,12 +76,13 @@ my $x = `cat ../config.log 2>&1 | grep h
 my $arch = substr($x, 0, index($x, "'"));
 
 my $extra_args;
-if (($arch eq 'mips') || ($arch eq 'mipsel')
-    || ($arch eq 'mipsisa32r2el')) {
-   $extra_args = "-static -Wl,--section-start=.reginfo=$ala";
-} elsif (($arch eq 'mips64') || ($arch eq 'mips64el') ||
-         ($arch eq 'mipsisa64el')) {
-   $extra_args = "-static -Wl,--section-start=.MIPS.options=$ala";
+if ($arch =~ /^mips/ && "@FLAG_T_TEXT@" eq '-Ttext') {
+   # We only need to use the special mips options when using -Ttext
+   if ($arch =~ /^mips(64|isa64)/) {
+      $extra_args = "-static -Wl,--section-start=.MIPS.options=$ala";
+   } else {
+      $extra_args = "-static -Wl,--section-start=.reginfo=$ala";
+   }
 } else {
    $extra_args = "-static -Wl,@FLAG_T_TEXT@=$ala";
 }

Reply via email to