Bug 411100 - Valgrind does not provide a solution in the error message when an mmap error is detected.
Summary: Valgrind does not provide a solution in the error message when an mmap error ...
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (other bugs)
Version First Reported In: unspecified
Platform: Compiled Sources Linux
: NOR minor
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-20 13:31 UTC by João M. S. Silva
Modified: 2019-12-30 20:56 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Program with large BSS. (93 bytes, text/x-csrc)
2019-08-20 13:31 UTC, João M. S. Silva
Details

Note You need to log in before you can comment on or make changes to this bug.
Description João M. S. Silva 2019-08-20 13:31:54 UTC
Created attachment 122258 [details]
Program with large BSS.

VERSION

Valgrind-3.16.0.GIT

SUMMARY

I get this error message:

valgrind: mmap(0x602000, 2147483648) failed in UME with error 22 (Invalid argument).
valgrind: this can be caused by executables with very large text, data or bss segments.

Valgrind could indicate a solution to this problem by suggesting the following linker option:

-Wl,-Ttext-segment=0x68000000

STEPS TO REPRODUCE
1. gcc -o large large.c
2. valgrind ./large
3. gcc -Wl,-Ttext-segment=0x68000000 -o large large.c
4. valgrind ./large

OBSERVED RESULT

valgrind: mmap(0x602000, 2147483648) failed in UME with error 22 (Invalid argument).
valgrind: this can be caused by executables with very large text, data or bss segments.

EXPECTED RESULT

A message suggesting usage of the above mentioned linker option.

SOFTWARE/OS VERSIONS
Linux: CentOS Linux release 7.5.1804 (Core)

ADDITIONAL INFORMATION

This has been discussed in threads:

https://sourceforge.net/p/valgrind/mailman/message/36140514/
https://sourceforge.net/p/valgrind/mailman/message/36744406/
Comment 1 Julian Seward 2019-12-30 10:51:00 UTC
Hmm, maybe it's time to change the tool load address .. again.
Comment 2 João M. S. Silva 2019-12-30 10:57:59 UTC
I found out that I could solve a similar issue with Address Sanitizer by building with -fPIE, -pie and -shared, iirc.
Comment 3 Julian Seward 2019-12-30 11:07:04 UTC
I just made a patch which changes the error message to this:

valgrind: mmap(0x405000, 2147483648) failed in UME with error 22 (Invalid argument).
valgrind: This can be caused by executables with very large text, data or bss segments.
valgrind: You might be able to work around this by changing the default load address on your executable.
valgrind: You can do that by adding the following flag to your gcc/g++ link command:
valgrind:   -Wl,-Ttext-segment=0x68000000

Maybe I should add text about PIE, etc, as an alternative solution?  Can you
suggest some suitable text?
Comment 4 Julian Seward 2019-12-30 11:14:05 UTC
I'm thinking of the following, but I don't know the *exact* details of
what to suggest to build a PIE.  Can you fill those in?

mmap(0x405000, 2147483648) failed in UME with error 22 (Invalid argument).

This can be caused by executables with very large text, data or bss segments.
The underlying problem is that some part of your executable wants to be loaded
at an address which conflicts with where Valgrind's tool executable wants to
be loaded.  There are two possible ways you could try to work around this:

* by changing the default load address on your executable.  You can do that by
  adding the following flag to your gcc/g++ link command:
     -Wl,-Ttext-segment=0x68000000

* by making your executable be position-independent, so it can be loaded
  anywhere.  You can do that by [FILL THIS BIT IN]
Comment 5 João M. S. Silva 2019-12-30 20:56:37 UTC
I'm not sure it also solves it for Valgrind because Valgrind had an additional issue with Ada elaboration / stack unwinding or so (don't understand enough about it) that I could never solve.

Anyway, it could be:

* by making your executable be position-independent, so it can be loaded
  anywhere.  You can do that by compiling with switch -fPIE and linking with switch -pie.

You should also pass -shared to the binder, but I believe this is only applicable to Ada code?