[lld] f964ca8 - [lld/coff] Add parsing for /pdbpagesize: flag

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 31 15:36:31 PDT 2021


Author: Nico Weber
Date: 2021-10-31T18:36:23-04:00
New Revision: f964ca896f5e2779d178148bc86b86a8ce977c6d

URL: https://github.com/llvm/llvm-project/commit/f964ca896f5e2779d178148bc86b86a8ce977c6d
DIFF: https://github.com/llvm/llvm-project/commit/f964ca896f5e2779d178148bc86b86a8ce977c6d.diff

LOG: [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

Added: 
    lld/test/COFF/pdbpagesize.test

Modified: 
    lld/COFF/Config.h
    lld/COFF/Driver.cpp
    lld/COFF/Driver.h
    lld/COFF/DriverUtils.cpp
    lld/COFF/Options.td
    lld/COFF/PDB.cpp
    llvm/include/llvm/DebugInfo/MSF/MSFCommon.h

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index feaad55da871b..3917975e165d1 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -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;

diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 0d42bb70d7c72..f1b0c5c0707d1 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -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)) {

diff  --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h
index 7c2fbe3c7d64c..77e67b282665b 100644
--- a/lld/COFF/Driver.h
+++ b/lld/COFF/Driver.h
@@ -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);
 

diff  --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index 9775e37f004fc..cac254ec6828a 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -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()) {

diff  --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index 387865faa35a0..7189088f8be6f 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -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>">;

diff  --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 00e171017f4bf..30d22dbd4bce5 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -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.

diff  --git a/lld/test/COFF/pdbpagesize.test b/lld/test/COFF/pdbpagesize.test
new file mode 100644
index 0000000000000..1f9df6510e6e5
--- /dev/null
+++ b/lld/test/COFF/pdbpagesize.test
@@ -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

diff  --git a/llvm/include/llvm/DebugInfo/MSF/MSFCommon.h b/llvm/include/llvm/DebugInfo/MSF/MSFCommon.h
index 83331b14b8af1..a922839a999d2 100644
--- a/llvm/include/llvm/DebugInfo/MSF/MSFCommon.h
+++ b/llvm/include/llvm/DebugInfo/MSF/MSFCommon.h
@@ -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;


        


More information about the llvm-commits mailing list