[llvm-bugs] [Bug 45277] New: llvm-objcopy generates unhelpful PE/COFF debug data for gnu-debuglink
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Mar 22 11:40:20 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45277
Bug ID: 45277
Summary: llvm-objcopy generates unhelpful PE/COFF debug data
for gnu-debuglink
Product: tools
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: llvm-objcopy/strip
Assignee: unassignedbugs at nondot.org
Reporter: vit9696 at avp.su
CC: alexander.v.shaposhnikov at gmail.com,
jake.h.ehrlich at gmail.com,
jh7370.2008 at my.bristol.ac.uk,
llvm-bugs at lists.llvm.org, rupprecht at google.com
After stripping DWARF debug information one can use --add-gnu-debuglink to link
the resulting file with the original file containing the debug information:
$ cp file.dll file.debug
$ llvm-objcopy --strip-unneeded file.dll
$ llvm-objcopy --add-gnu-debuglink=$(pwd)/file.debug file.dll
When working with PE/COFF files this functionality is unfortunately very
limited:
https://github.com/llvm/llvm-project/blob/f69eba07726a9fe084812aa224309d62c4bdd2e4/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp#L84-L90
1. Unlike ELF, which gets a section with .gnu_debuglink name, PE/COFF files get
anonymous sections like /1234. This makes it very hard to reliably locate the
section, as it does not even have a magic, just a filename and a CRC32 hash.
.gnu_debuglink is 14 bytes long, while PE/COFF has 8 bytes maximum for the
section name. However, even if we cannot use this name, any other unique value
will work just fine (e.g. .dbglink or .debug).
2. .gnu_debuglink section is not an expected way to link PE with the debug
information. In general for PE/COFF a CodeView entry in debug DataDirectory is
used in either PDB 2.0 (NB10) or PDB 7.0 (RSDS) format.
For DWARF this is not added by llvm-objcopy, but it is likely desired, as
several tools for e.g. UEFI firmware debugging rely on at least some kind of
CodeView entry to be present.
In MinGW mode LLD already generates a dummy PDB 7.0 entry:
https://github.com/llvm/llvm-project/blob/8620bb9534342176ac739e2a587e4cecf437310c/lld/COFF/Writer.cpp#L1823-L1831
For non-LLVM projects, such as EDK II GenFw utility used for building UEFI
firmware PE files from ELFs, it is common to add a PDB 2.0 (NB10) entry:
https://github.com/tianocore/edk2/blob/b219e2c/MdePkg/Include/IndustryStandard/PeImage.h#L614
Perhaps, this can be adopted in llvm-objcopy as well.
3. Tools like GenFw also embed full file path instead of just the base name,
which makes it much easier to locate the file on the host during the debugging
session.
I believe GNU objcopy for ELF also strips the path, but for convenience reasons
we can make an option to keep it. E.g.
--add-gnu-debuglink=/path/to/filename,/path/to/embedded/filename.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200322/98348d65/attachment.html>
More information about the llvm-bugs
mailing list