bool showSummary = false;
unsigned debugTypes = static_cast<unsigned>(DebugType::None);
std::vector<std::string> natvisFiles;
+ llvm::StringMap<std::string> namedStreams;
llvm::SmallString<128> pdbAltPath;
llvm::SmallString<128> pdbPath;
llvm::SmallString<128> pdbSourcePath;
config->pdbAltPath = arg->getValue();
if (args.hasArg(OPT_natvis))
config->natvisFiles = args.getAllArgValues(OPT_natvis);
+ if (args.hasArg(OPT_pdbstream)) {
+ for (const StringRef value : args.getAllArgValues(OPT_pdbstream)) {
+ const std::pair<StringRef, StringRef> nameFile = value.split("=");
+ const StringRef name = nameFile.first;
+ const std::string file = nameFile.second.str();
+ config->namedStreams[name] = file;
+ }
+ }
if (auto *arg = args.getLastArg(OPT_pdb_source_path))
config->pdbSourcePath = arg->getValue();
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 pdbstream : Joined<["/", "-", "/?", "-?"], "pdbstream:">,
+ MetaVarName<"<name>=<file>">,
+ HelpText<"Embed the contents of <file> in the PDB as named stream <name>">;
def section : P<"section", "Specify section attributes">;
def stack : P<"stack", "Size of the stack">;
def stub : P<"stub", "Specify DOS stub file">;
/// Add natvis files specified on the command line.
void addNatvisFiles();
+ /// Add named streams specified on the command line.
+ void addNamedStreams();
+
/// Link CodeView from each object file in the symbol table into the PDB.
void addObjectsToPDB();
}
}
+void PDBLinker::addNamedStreams() {
+ for (const auto &streamFile : config->namedStreams) {
+ const StringRef stream = streamFile.getKey(), file = streamFile.getValue();
+ ErrorOr<std::unique_ptr<MemoryBuffer>> dataOrErr =
+ MemoryBuffer::getFile(file);
+ if (!dataOrErr) {
+ warn("Cannot open input file: " + file);
+ continue;
+ }
+ exitOnErr(builder.addNamedStream(stream, (*dataOrErr)->getBuffer()));
+ }
+}
+
static codeview::CPUType toCodeViewMachine(COFF::MachineTypes machine) {
switch (machine) {
case COFF::IMAGE_FILE_MACHINE_AMD64:
pdb.addImportFilesToPDB(outputSections);
pdb.addSections(outputSections, sectionTable);
pdb.addNatvisFiles();
+ pdb.addNamedStreams();
ScopedTimer t2(diskCommitTimer);
codeview::GUID guid;
--- /dev/null
+Stream contents
+Line 2
+Line 3
--- /dev/null
+# RUN: yaml2obj %p/Inputs/empty.yaml > %t.obj
+
+# RUN: lld-link /entry:main %t.obj /out:%t.exe /debug /pdbstream:srcsrv=%p/Inputs/stream.txt
+# RUN: llvm-pdbutil export -stream=srcsrv -out=- %t.pdb | FileCheck %s
+
+CHECK: Stream contents
+CHECK-NEXT: Line 2
+CHECK-NEXT: Line 3