Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lld/COFF/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ struct Configuration {
bool largeAddressAware = false;
bool highEntropyVA = false;
bool appContainer = false;
bool mergeDebugDirectory = true;
bool mingw = false;
bool warnMissingOrderSymbol = true;
bool warnLocallyDefinedImported = true;
Expand Down
3 changes: 3 additions & 0 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
config->is64() &&
args.hasFlag(OPT_highentropyva, OPT_highentropyva_no, true);

// Handle /nodbgdirmerge
config->mergeDebugDirectory = args.hasArg(OPT_nodbgdirmerge);

if (!config->dynamicBase &&
(config->machine == ARMNT || isAnyArm64(config->machine)))
Err(ctx) << "/dynamicbase:no is not compatible with "
Expand Down
2 changes: 2 additions & 0 deletions lld/COFF/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def machine : P<"machine", "Specify target platform">;
def merge : P<"merge", "Combine sections">;
def mllvm : P<"mllvm", "Options to pass to LLVM">;
def nodefaultlib : P<"nodefaultlib", "Remove a default library">;
def nodbgdirmerge : F<"nodbgdirmerge">,
HelpText<"Emit the debug directory in a separate section">;
def opt : P<"opt", "Control optimizations">;
def order : P<"order", "Put functions in order">;
def out : P<"out", "Path to file to write output">;
Expand Down
10 changes: 9 additions & 1 deletion lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class Writer {
OutputSection *bssSec;
OutputSection *rdataSec;
OutputSection *buildidSec;
OutputSection *cvinfoSec;
OutputSection *dataSec;
OutputSection *pdataSec;
OutputSection *idataSec;
Expand Down Expand Up @@ -1092,6 +1093,7 @@ void Writer::createSections() {
bssSec = createSection(".bss", bss | r | w);
rdataSec = createSection(".rdata", data | r);
buildidSec = createSection(".buildid", data | r);
cvinfoSec = createSection(".cvinfo", data | r);
dataSec = createSection(".data", data | r | w);
pdataSec = createSection(".pdata", data | r);
idataSec = createSection(".idata", data | r);
Expand Down Expand Up @@ -1228,7 +1230,13 @@ void Writer::createMiscChunks() {
});

// Create Debug Information Chunks
debugInfoSec = config->mingw ? buildidSec : rdataSec;
if (config->mingw) {
debugInfoSec = buildidSec;
} else if (config->mergeDebugDirectory) {
debugInfoSec = cvinfoSec;
} else {
debugInfoSec = rdataSec;
}
if (config->buildIDHash != BuildIDHash::None || config->debug ||
config->repro || config->cetCompat || config->cetCompatStrict ||
config->cetCompatIpValidationRelaxed ||
Expand Down
28 changes: 28 additions & 0 deletions lld/test/COFF/nodbgdirmerge.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
RUN: yaml2obj %p/Inputs/pdb1.yaml -o %t1.obj
RUN: yaml2obj %p/Inputs/pdb2.yaml -o %t2.obj
RUN: rm -f %t.dll %t.pdb

## Check that it emits the debug directory in .cvinfo section when
## /nodbgdirmerge is specified
RUN: lld-link /debug /pdb:%t.pdb /pdbaltpath:test.pdb /dll /out:%t.dll \
RUN: /entry:main /nodefaultlib /nodbgdirmerge %t1.obj %t2.obj
RUN: llvm-readobj --sections %t.dll | FileCheck -check-prefix=CHECKNOTMERGED %s

CHECKNOTMERGED: Section {
CHECKNOTMERGED: Number: 3
CHECKNOTMERGED: Name: .cvinfo
CHECKNOTMERGED: Characteristics [ (0x40000040)
CHECKNOTMERGED: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
CHECKNOTMERGED: IMAGE_SCN_MEM_READ (0x40000000)
CHECKNOTMERGED: ]
CHECKNOTMERGED: }

## Check that it triggers merge on when /nodbgdirmerge is not specified
RUN: lld-link /debug /pdb:%t.pdb /pdbaltpath:test.pdb /dll /out:%t.dll \
RUN: /entry:main /nodefaultlib %t1.obj %t2.obj
RUN: llvm-readobj --sections %t.dll | FileCheck -check-prefix=CHECKMERGED %s

CHECKMERGED: Section {
CHECKMERGED: Number: 3
CHECKMERGED-NOT: Name: .cvinfo
CHECKMERGED: }