Bug 384727 - [PATCH]valgrind does not support debug info for read only segments (generated by LLD)
Summary: [PATCH]valgrind does not support debug info for read only segments (generated...
Status: RESOLVED DUPLICATE of bug 395682
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.14 SVN
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Ivo Raisr
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-15 04:25 UTC by Orivej Desh
Modified: 2018-07-15 11:13 UTC (History)
5 users (show)

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


Attachments
valgrind patch (17.01 KB, patch)
2018-07-04 14:29 UTC, Lubos Lunak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Orivej Desh 2017-09-15 04:25:04 UTC
By default (without --no-rosegment option) LLD [1] puts read only code in read only segments (and provides debug info for it). However, valgrind fails to parse ELF files that contain debug info for read only segments.

Here is an incomplete attempt to fix this: [2]
It parses read only segments, but then fails to match them with read only sections at [3]

[1] http://lld.llvm.org/
[2] https://github.com/orivej/valgrind/commits/lld
[3] https://github.com/orivej/valgrind/blob/c59bf5c215f85fb08605708b51f88777227885ae/coregrind/m_debuginfo/readelf.c#L2121
Comment 1 Rui Ueyama 2017-10-26 17:47:37 UTC
We independently found the same issue: https://bugs.llvm.org/show_bug.cgi?id=35032

This is not particularly specific to lld. It is reproducible by passing --rosegment to gold.
Comment 2 Lubos Lunak 2018-07-04 14:29:21 UTC
Created attachment 113765 [details]
valgrind patch

I think this patch completes the fix (i.e. it's meant to be added on top of the above-mentioned https://github.com/orivej/valgrind/commit/c59bf5c215f85fb08605708b51f88777227885ae.patch ).

With these two patches, valgrind works for me fine with lld-generated binaries (and my testcase is LibreOffice, so if it works there, it must work for everything else too :) ).

The only place I'm somewhat unsure of is the "FIND(rodata, rw)", i.e. the last snippet, but I assume that doesn't actually matter. As noted in "JRS 2013-Jun-01" a couple of lines above, all the code related to the second argument to FIND(), variables like rx_dsvma_limit and all that are actually unused.
Comment 3 Ivo Raisr 2018-07-12 20:05:00 UTC
Please could you try one of the patches from bug https://bugs.kde.org/show_bug.cgi?id=395682
These two bugs seem to be very similar.
Comment 4 Julian Seward 2018-07-13 09:10:20 UTC
(In reply to Ivo Raisr from comment #3)
> Please could you try one of the patches from bug
> https://bugs.kde.org/show_bug.cgi?id=395682
> These two bugs seem to be very similar.

That seems to help, yes.  On aarch64-linux, with a big C++ executable
(SpiderMonkey) compiled by clang-6.0.0 and ld.lld, it makes the difference
between no debuginfo at all and, as far as I can see, everything working
normally.
Comment 5 Lubos Lunak 2018-07-14 16:33:41 UTC
(In reply to Ivo Raisr from comment #3)
> Please could you try one of the patches from bug
> https://bugs.kde.org/show_bug.cgi?id=395682
> These two bugs seem to be very similar.

Yes, the patch from bug #395682 seems to work for me too (again tested with LibreOffice debug build with with clang6 and lld6). The bugreports look like duplicates to me and that patch seems better than mine (no idea why I got confused into thinking that .rodata could be encountered twice in one binary).
Comment 6 Ivo Raisr 2018-07-15 11:13:37 UTC

*** This bug has been marked as a duplicate of bug 395682 ***