summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPuyan Lotfi <puyan@puyan.org>2019-08-22 23:29:22 +0000
committerPuyan Lotfi <puyan@puyan.org>2019-08-22 23:29:22 +0000
commitf9ea87c3e3ab0d6772b1c16a0f5734dc29791724 (patch)
tree98c515dfe7cd73d01817ca80b1becf4139339240
parent3d90e05c7752c154106656286bd021d5918490a4 (diff)
downloadclang-f9ea87c3e3ab0d6772b1c16a0f5734dc29791724.tar.gz
[clang][ifs] New interface stubs format (llvm triple based).
After posting llvm-ifs on phabricator, I made some progress in hardening up how I think the format for Interface Stubs should look. There are a number of things I think the TBE format was missing (no endianness, no info about the Object Format because it assumes ELF), so I have added those and broken off from being as similar to the TBE schema. In a subsequent commit I can drop the other formats. An example of how The format will look is as follows: --- !experimental-ifs-v1 IfsVersion: 1.0 Triple: x86_64-unknown-linux-gnu ObjectFileFormat: ELF Symbols: _Z9nothiddenv: { Type: Func } _Z10cmdVisiblev: { Type: Func } ... The format is still marked experimental. Differential Revision: https://reviews.llvm.org/D66446 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369715 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Frontend/FrontendActions.h6
-rw-r--r--include/clang/Frontend/FrontendOptions.h1
-rw-r--r--lib/Driver/ToolChains/Clang.cpp2
-rw-r--r--lib/Frontend/CompilerInvocation.cpp4
-rw-r--r--lib/Frontend/InterfaceStubFunctionsConsumer.cpp53
-rw-r--r--lib/FrontendTool/ExecuteCompilerInvocation.cpp2
6 files changed, 68 insertions, 0 deletions
diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h
index 6c7bc6046f..911d820520 100644
--- a/include/clang/Frontend/FrontendActions.h
+++ b/include/clang/Frontend/FrontendActions.h
@@ -139,6 +139,12 @@ protected:
StringRef InFile) override;
};
+class GenerateInterfaceIfsExpV1Action : public GenerateInterfaceStubAction {
+protected:
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override;
+};
+
class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
private:
bool BeginSourceFileAction(CompilerInstance &CI) override;
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
index d9d961ccbb..adee47342a 100644
--- a/include/clang/Frontend/FrontendOptions.h
+++ b/include/clang/Frontend/FrontendOptions.h
@@ -92,6 +92,7 @@ enum ActionKind {
/// Generate Interface Stub Files.
GenerateInterfaceYAMLExpV1,
GenerateInterfaceTBEExpV1,
+ GenerateInterfaceIfsExpV1,
/// Only execute frontend initialization.
InitOnly,
diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp
index 690d4fa3fa..7e420da94f 100644
--- a/lib/Driver/ToolChains/Clang.cpp
+++ b/lib/Driver/ToolChains/Clang.cpp
@@ -3638,12 +3638,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
: "")
.Case("experimental-yaml-elf-v1", "experimental-yaml-elf-v1")
.Case("experimental-tapi-elf-v1", "experimental-tapi-elf-v1")
+ .Case("experimental-ifs-v1", "experimental-ifs-v1")
.Default("");
if (StubFormat.empty())
D.Diag(diag::err_drv_invalid_value)
<< "Must specify a valid interface stub format type using "
<< "-interface-stub-version=<experimental-tapi-elf-v1 | "
+ "experimental-ifs-v1 | "
"experimental-yaml-elf-v1>";
CmdArgs.push_back("-emit-interface-stubs");
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 66684e5c96..c0539cda11 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1737,11 +1737,14 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
frontend::GenerateInterfaceYAMLExpV1)
.Case("experimental-tapi-elf-v1",
frontend::GenerateInterfaceTBEExpV1)
+ .Case("experimental-ifs-v1",
+ frontend::GenerateInterfaceIfsExpV1)
.Default(llvm::None);
if (!ProgramAction)
Diags.Report(diag::err_drv_invalid_value)
<< "Must specify a valid interface stub format type using "
<< "-interface-stub-version=<experimental-tapi-elf-v1 | "
+ "experimental-ifs-v1 | "
"experimental-yaml-elf-v1>";
Opts.ProgramAction = *ProgramAction;
break;
@@ -3185,6 +3188,7 @@ static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
case frontend::GeneratePCH:
case frontend::GenerateInterfaceYAMLExpV1:
case frontend::GenerateInterfaceTBEExpV1:
+ case frontend::GenerateInterfaceIfsExpV1:
case frontend::ParseSyntaxOnly:
case frontend::ModuleFileInfo:
case frontend::VerifyPCH:
diff --git a/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index 970f8853a0..cb597c4709 100644
--- a/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -354,9 +354,55 @@ public:
OS.flush();
};
+ auto writeIfsV1 =
+ [this](const llvm::Triple &T, const MangledSymbols &Symbols,
+ const ASTContext &context, StringRef Format,
+ raw_ostream &OS) -> void {
+ OS << "--- !" << Format << "\n";
+ OS << "IfsVersion: 1.0\n";
+ OS << "Triple: " << T.str() << "\n";
+ OS << "ObjectFileFormat: " << "ELF" << "\n"; // TODO: For now, just ELF.
+ OS << "Symbols:\n";
+ for (const auto &E : Symbols) {
+ const MangledSymbol &Symbol = E.second;
+ for (auto Name : Symbol.Names) {
+ OS << " "
+ << (Symbol.ParentName.empty() || Instance.getLangOpts().CPlusPlus
+ ? ""
+ : (Symbol.ParentName + "."))
+ << Name << ": { Type: ";
+ switch (Symbol.Type) {
+ default:
+ llvm_unreachable(
+ "clang -emit-iterface-stubs: Unexpected symbol type.");
+ case llvm::ELF::STT_NOTYPE:
+ OS << "NoType";
+ break;
+ case llvm::ELF::STT_OBJECT: {
+ auto VD = cast<ValueDecl>(E.first)->getType();
+ OS << "Object, Size: "
+ << context.getTypeSizeInChars(VD).getQuantity();
+ break;
+ }
+ case llvm::ELF::STT_FUNC:
+ OS << "Func";
+ break;
+ }
+ if (Symbol.Binding == llvm::ELF::STB_WEAK)
+ OS << ", Weak: true";
+ OS << " }\n";
+ }
+ }
+ OS << "...\n";
+ OS.flush();
+ };
+
if (Format == "experimental-yaml-elf-v1")
writeIfoYaml(Instance.getTarget().getTriple(), Symbols, context, Format,
*OS);
+ else if (Format == "experimental-ifs-v1")
+ writeIfsV1(Instance.getTarget().getTriple(), Symbols, context, Format,
+ *OS);
else
writeIfoElfAbiYaml(Instance.getTarget().getTriple(), Symbols, context,
Format, *OS);
@@ -376,3 +422,10 @@ GenerateInterfaceTBEExpV1Action::CreateASTConsumer(CompilerInstance &CI,
return std::make_unique<InterfaceStubFunctionsConsumer>(
CI, InFile, "experimental-tapi-elf-v1");
}
+
+std::unique_ptr<ASTConsumer>
+GenerateInterfaceIfsExpV1Action::CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) {
+ return std::make_unique<InterfaceStubFunctionsConsumer>(
+ CI, InFile, "experimental-ifs-v1");
+}
diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 9cbfe70c70..f966750161 100644
--- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -68,6 +68,8 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
return std::make_unique<GenerateInterfaceYAMLExpV1Action>();
case GenerateInterfaceTBEExpV1:
return std::make_unique<GenerateInterfaceTBEExpV1Action>();
+ case GenerateInterfaceIfsExpV1:
+ return std::make_unique<GenerateInterfaceIfsExpV1Action>();
case InitOnly: return std::make_unique<InitOnlyAction>();
case ParseSyntaxOnly: return std::make_unique<SyntaxOnlyAction>();
case ModuleFileInfo: return std::make_unique<DumpModuleInfoAction>();