[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
This commit is contained in:
Nico Weber 2021-10-30 11:22:55 -04:00
parent 9f8ffaaa0b
commit f964ca896f
8 changed files with 45 additions and 2 deletions

View File

@ -124,6 +124,7 @@ struct Configuration {
std::vector<std::string> natvisFiles;
llvm::StringMap<std::string> namedStreams;
llvm::SmallString<128> pdbAltPath;
int pdbPageSize = 4096;
llvm::SmallString<128> pdbPath;
llvm::SmallString<128> pdbSourcePath;
std::vector<llvm::StringRef> argv;

View File

@ -1428,6 +1428,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
config->pdbPath = arg->getValue();
if (auto *arg = args.getLastArg(OPT_pdbaltpath))
config->pdbAltPath = arg->getValue();
if (auto *arg = args.getLastArg(OPT_pdbpagesize))
parsePDBPageSize(arg->getValue());
if (args.hasArg(OPT_natvis))
config->natvisFiles = args.getAllArgValues(OPT_natvis);
if (args.hasArg(OPT_pdbstream)) {

View File

@ -176,6 +176,7 @@ void parseSubsystem(StringRef arg, WindowsSubsystem *sys, uint32_t *major,
void parseAlternateName(StringRef);
void parseMerge(StringRef);
void parsePDBPageSize(StringRef);
void parseSection(StringRef);
void parseAligncomm(StringRef);

View File

@ -175,6 +175,26 @@ void parseMerge(StringRef s) {
}
}
void parsePDBPageSize(StringRef s) {
int v;
if (s.getAsInteger(0, v)) {
error("/pdbpagesize: invalid argument: " + s);
return;
}
if (v != 4096 && v != 8192 && v != 16384 && v != 32768) {
error("/pdbpagesize: invalid argument: " + s);
return;
}
// FIXME: Remove this once other page sizes work.
if (v != 4096) {
warn("/pdbpagesize: page sizes != 4096 not yet implemented, ignoring flag");
v = 4096;
}
config->pdbPageSize = v;
}
static uint32_t parseSectionAttributes(StringRef s) {
uint32_t ret = 0;
for (char c : s.lower()) {

View File

@ -78,8 +78,9 @@ def order : P<"order", "Put functions in order">;
def out : P<"out", "Path to file to write output">;
def natvis : P<"natvis", "Path to natvis file to embed in the PDB">;
def pdb : P<"pdb", "PDB file path">;
def pdbstripped : P<"pdbstripped", "Stripped PDB file path">;
def pdbaltpath : P<"pdbaltpath", "PDB file path to embed in the image">;
def pdbpagesize : P<"pdbpagesize", "PDB page size">;
def pdbstripped : P<"pdbstripped", "Stripped PDB file path">;
def pdbstream : Joined<["/", "-", "/?", "-?"], "pdbstream:">,
MetaVarName<"<name>=<file>">,
HelpText<"Embed the contents of <file> in the PDB as named stream <name>">;

View File

@ -1588,7 +1588,7 @@ void lld::coff::createPDB(COFFLinkerContext &ctx,
}
void PDBLinker::initialize(llvm::codeview::DebugInfo *buildId) {
exitOnErr(builder.initialize(4096)); // 4096 is blocksize
exitOnErr(builder.initialize(config->pdbPageSize));
buildId->Signature.CVSignature = OMF::Signature::PDB70;
// Signature is set to a hash of the PDB contents when the PDB is done.

View File

@ -0,0 +1,15 @@
# RUN: yaml2obj %p/Inputs/empty.yaml -o %t.obj
# RUN: not lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:hi 2>&1 \
# RUN: | FileCheck --check-prefix=INVALID %s
# RUN: not lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:15 2>&1 \
# RUN: | FileCheck --check-prefix=INVALID %s
# INVALID: error: /pdbpagesize: invalid argument:
# RUN: lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:4096
# RUN: llvm-pdbutil pdb2yaml %t.pdb | FileCheck --check-prefix=PAGE4096 %s
# PAGE4096: BlockSize: 4096
# RUN: lld-link /entry:main %t.obj /out:%t.exe /debug /pdbpagesize:8192 2>&1 \
# RUN: | FileCheck --check-prefix=TODO %s
# TODO: warning: /pdbpagesize: page sizes != 4096 not yet implemented, ignoring flag

View File

@ -93,6 +93,9 @@ inline bool isValidBlockSize(uint32_t Size) {
case 1024:
case 2048:
case 4096:
case 8192:
case 16384:
case 32768:
return true;
}
return false;