<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<div style="color: rgb(33, 33, 33);">
<div>
<div>
<div dir="ltr"><br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<p>But, this would not completely solve the problem from <a href="https://reviews.llvm.org/D59553" target="_blank">
https://reviews.llvm.org/D59553</a> - Overlapped address ranges. Binutils approach will solve the problem if the address range specified as start_address:end_address. While resolving relocations, it would replace such a range with 1:1.<br>
</p>
</div>
</blockquote>
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div>
<div dir="ltr">>> However, It would not work if address ranges were specified as start_address:length since the</div>
<div dir="ltr">>> length is not relocated.<span style="font-family:Arial,Helvetica,sans-serif; font-size:small; color:rgb(34,34,34)"> </span></div>
</div>
</div>
</div>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div></div>
</div>
</div>
</div>
</blockquote>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div></div>
</div>
</div>
</div>
</blockquote>
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div>
<div dir="ltr">>>This case could be additionally fixed by fast scan debug_info for High_PC defined as length
</div>
<div dir="ltr">>>and changing it to 1. Something which you suggested </div>
<div dir="ltr">>>here: <a href="http://lists.llvm.org/pipermail/llvm-dev/2020-May/141599.html" target="_blank">
http://lists.llvm.org/pipermail/llvm-dev/2020-May/141599.html</a>.<br>
</div>
</div>
</div>
</div>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div></div>
</div>
</div>
</div>
</blockquote>
<div><br>
> Hmm, I don't /think/ I intended to suggest anything that would have to parse all the debug_info,
</div>
<div>> even if just to fixup high_pc. I meant that debug_rnglist for the CU at least (rnglist has fewer
</div>
<div>> problems - you can't accidentally terminate it early, but still has the "large functions in programs
</div>
<div>> that use relatively low code addresses can't just be resolved to "addend" because then [0, length)
</div>
<div>> of the large function might overlap into that code address range") could be modified by a
</div>
<div>> DWARF-aware linker to remove the unused chunks. </div>
<div><br>
</div>
<div>right. you did not. <br>
that is my suggestion to extend that idea - not only fix debug_rnglist </div>
<div>but all other occurrences of HighPC.<br>
</div>
<div><br>
</div>
<div>>The DWARF that describes a specific function </div>
<div>> using low_pc/high_pc - it may be split into a .dwo file and unreachable by the linker - so it /needs/ a
</div>
<div>> magic value for the address referenced by the low_pc to indicate that it is invalid.<br>
</div>
<div><br>
</div>
<div>for the split-dwarf: solution which updates HighPC should patch .dwo files also.<br>
</div>
<div><br>
> Which all comes back to "we probably need to pick a value that's explicitly invalid" and -2 (max - 1)
</div>
<div>> seems to be about the right thing.<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div></div>
</div>
</div>
</div>
</blockquote>
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div>
<div dir="ltr">>>So it looks like following solution could fix both problems and be relatively fast:
</div>
<div dir="ltr">>>"Resolve all relocations from debug sections into dead code to 1. Parse debug sections
</div>
<div dir="ltr">>> and replace HighPc of an address range pointing to dead code and specified as length to 1".<br>
</div>
</div>
</div>
</div>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div></div>
</div>
</div>
</div>
</blockquote>
<div><br>
> That second part seems pretty expensive compared to anything else the linker is doing with
</div>
<div>> debug info. I'd try to avoid it if at all possible.<br>
</div>
<div>Agreed with that. Though there are some concerns about -2 which could be essential or not:
<br>
<br>
I do not know real problems caused by using UINT64_MAX-1 for address ranges </div>
<div>pointing to deleted code. Moreover, while testing https://reviews.llvm.org/D59553
</div>
<div>I noticed that the tools become work better: lldb, llvm-symbolizer, gnu addr2line,
</div>
<div>gnu objdump. They report code location correctly with the patch and incorrectly
</div>
<div>without the patch.<br>
<br>
But there is a corner case: address range is specified as start_address:length. </div>
<div>After replacing start_address with -2, LowPC becomes higher than HighPC. </div>
<div>From the point of DWARF standard - this is "undefined behavior". The standard
</div>
<div>says nothing about that case. Different tools could interpret it differently.<br>
Some tools could assume that such a situation is not possible and crash if it occurs.<br>
Some could ignore it. Others could report an error and stop working.<br>
f.e. llvm-dwarfdump --verify reports error and continue to work.<br>
<br>
llvm-dwarfdump --verify :<br>
error: Invalid address range [0xfffffffffffffffe, 0x0000000000000004) <br>
<br>
So after implementing this, some tools could potentially stop working. <br>
I do not know, such tools. So, I am not sure whether that is the problem.<br>
<br>
Additionally, It is necessary to document that behavior in DWARF standard to avoid problems
</div>
<div>in the future(same as for zero length address ranges):<br>
<br>
"A bounded range entry whose beginning address offset greater than ending address offset<br>
indicates an invalid range and may be ignored. "<br>
<br>
Note, that this does not specify an additional magic value(UINT64_MAX-1). </div>
<div>Instead, it describes general situation(LowPC>HighPC).<br>
<br>
If backward compatibility is not a problem - then using LowPC>HighPC to indicate invalid
</div>
<div>address range pointing to deleted code seems to be the fastest solution(which could be
</div>
<div>implemented by resolving relocations from debug sections to deleted code to UINT64_MAX-1).
<br>
<br>
If backward compatibility is a problem - then we could use already standardized </div>
<div>"zero-length address range" to mark address ranges pointing to deleted code.
</div>
<div>That solution would require to patch address range length in the dwarf.<br>
</div>
</div>
<div class="gmail_quote"><br>
</div>
<div class="gmail_quote">Thank you, Alexey<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="color:rgb(33,33,33)">
<div>
<div></div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</body>
</html>