Path: blob/main/contrib/llvm-project/clang/lib/Driver/ToolChains/InterfaceStubs.cpp
35294 views
//===--- InterfaceStubs.cpp - Base InterfaceStubs Implementations C++ ---===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "InterfaceStubs.h"9#include "CommonArgs.h"10#include "clang/Driver/Compilation.h"11#include "llvm/Support/Path.h"1213namespace clang {14namespace driver {15namespace tools {16namespace ifstool {17void Merger::ConstructJob(Compilation &C, const JobAction &JA,18const InputInfo &Output, const InputInfoList &Inputs,19const llvm::opt::ArgList &Args,20const char *LinkingOutput) const {21std::string Merger = getToolChain().GetProgramPath(getShortName());22// TODO: Use IFS library directly in the future.23llvm::opt::ArgStringList CmdArgs;24CmdArgs.push_back("--input-format=IFS");25const bool WriteBin = !Args.getLastArg(options::OPT_emit_merged_ifs);26CmdArgs.push_back(WriteBin ? "--output-format=ELF" : "--output-format=IFS");27CmdArgs.push_back("-o");2829// Normally we want to write to a side-car file ending in ".ifso" so for30// example if `clang -emit-interface-stubs -shared -o libhello.so` were31// invoked then we would like to get libhello.so and libhello.ifso. If the32// stdout stream is given as the output file (ie `-o -`), that is the one33// exception where we will just append to the same filestream as the normal34// output.35SmallString<128> OutputFilename(Output.getFilename());36if (OutputFilename != "-") {37if (Args.hasArg(options::OPT_shared))38llvm::sys::path::replace_extension(OutputFilename,39(WriteBin ? "ifso" : "ifs"));40else41OutputFilename += (WriteBin ? ".ifso" : ".ifs");42}4344CmdArgs.push_back(Args.MakeArgString(OutputFilename.c_str()));4546// Here we append the input files. If the input files are object files, then47// we look for .ifs files present in the same location as the object files.48for (const auto &Input : Inputs) {49if (!Input.isFilename())50continue;51SmallString<128> InputFilename(Input.getFilename());52if (Input.getType() == types::TY_Object)53llvm::sys::path::replace_extension(InputFilename, ".ifs");54CmdArgs.push_back(Args.MakeArgString(InputFilename.c_str()));55}5657C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),58Args.MakeArgString(Merger), CmdArgs,59Inputs, Output));60}61} // namespace ifstool62} // namespace tools63} // namespace driver64} // namespace clang656667