<div dir="ltr">Using a SectionedAddress instead of a raw address makes sense to me.<br><br>Some side notes on the bug/issue (partly as exposition for other readers of this thread):<br><br>This shows up only for objects, I think (not linked executables - because then all the executable code is in one section anyway).<br><br>This isn't unique to using function-sections. It applies to any object with more than one .text section, which is common in C++ for any inline functions. eg:<br>  inline void f1() { }<div>  void f2() { f1(); }<br>  $ clang++ x.cpp -g -c && llvm-objdump --disassemble --line-numbers x.o<br>  _Z2f2v:<div>  ; /usr/local/google/home/blaikie/dev/scratch/inl.cpp:2</div><div>  ...</div><div>  ; /usr/local/google/home/blaikie/dev/scratch/inl.cpp:1<br>  ...</div><div>  Disassembly of section .text._Z2f1v:</div><div>  _Z2f1v:</div><div>  ; /usr/local/google/home/blaikie/dev/scratch/inl.cpp:2</div><div>  ...</div><div>  ; /usr/local/google/home/blaikie/dev/scratch/inl.cpp:1</div><div>  ...<br><br>(whereas binutils objdump prints line 2 for f2 and line 1 for f1)</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 12, 2019 at 7:36 AM Alexey Lapshin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br>Folks,<br><br>     I would like to ask about <a href="https://bugs.llvm.org/show_bug.cgi?id=40703" target="_blank"><strong>Bug 40703</strong></a> <span id="m_5514894745319943098summary_container"> - <span id="m_5514894745319943098short_desc_nonedit_display">wrong line number info for obj file compiled with -ffunction-sections. The problem there is that when object file compiled, it does not have addresses assigned to sections. So it uses offsets inside section to dump instructions. When these offsets came to DwarfLineTable(to get line information) - it does not know which section it relates to. I have a fix for that bug. I believe correct fix would be to pass additional section information. But it changes interfaces and need to patch many places. I would like to ask whether these interface changes are OK. The main change is to pass not only address but corresponding Section Index also:<br><br>struct SectionedAddress {<br>  uint64_t Address;<br>  uint64_t SectionIndex;<br>};<br><br>include/llvm/DebugInfo/DIContext.h <br><span id="m_5514894745319943098summary_container"><span id="m_5514894745319943098short_desc_nonedit_display">======================================================</span></span><br>index a41ab21412d..cea7aedc26a 100644<br>--- a/llvm/include/llvm/DebugInfo/DIContext.h<br>+++ b/llvm/include/llvm/DebugInfo/DIContext.h<br>@@ -203,11 +203,11 @@ public:<br>     return true;<br>   }<br> <br>-  virtual DILineInfo getLineInfoForAddress(uint64_t Address,<br>+  virtual DILineInfo getLineInfoForAddress(object::SectionedAddress Address,<br>       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;<br>-  virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,<br>+  virtual DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address,<br>       uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;<br>-  virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,<br>+  virtual DIInliningInfo getInliningInfoForAddress(object::SectionedAddress Address,<br>       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;<br><br><br>include/llvm/DebugInfo/DWARF/DWARFDebugLine.h<br>======================================================<br>-    uint32_t lookupAddress(uint64_t Address) const;<br>+    uint32_t lookupAddress(llvm::SectionedAddress Address) const;<br> <br>-    bool lookupAddressRange(uint64_t Address, uint64_t Size,<br>+    bool lookupAddressRange(llvm::SectionedAddress Address, uint64_t Size,<br>                             std::vector<uint32_t> &Result) const;<br> <br>     bool hasFileAtIndex(uint64_t FileIndex) const;<br>@@ -238,7 +247,7 @@ public:<br> <br>     /// Fills the Result argument with the file and line information<br>     /// corresponding to Address. Returns true on success.<br>-    bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,<br>+    bool getFileLineInfoForAddress(llvm::SectionedAddress Address, const char *CompDir,<br>                                    DILineInfoSpecifier::FileLineInfoKind Kind,<br>                                    DILineInfo &Result) const;<br><br>-    uint32_t lookupAddress(uint64_t Address) const;<br>+    uint32_t lookupAddress(llvm::SectionedAddress Address) const;<br> <br>include/llvm/DebugInfo/Symbolize/Symbolize.h<br><span id="m_5514894745319943098summary_container"><span id="m_5514894745319943098short_desc_nonedit_display">======================================================<br></span></span>@@ -57,13 +57,13 @@ public:<br>   }<br> <br>   Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,<br>-                                     uint64_t ModuleOffset,<br>+                                     object::SectionedAddress ModuleOffset,<br>                                      StringRef DWPName = "");<br>   Expected<DIInliningInfo> symbolizeInlinedCode(const std::string &ModuleName,<br>-                                                uint64_t ModuleOffset,<br>+                                                object::SectionedAddress ModuleOffset,<br>                                                 StringRef DWPName = "");<br>   Expected<DIGlobal> symbolizeData(const std::string &ModuleName,<br>-                                   uint64_t ModuleOffset);<br>+                                   object::SectionedAddress  ModuleOffset);<br><br><br>include/llvm/DebugInfo/Symbolize/SymbolizableModule.h<br><span id="m_5514894745319943098summary_container"><span id="m_5514894745319943098short_desc_nonedit_display"><span id="m_5514894745319943098summary_container"><span id="m_5514894745319943098short_desc_nonedit_display">======================================================<br></span></span></span></span>@@ -24,13 +24,13 @@ class SymbolizableModule {<br> public:<br>   virtual ~SymbolizableModule() = default;<br> <br>-  virtual DILineInfo symbolizeCode(uint64_t ModuleOffset,<br>+  virtual DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,<br>                                    FunctionNameKind FNKind,<br>                                    bool UseSymbolTable) const = 0;<br>-  virtual DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,<br>+  virtual DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset,<br>                                               FunctionNameKind FNKind,<br>                                               bool UseSymbolTable) const = 0;<br>-  virtual DIGlobal symbolizeData(uint64_t ModuleOffset) const = 0;<br>+  virtual DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const = 0;<br></span></span><br>If there are no objections for such interface change I would proceed with my fix in fabricator.<br><br><br>Thank you, Alexey.<br></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div></div>