Bug 365750

Summary: Valgrind fails on binary with .text section not in default place
Product: [Developer tools] valgrind Reporter: janisozaur+kde
Component: callgrindAssignee: Josef Weidendorfer <josef.weidendorfer>
Status: REPORTED ---    
Severity: normal CC: jseward
Priority: NOR    
Version First Reported In: 3.11.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description janisozaur+kde 2016-07-16 18:44:31 UTC
When I run my program, OpenRCT2, for which we use custom linker script[1] to move .text section around, valgrind's callgrind fails with following assertion:

valgrind: m_debuginfo/debuginfo.c:552 (check_CFSI_related_invariants): Assertion 'cfsi_fits' failed

This is a program compiled with -m32 on a 64-bit system. Similar case when compiling a 64-bit version on 64-bit system.

It works, however, when compiled with .text section set to default on my system, then mmap-ing sections in their expected place.

[1] https://github.com/OpenRCT2/OpenRCT2/blob/76cca7a/distribution/linux/ld_script_i386.xc#L54-L56
Comment 1 Julian Seward 2016-09-14 15:00:53 UTC
I suspect that happens because the linker script moves the .text section around
but it doesn't update the Dwarf related sections accordingly.  Why do you need to
do such a thing?  I'd say the best advice is "don't do that!"
Comment 2 janisozaur+kde 2016-09-14 15:16:20 UTC
I'm not very well-versed in ELF, and what you suggest is entirely possible. I can, however, debug with GDB just like you would expect, if that could be used as any kind of indicator.

Where would I read more about that?

The reason I commit such atrocities is I have to load bits of original binary into memory, which is expected at specified VMAs.