diff options
Diffstat (limited to 'clang/lib/Driver/ToolChains/InterfaceStubs.cpp')
-rw-r--r-- | clang/lib/Driver/ToolChains/InterfaceStubs.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp index 6677843b2c5..b57602cd362 100644 --- a/clang/lib/Driver/ToolChains/InterfaceStubs.cpp +++ b/clang/lib/Driver/ToolChains/InterfaceStubs.cpp @@ -9,6 +9,7 @@ #include "InterfaceStubs.h" #include "CommonArgs.h" #include "clang/Driver/Compilation.h" +#include "llvm/Support/Path.h" namespace clang { namespace driver { @@ -21,13 +22,36 @@ void Merger::ConstructJob(Compilation &C, const JobAction &JA, std::string Merger = getToolChain().GetProgramPath(getShortName()); llvm::opt::ArgStringList CmdArgs; CmdArgs.push_back("-action"); - CmdArgs.push_back(Args.getLastArg(options::OPT_emit_merged_ifs) - ? "write-ifs" - : "write-bin"); + const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs); + CmdArgs.push_back(WriteBin ? "write-bin" : "write-ifs"); CmdArgs.push_back("-o"); - CmdArgs.push_back(Output.getFilename()); - for (const auto &Input : Inputs) - CmdArgs.push_back(Input.getFilename()); + + // Normally we want to write to a side-car file ending in ".ifso" so for + // example if `clang -emit-interface-stubs -shared -o libhello.so` were + // invoked then we would like to get libhello.so and libhello.ifso. If the + // stdout stream is given as the output file (ie `-o -`), that is the one + // exception where we will just append to the same filestream as the normal + // output. + SmallString<128> OutputFilename(Output.getFilename()); + if (OutputFilename != "-") { + if (Args.hasArg(options::OPT_shared)) + llvm::sys::path::replace_extension(OutputFilename, + (WriteBin ? "ifso" : "ifs")); + else + OutputFilename += ".ifso"; + } + + CmdArgs.push_back(Args.MakeArgString(OutputFilename.c_str())); + + // Here we append the input files. If the input files are object files, then + // we look for .ifs files present in the same location as the object files. + for (const auto &Input : Inputs) { + SmallString<128> InputFilename(Input.getFilename()); + if (Input.getType() == types::TY_Object) + llvm::sys::path::replace_extension(InputFilename, ".ifs"); + CmdArgs.push_back(Args.MakeArgString(InputFilename.c_str())); + } + C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Merger), CmdArgs, Inputs)); } |