[PATCH] D49352: [LLD] [COFF] Write the debug directory and build id to a separate section for MinGW
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 15 13:42:57 PDT 2018
mstorsjo created this revision.
mstorsjo added reviewers: ruiu, pcc.
Herald added subscribers: JDevlieghere, aprantl.
For dwarf debug info, an executable normally either contains the debug info, or it is stripped out. To reduce the storage needed (slightly) for the debug info kept separately from the released, stripped binaries, one can choose to only copy the debug data from the original executable (essentially the reverse of the strip operation), producing a file with only debug info.
When copying the debug data from an executable with GNU objcopy, the build id and debug directory need to reside in a separate section, as this will be kept while the rest of the .rdata section is removed.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D49352
Files:
COFF/Writer.cpp
test/COFF/debug-reloc.s
Index: test/COFF/debug-reloc.s
===================================================================
--- test/COFF/debug-reloc.s
+++ test/COFF/debug-reloc.s
@@ -5,7 +5,13 @@
# RUN: lld-link -lldmingw -debug:dwarf -out:%t.exe -entry:mainfunc -subsystem:console %t.obj
# RUN: llvm-readobj -sections %t.exe | FileCheck %s -check-prefix SECTIONS
# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck %s -check-prefix RELOCS
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s -check-prefix HEADERS
+# RUN: llvm-readobj -coff-debug-directory %t.exe | FileCheck %s -check-prefix DEBUG
+# SECTIONS: Number: 2
+# SECTIONS-NEXT: Name: .buildid (2E 62 75 69 6C 64 69 64)
+# SECTIONS-NEXT: VirtualSize: 0x35
+# SECTIONS-NEXT: VirtualAddress: 0x2000
# SECTIONS: Number: 3
# SECTIONS-NEXT: Name: .data (2E 64 61 74 61 00 00 00)
# SECTIONS-NEXT: VirtualSize: 0x8
@@ -22,6 +28,16 @@
# RELOCS-NEXT: }
# RELOCS-NEXT: ]
+# HEADERS: DebugRVA: 0x2000
+# HEADERS: DebugSize: 0x1C
+
+# DEBUG: DebugDirectory [
+# DEBUG: DebugEntry {
+# DEBUG: Type: CodeView (0x2)
+# DEBUG: SizeOfData: 0x19
+# DEBUG: AddressOfRawData: 0x201C
+# DEBUG: PointerToRawData: 0x61C
+
.text
.def mainfunc;
.scl 2;
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -201,6 +201,7 @@
OutputSection *TextSec;
OutputSection *RdataSec;
+ OutputSection *BuildidSec;
OutputSection *DataSec;
OutputSection *PdataSec;
OutputSection *IdataSec;
@@ -420,6 +421,10 @@
TextSec = CreateSection(".text", CODE | R | X);
CreateSection(".bss", BSS | R | W);
RdataSec = CreateSection(".rdata", DATA | R);
+ if (Config->MinGW)
+ BuildidSec = CreateSection(".buildid", DATA | R);
+ else
+ BuildidSec = nullptr;
DataSec = CreateSection(".data", DATA | R | W);
PdataSec = CreateSection(".pdata", DATA | R);
IdataSec = CreateSection(".idata", DATA | R);
@@ -504,17 +509,19 @@
if (Config->Debug) {
DebugDirectory = make<DebugDirectoryChunk>(DebugRecords);
+ OutputSection *DebugInfoSec = Config->MinGW ? BuildidSec : RdataSec;
+
// Make a CVDebugRecordChunk even when /DEBUG:CV is not specified. We
// output a PDB no matter what, and this chunk provides the only means of
// allowing a debugger to match a PDB and an executable. So we need it even
// if we're ultimately not going to write CodeView data to the PDB.
auto *CVChunk = make<CVDebugRecordChunk>();
BuildId = CVChunk;
DebugRecords.push_back(CVChunk);
- RdataSec->addChunk(DebugDirectory);
+ DebugInfoSec->addChunk(DebugDirectory);
for (Chunk *C : DebugRecords)
- RdataSec->addChunk(C);
+ DebugInfoSec->addChunk(C);
}
// Create SEH table. x86-only.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49352.155597.patch
Type: text/x-patch
Size: 2829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180715/2447ef73/attachment.bin>
More information about the llvm-commits
mailing list