Skip to content

Commit f964ca8

Browse files
committed
[lld/coff] Add parsing for /pdbpagesize: flag
It's not used for anything yet, but we now accept `/pdbpagesize:4096` (the default behavior) and we give arguably more useful diagnostics for other values. It's plumbed through to the MSF layer, so just uncommenting out the bit in DriverUtils.cpp that rejects args other than 4096 is enough to try other values. Differential Revision: https://reviews.llvm.org/D112871
1 parent 9f8ffaa commit f964ca8

File tree

8 files changed

+45
-2
lines changed

8 files changed

+45
-2
lines changed

lld/COFF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct Configuration {
124124
std::vector<std::string> natvisFiles;
125125
llvm::StringMap<std::string> namedStreams;
126126
llvm::SmallString<128> pdbAltPath;
127+
int pdbPageSize = 4096;
127128
llvm::SmallString<128> pdbPath;
128129
llvm::SmallString<128> pdbSourcePath;
129130
std::vector<llvm::StringRef> argv;

lld/COFF/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
14281428
config->pdbPath = arg->getValue();
14291429
if (auto *arg = args.getLastArg(OPT_pdbaltpath))
14301430
config->pdbAltPath = arg->getValue();
1431+
if (auto *arg = args.getLastArg(OPT_pdbpagesize))
1432+
parsePDBPageSize(arg->getValue());
14311433
if (args.hasArg(OPT_natvis))
14321434
config->natvisFiles = args.getAllArgValues(OPT_natvis);
14331435
if (args.hasArg(OPT_pdbstream)) {

lld/COFF/Driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void parseSubsystem(StringRef arg, WindowsSubsystem *sys, uint32_t *major,
176176

177177
void parseAlternateName(StringRef);
178178
void parseMerge(StringRef);
179+
void parsePDBPageSize(StringRef);
179180
void parseSection(StringRef);
180181
void parseAligncomm(StringRef);
181182

lld/COFF/DriverUtils.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ void parseMerge(StringRef s) {
175175
}
176176
}
177177

178+
void parsePDBPageSize(StringRef s) {
179+
int v;
180+
if (s.getAsInteger(0, v)) {
181+
error("/pdbpagesize: invalid argument: " + s);
182+
return;
183+
}
184+
if (v != 4096 && v != 8192 && v != 16384 && v != 32768) {
185+
error("/pdbpagesize: invalid argument: " + s);
186+
return;
187+
}
188+
189+
// FIXME: Remove this once other page sizes work.
190+
if (v != 4096) {
191+
warn("/pdbpagesize: page sizes != 4096 not yet implemented, ignoring flag");
192+
v = 4096;
193+
}
194+
195+
config->pdbPageSize = v;
196+
}
197+
178198
static uint32_t parseSectionAttributes(StringRef s) {
179199
uint32_t ret = 0;
180200
for (char c : s.lower()) {

lld/COFF/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def order : P<"order", "Put functions in order">;
7878
def out : P<"out", "Path to file to write output">;
7979
def natvis : P<"natvis", "Path to natvis file to embed in the PDB">;
8080
def pdb : P<"pdb", "PDB file path">;
81-
def pdbstripped : P<"pdbstripped", "Stripped PDB file path">;
8281
def pdbaltpath : P<"pdbaltpath", "PDB file path to embed in the image">;
82+
def pdbpagesize : P<"pdbpagesize", "PDB page size">;
83+
def pdbstripped : P<"pdbstripped", "Stripped PDB file path">;
8384
def pdbstream : Joined<["/", "-", "/?", "-?"], "pdbstream:">,
8485
MetaVarName<"<name>=<file>">,
8586
HelpText<"Embed the contents of <file> in the PDB as named stream <name>">;

lld/COFF/PDB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ void lld::coff::createPDB(COFFLinkerContext &ctx,
15881588
}
15891589

15901590
void PDBLinker::initialize(llvm::codeview::DebugInfo *buildId) {
1591-
exitOnErr(builder.initialize(4096)); // 4096 is blocksize
1591+
exitOnErr(builder.initialize(config->pdbPageSize));
15921592

15931593
buildId->Signature.CVSignature = OMF::Signature::PDB70;
15941594
// Signature is set to a hash of the PDB contents when the PDB is done.

lld/test/COFF/pdbpagesize.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# RUN: yaml2obj %p/Inputs/empty.yaml -o %t.obj
2+
3+
# RUN: not lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:hi 2>&1 \
4+
# RUN: | FileCheck --check-prefix=INVALID %s
5+
# RUN: not lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:15 2>&1 \
6+
# RUN: | FileCheck --check-prefix=INVALID %s
7+
# INVALID: error: /pdbpagesize: invalid argument:
8+
9+
# RUN: lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:4096
10+
# RUN: llvm-pdbutil pdb2yaml %t.pdb | FileCheck --check-prefix=PAGE4096 %s
11+
# PAGE4096: BlockSize: 4096
12+
13+
# RUN: lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:8192 2>&1 \
14+
# RUN: | FileCheck --check-prefix=TODO %s
15+
# TODO: warning: /pdbpagesize: page sizes != 4096 not yet implemented, ignoring flag

llvm/include/llvm/DebugInfo/MSF/MSFCommon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ inline bool isValidBlockSize(uint32_t Size) {
9393
case 1024:
9494
case 2048:
9595
case 4096:
96+
case 8192:
97+
case 16384:
98+
case 32768:
9699
return true;
97100
}
98101
return false;

0 commit comments

Comments
 (0)