When targetting CodeView, the goal is to store argv0 & cc1 cmd-line in the emitted .OBJ, in order to allow a reproducer from the .OBJ alone.
This patch is to simplify https://reviews.llvm.org/D80833
/// coverage pass should actually not be instrumented.
std::vector<std::string> SanitizeCoverageBlacklistFiles;
+ /// Executable and command-line used to create a given CompilerInvocation.
+ /// Most of the time this will be the full -cc1 command.
+ const char *Argv0 = nullptr;
+ ArrayRef<const char *> CommandLineArgs;
+
public:
// Define accessors/mutators for code generation options of enumeration type.
#define CODEGENOPT(Name, Bits, Default)
/// \param [out] Res - The resulting invocation.
static bool CreateFromArgs(CompilerInvocation &Res,
ArrayRef<const char *> CommandLineArgs,
- DiagnosticsEngine &Diags);
+ DiagnosticsEngine &Diags,
+ const char *Argv0 = nullptr);
/// Get the directory where the compiler headers
/// reside, relative to the compiler binary (found by the passed in
Entry.Group == frontend::IncludeDirGroup::System))
Options.MCOptions.IASSearchPaths.push_back(
Entry.IgnoreSysRoot ? Entry.Path : HSOpts.Sysroot + Entry.Path);
+ Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
+ Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
}
static Optional<GCOVOptions> getGCOVOptions(const CodeGenOptions &CodeGenOpts) {
if (CodeGenOpts.DisableGCov)
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
ArrayRef<const char *> CommandLineArgs,
- DiagnosticsEngine &Diags) {
+ DiagnosticsEngine &Diags,
+ const char *Argv0) {
bool Success = true;
// Parse the arguments.
Res.getCodeGenOpts().FineGrainedBitfieldAccesses = false;
Diags.Report(diag::warn_drv_fine_grained_bitfield_accesses_ignored);
}
+
+ // Store the command-line for using in the CodeView backend.
+ Res.getCodeGenOpts().Argv0 = Argv0;
+ Res.getCodeGenOpts().CommandLineArgs = CommandLineArgs;
+
return Success;
}
if (CC1Args)
*CC1Args = {CCArgs.begin(), CCArgs.end()};
auto CI = std::make_unique<CompilerInvocation>();
- if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags) &&
+ if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags, Args[0]) &&
!ShouldRecoverOnErorrs)
return nullptr;
return CI;
namespace tooling {
/// Returns a clang build invocation initialized from the CC1 flags.
-CompilerInvocation *newInvocation(
- DiagnosticsEngine *Diagnostics, const llvm::opt::ArgStringList &CC1Args) {
+CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
+ const llvm::opt::ArgStringList &CC1Args,
+ const char *const BinaryName) {
assert(!CC1Args.empty() && "Must at least contain the program name!");
CompilerInvocation *Invocation = new CompilerInvocation;
- CompilerInvocation::CreateFromArgs(*Invocation, CC1Args, *Diagnostics);
+ CompilerInvocation::CreateFromArgs(*Invocation, CC1Args, *Diagnostics,
+ BinaryName);
Invocation->getFrontendOpts().DisableFree = false;
Invocation->getCodeGenOpts().DisableFree = false;
return Invocation;
if (!CC1Args)
return false;
std::unique_ptr<CompilerInvocation> Invocation(
- newInvocation(&Diagnostics, *CC1Args));
+ newInvocation(&Diagnostics, *CC1Args, BinaryName));
// FIXME: remove this when all users have migrated!
for (const auto &It : MappedFileContents) {
// Inject the code as the given file name into the preprocessor options.
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
- bool Success =
- CompilerInvocation::CreateFromArgs(Clang->getInvocation(), Argv, Diags);
+ bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
+ Argv, Diags, Argv0);
if (Clang->getFrontendOpts().TimeTrace) {
llvm::timeTraceProfilerInitialize(
StringRef Tool = ArgV[1];
void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;
if (Tool == "-cc1")
- return cc1_main(makeArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);
+ return cc1_main(makeArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP);
if (Tool == "-cc1as")
return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0],
GetExecutablePathVP);
#ifndef LLVM_MC_MCTARGETOPTIONS_H
#define LLVM_MC_MCTARGETOPTIONS_H
+#include "llvm/ADT/ArrayRef.h"
#include <string>
#include <vector>
std::string AssemblyLanguage;
std::string SplitDwarfFile;
+ const char *Argv0 = nullptr;
+ ArrayRef<const char *> CommandLineArgs;
+
/// Additional paths to search for `.include` directives when using the
/// integrated assembler.
std::vector<std::string> IASSearchPaths;