[PATCH] D54828: [LLD] [COFF] Generate a codeview build id signature for MinGW even when not creating a PDB
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 22 01:21:22 PST 2018
mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk, zturner.
Herald added a subscriber: aprantl.
GNU ld, which doesn't generate PDBs, can optionally generate a build id by passing the `--build-id` option. LLD's MinGW frontend knows about this option but ignores it, as I had incorrectly assumed that LLD already generated build IDs even in those cases.
If debug info is requested and no PDB path is set, generate a build id signature as a hash of the binary itself. This allows associating a binary to a minidump, even if debug info isn't written in PDB form by the linker.
I guess the main question is if we should add an lld specific option for this to the lld-link inteface, which we pass from the MinGW frontend when `--build-id` is received, or if we just should always generate it for the "mingw && debug && !pdb" case.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D54828
Files:
COFF/Writer.cpp
test/COFF/rsds.test
Index: test/COFF/rsds.test
===================================================================
--- test/COFF/rsds.test
+++ test/COFF/rsds.test
@@ -22,6 +22,10 @@
# RUN: lld-link /Brepro /debug /dll /out:%t.dll /entry:DllMain %t.obj
# RUN: llvm-readobj -coff-debug-directory %t.dll | FileCheck --check-prefix REPRODEBUG %s
+# RUN: rm -f %t.dll %t.pdb
+# RUN: lld-link /lldmingw /debug:dwarf /dll /out:%t.dll /entry:DllMain %t.obj
+# RUN: llvm-readobj -coff-debug-directory %t.dll | FileCheck --check-prefix MINGW %s
+
# CHECK: File: [[FILE:.*]].dll
# CHECK: DebugDirectory [
# CHECK: DebugEntry {
@@ -143,6 +147,26 @@
# REPRODEBUG: PointerToRawData: 0x0
# REPRODEBUG: }
# REPRODEBUG: ]
+
+# MINGW: File: {{.*}}.dll
+# MINGW: DebugDirectory [
+# MINGW: DebugEntry {
+# MINGW: Characteristics: 0x0
+# MINGW: TimeDateStamp:
+# MINGW: MajorVersion: 0x0
+# MINGW: MinorVersion: 0x0
+# MINGW: Type: CodeView (0x2)
+# MINGW: SizeOfData: 0x{{[^0]}}
+# MINGW: AddressOfRawData: 0x{{[^0]}}
+# MINGW: PointerToRawData: 0x{{[^0]}}
+# MINGW: PDBInfo {
+# MINGW: PDBSignature: 0x53445352
+# MINGW: PDBGUID: [[GUID:\(([A-Za-z0-9]{2} ?){16}\)]]
+# MINGW: PDBAge: 1
+# MINGW: PDBFileName:
+# MINGW: }
+# MINGW: }
+# MINGW: ]
--- !COFF
header:
Machine: IMAGE_FILE_MACHINE_I386
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -1561,8 +1561,23 @@
Buffer->getBufferSize());
uint32_t Timestamp = Config->Timestamp;
+ uint64_t Hash = 0;
+ bool GenerateBuildId =
+ Config->MinGW && Config->Debug && Config->PDBPath.empty();
+
+ if (Config->Repro || GenerateBuildId)
+ Hash = xxHash64(OutputFileData);
+
if (Config->Repro)
- Timestamp = static_cast<uint32_t>(xxHash64(OutputFileData));
+ Timestamp = static_cast<uint32_t>(Hash);
+
+ if (GenerateBuildId) {
+ BuildId->BuildId->PDB70.CVSignature = OMF::Signature::PDB70;
+ BuildId->BuildId->PDB70.Age = 1;
+ memcpy(BuildId->BuildId->PDB70.Signature, &Hash, 8);
+ // xxhash only gives us 8 bytes, so put some fixed data in the other half.
+ memcpy(&BuildId->BuildId->PDB70.Signature[8], "LLD PDB.", 8);
+ }
if (DebugDirectory)
DebugDirectory->setTimeDateStamp(Timestamp);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54828.175020.patch
Type: text/x-patch
Size: 2337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181122/f5dd0369/attachment.bin>
More information about the llvm-commits
mailing list