r363948 - [clang-ifs] Clang Interface Stubs, first version (second landing attempt).
Puyan Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 20 09:59:48 PDT 2019
Author: zer0
Date: Thu Jun 20 09:59:48 2019
New Revision: 363948
URL: http://llvm.org/viewvc/llvm-project?rev=363948&view=rev
Log:
[clang-ifs] Clang Interface Stubs, first version (second landing attempt).
This change reverts r363649; effectively re-landing r363626. At this point
clang::Index::CodegenNameGeneratorImpl has been refactored into
clang::AST::ASTNameGenerator. This makes it so that the previous circular link
dependency no longer exists, fixing the previous share lib
(-DBUILD_SHARED_LIBS=ON) build issue which was the reason for r363649.
Clang interface stubs (previously referred to as clang-ifsos) is a new frontend
action in clang that allows the generation of stub files that contain mangled
name info that can be used to produce a stub library. These stub libraries can
be useful for breaking up build dependencies and controlling access to a
library's internal symbols. Generation of these stubs can be invoked by:
clang -fvisibility=<visibility> -emit-interface-stubs \
-interface-stub-version=<interface format>
Notice that -fvisibility (along with use of visibility attributes) can be used
to control what symbols get generated. Currently the interface format is
experimental but there are a wide range of possibilities here.
Currently clang-ifs produces .ifs files that can be thought of as analogous to
object (.o) files, but just for the mangled symbol info. In a subsequent patch
I intend to add support for merging the .ifs files into one .ifs/.ifso file
that can be the input to something like llvm-elfabi to produce something like a
.so file or .dll (but without any of the code, just symbols).
Differential Revision: https://reviews.llvm.org/D60974
Added:
cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
cfe/trunk/test/InterfaceStubs/bad-format.cpp
cfe/trunk/test/InterfaceStubs/class-template-specialization.cpp
cfe/trunk/test/InterfaceStubs/externstatic.c
cfe/trunk/test/InterfaceStubs/function-template-specialization.cpp
cfe/trunk/test/InterfaceStubs/hidden-class-inheritance.cpp
cfe/trunk/test/InterfaceStubs/inline.c
cfe/trunk/test/InterfaceStubs/inline.h
cfe/trunk/test/InterfaceStubs/object.cpp
cfe/trunk/test/InterfaceStubs/template-namespace-function.cpp
cfe/trunk/test/InterfaceStubs/virtual.cpp
cfe/trunk/test/InterfaceStubs/visibility.cpp
cfe/trunk/test/InterfaceStubs/weak.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Driver/Types.def
cfe/trunk/include/clang/Frontend/FrontendActions.h
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CMakeLists.txt
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Thu Jun 20 09:59:48 2019
@@ -220,6 +220,8 @@ def err_module_header_file_not_found :
def err_module_header_file_invalid :
Error<"unexpected module header file input '%0'">, DefaultFatal;
+def err_interface_stubs : Error<"clang-ifs (-emit-iterface-stubs): %0">;
+
def err_test_module_file_extension_version : Error<
"test module file extension '%0' has different version (%1.%2) than expected "
"(%3.%4)">;
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Jun 20 09:59:48 2019
@@ -623,6 +623,9 @@ def emit_ast : Flag<["-"], "emit-ast">,
HelpText<"Emit Clang AST files for source inputs">;
def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option]>, Group<Action_Group>,
HelpText<"Use the LLVM representation for assembler and object files">;
+def emit_iterface_stubs : Flag<["-"], "emit-interface-stubs">, Flags<[CC1Option]>, Group<Action_Group>,
+ HelpText<"Generate Inteface Stub Files.">;
+def iterface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Flags<[CC1Option]>;
def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
def e : JoinedOrSeparate<["-"], "e">, Group<Link_Group>;
def fPIC : Flag<["-"], "fPIC">, Group<f_Group>;
Modified: cfe/trunk/include/clang/Driver/Types.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.def?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Types.def (original)
+++ cfe/trunk/include/clang/Driver/Types.def Thu Jun 20 09:59:48 2019
@@ -88,6 +88,7 @@ TYPE("lto-bc", LTO_BC,
// Misc.
TYPE("ast", AST, INVALID, "ast", "u")
+TYPE("ifs", IFS, INVALID, "ifs", "u")
TYPE("pcm", ModuleFile, INVALID, "pcm", "u")
TYPE("plist", Plist, INVALID, "plist", "")
TYPE("rewritten-objc", RewrittenObjC,INVALID, "cpp", "")
Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendActions.h?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendActions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendActions.h Thu Jun 20 09:59:48 2019
@@ -119,6 +119,26 @@ protected:
bool hasASTFileSupport() const override { return false; }
};
+class GenerateInterfaceStubAction : public ASTFrontendAction {
+protected:
+ TranslationUnitKind getTranslationUnitKind() override { return TU_Module; }
+
+ bool hasASTFileSupport() const override { return false; }
+};
+
+// Support different interface stub formats this way:
+class GenerateInterfaceYAMLExpV1Action : public GenerateInterfaceStubAction {
+protected:
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override;
+};
+
+class GenerateInterfaceTBEExpV1Action : public GenerateInterfaceStubAction {
+protected:
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override;
+};
+
class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
private:
bool BeginSourceFileAction(CompilerInstance &CI) override;
Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Thu Jun 20 09:59:48 2019
@@ -88,6 +88,10 @@ enum ActionKind {
/// Generate pre-compiled header.
GeneratePCH,
+ /// Generate Interface Stub Files.
+ GenerateInterfaceYAMLExpV1,
+ GenerateInterfaceTBEExpV1,
+
/// Only execute frontend initialization.
InitOnly,
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Jun 20 09:59:48 2019
@@ -285,6 +285,7 @@ phases::ID Driver::getFinalPhase(const D
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
(PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
+ (PhaseArg = DAL.getLastArg(options::OPT_emit_iterface_stubs)) ||
(PhaseArg = DAL.getLastArg(options::OPT__analyze,
options::OPT__analyze_auto)) ||
(PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
@@ -3472,6 +3473,8 @@ Action *Driver::ConstructPhaseAction(
return C.MakeAction<CompileJobAction>(Input, types::TY_ModuleFile);
if (Args.hasArg(options::OPT_verify_pch))
return C.MakeAction<VerifyPCHJobAction>(Input, types::TY_Nothing);
+ if (Args.hasArg(options::OPT_emit_iterface_stubs))
+ return C.MakeAction<CompileJobAction>(Input, types::TY_IFS);
return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);
}
case phases::Backend: {
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Jun 20 09:59:48 2019
@@ -3613,6 +3613,25 @@ void Clang::ConstructJob(Compilation &C,
} else if (JA.getType() == types::TY_LLVM_BC ||
JA.getType() == types::TY_LTO_BC) {
CmdArgs.push_back("-emit-llvm-bc");
+ } else if (JA.getType() == types::TY_IFS) {
+ StringRef StubFormat =
+ llvm::StringSwitch<StringRef>(
+ Args.hasArg(options::OPT_iterface_stub_version_EQ)
+ ? Args.getLastArgValue(options::OPT_iterface_stub_version_EQ)
+ : "")
+ .Case("experimental-yaml-elf-v1", "experimental-yaml-elf-v1")
+ .Case("experimental-tapi-elf-v1", "experimental-tapi-elf-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-yaml-elf-v1>";
+
+ CmdArgs.push_back("-emit-interface-stubs");
+ CmdArgs.push_back(
+ Args.MakeArgString(Twine("-interface-stub-version=") + StubFormat));
} else if (JA.getType() == types::TY_PP_Asm) {
CmdArgs.push_back("-S");
} else if (JA.getType() == types::TY_AST) {
Modified: cfe/trunk/lib/Frontend/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CMakeLists.txt?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CMakeLists.txt (original)
+++ cfe/trunk/lib/Frontend/CMakeLists.txt Thu Jun 20 09:59:48 2019
@@ -45,6 +45,7 @@ add_clang_library(clangFrontend
TextDiagnosticBuffer.cpp
TextDiagnosticPrinter.cpp
VerifyDiagnosticConsumer.cpp
+ InterfaceStubFunctionsConsumer.cpp
DEPENDS
ClangDriverOptions
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Jun 20 09:59:48 2019
@@ -1681,6 +1681,25 @@ static InputKind ParseFrontendArgs(Front
Opts.ProgramAction = frontend::GenerateHeaderModule; break;
case OPT_emit_pch:
Opts.ProgramAction = frontend::GeneratePCH; break;
+ case OPT_emit_iterface_stubs: {
+ llvm::Optional<frontend::ActionKind> ProgramAction =
+ llvm::StringSwitch<llvm::Optional<frontend::ActionKind>>(
+ Args.hasArg(OPT_iterface_stub_version_EQ)
+ ? Args.getLastArgValue(OPT_iterface_stub_version_EQ)
+ : "")
+ .Case("experimental-yaml-elf-v1",
+ frontend::GenerateInterfaceYAMLExpV1)
+ .Case("experimental-tapi-elf-v1",
+ frontend::GenerateInterfaceTBEExpV1)
+ .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-yaml-elf-v1>";
+ Opts.ProgramAction = *ProgramAction;
+ break;
+ }
case OPT_init_only:
Opts.ProgramAction = frontend::InitOnly; break;
case OPT_fsyntax_only:
@@ -3119,6 +3138,8 @@ static bool isStrictlyPreprocessorAction
case frontend::GenerateModuleInterface:
case frontend::GenerateHeaderModule:
case frontend::GeneratePCH:
+ case frontend::GenerateInterfaceYAMLExpV1:
+ case frontend::GenerateInterfaceTBEExpV1:
case frontend::ParseSyntaxOnly:
case frontend::ModuleFileInfo:
case frontend::VerifyPCH:
Added: cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp (added)
+++ cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,378 @@
+//===--- InterfaceStubFunctionsConsumer.cpp -------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/Mangle.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Sema/TemplateInstCallback.h"
+#include "llvm/BinaryFormat/ELF.h"
+
+using namespace clang;
+
+class InterfaceStubFunctionsConsumer : public ASTConsumer {
+ CompilerInstance &Instance;
+ StringRef InFile;
+ StringRef Format;
+ std::set<std::string> ParsedTemplates;
+
+ enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
+ struct MangledSymbol {
+ std::string ParentName;
+ uint8_t Type;
+ uint8_t Binding;
+ std::vector<std::string> Names;
+ MangledSymbol() = delete;
+
+ MangledSymbol(const std::string &ParentName, uint8_t Type, uint8_t Binding,
+ std::vector<std::string> Names)
+ : ParentName(ParentName), Type(Type), Binding(Binding), Names(Names) {}
+ };
+ using MangledSymbols = std::map<const NamedDecl *, MangledSymbol>;
+
+ bool WriteNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
+ // Here we filter out anything that's not set to DefaultVisibility.
+ // DefaultVisibility is set on a decl when -fvisibility is not specified on
+ // the command line (or specified as default) and the decl does not have
+ // __attribute__((visibility("hidden"))) set or when the command line
+ // argument is set to hidden but the decl explicitly has
+ // __attribute__((visibility ("default"))) set. We do this so that the user
+ // can have fine grain control of what they want to expose in the stub.
+ auto isVisible = [](const NamedDecl *ND) -> bool {
+ return ND->getVisibility() == DefaultVisibility;
+ };
+
+ auto ignoreDecl = [this, isVisible](const NamedDecl *ND) -> bool {
+ if (!isVisible(ND))
+ return true;
+
+ if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
+ if ((VD->getStorageClass() == StorageClass::SC_Extern) ||
+ (VD->getStorageClass() == StorageClass::SC_Static &&
+ VD->getParentFunctionOrMethod() == nullptr))
+ return true;
+
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
+ if (FD->isInlined() && !isa<CXXMethodDecl>(FD) &&
+ !Instance.getLangOpts().GNUInline)
+ return true;
+ if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
+ if (const auto *RC = dyn_cast<CXXRecordDecl>(MD->getParent()))
+ if (isa<ClassTemplateDecl>(RC->getParent()) || !isVisible(RC))
+ return true;
+ if (MD->isDependentContext() || !MD->hasBody())
+ return true;
+ }
+ if (FD->getStorageClass() == StorageClass::SC_Static)
+ return true;
+ }
+ return false;
+ };
+
+ auto getParentFunctionDecl = [](const NamedDecl *ND) -> const NamedDecl * {
+ if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
+ if (const auto *FD =
+ dyn_cast_or_null<FunctionDecl>(VD->getParentFunctionOrMethod()))
+ return FD;
+ return nullptr;
+ };
+
+ auto getMangledNames = [](const NamedDecl *ND) -> std::vector<std::string> {
+ if (!ND)
+ return {""};
+ ASTNameGenerator NameGen(ND->getASTContext());
+ std::vector<std::string> MangledNames = NameGen.getAllManglings(ND);
+ if (isa<CXXConstructorDecl>(ND) || isa<CXXDestructorDecl>(ND))
+ return MangledNames;
+#ifdef EXPENSIVE_CHECKS
+ assert(MangledNames.size() <= 1 && "Expected only one name mangling.");
+#endif
+ return {NameGen.getName(ND)};
+ };
+
+ if (!(RDO & FromTU))
+ return true;
+ if (Symbols.find(ND) != Symbols.end())
+ return true;
+ // - Currently have not figured out how to produce the names for FieldDecls.
+ // - Do not want to produce symbols for function paremeters.
+ if (isa<FieldDecl>(ND) || isa<ParmVarDecl>(ND))
+ return true;
+
+ const NamedDecl *ParentDecl = getParentFunctionDecl(ND);
+ if ((ParentDecl && ignoreDecl(ParentDecl)) || ignoreDecl(ND))
+ return true;
+
+ if (RDO & IsLate) {
+ Instance.getDiagnostics().Report(diag::err_asm_invalid_type_in_input)
+ << "Generating Interface Stubs is not supported with "
+ "delayed template parsing.";
+ } else {
+ if (const auto *FD = dyn_cast<FunctionDecl>(ND))
+ if (FD->isDependentContext())
+ return true;
+
+ const bool IsWeak = (ND->hasAttr<WeakAttr>() ||
+ ND->hasAttr<WeakRefAttr>() || ND->isWeakImported());
+
+ Symbols.insert(std::make_pair(
+ ND,
+ MangledSymbol(getMangledNames(ParentDecl).front(),
+ // Type:
+ isa<VarDecl>(ND) ? llvm::ELF::STT_OBJECT
+ : llvm::ELF::STT_FUNC,
+ // Binding:
+ IsWeak ? llvm::ELF::STB_WEAK : llvm::ELF::STB_GLOBAL,
+ getMangledNames(ND))));
+ }
+ return true;
+ }
+
+ void
+ HandleDecls(const llvm::iterator_range<DeclContext::decl_iterator> &Decls,
+ MangledSymbols &Symbols, int RDO) {
+ for (const auto *D : Decls)
+ HandleNamedDecl(dyn_cast<NamedDecl>(D), Symbols, RDO);
+ }
+
+ void HandleTemplateSpecializations(const FunctionTemplateDecl &FTD,
+ MangledSymbols &Symbols, int RDO) {
+ for (const auto *D : FTD.specializations())
+ HandleNamedDecl(dyn_cast<NamedDecl>(D), Symbols, RDO);
+ }
+
+ void HandleTemplateSpecializations(const ClassTemplateDecl &CTD,
+ MangledSymbols &Symbols, int RDO) {
+ for (const auto *D : CTD.specializations())
+ HandleNamedDecl(dyn_cast<NamedDecl>(D), Symbols, RDO);
+ }
+
+ bool HandleNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
+ if (!ND)
+ return false;
+
+ switch (ND->getKind()) {
+ default:
+ break;
+ case Decl::Kind::Namespace:
+ HandleDecls(cast<NamespaceDecl>(ND)->decls(), Symbols, RDO);
+ return true;
+ case Decl::Kind::CXXRecord:
+ HandleDecls(cast<CXXRecordDecl>(ND)->decls(), Symbols, RDO);
+ return true;
+ case Decl::Kind::ClassTemplateSpecialization:
+ HandleDecls(cast<ClassTemplateSpecializationDecl>(ND)->decls(), Symbols,
+ RDO);
+ return true;
+ case Decl::Kind::ClassTemplate:
+ HandleTemplateSpecializations(*cast<ClassTemplateDecl>(ND), Symbols, RDO);
+ return true;
+ case Decl::Kind::FunctionTemplate:
+ HandleTemplateSpecializations(*cast<FunctionTemplateDecl>(ND), Symbols,
+ RDO);
+ return true;
+ case Decl::Kind::TemplateTypeParm:
+ return true;
+ case Decl::Kind::Var:
+ case Decl::Kind::ParmVar:
+ case Decl::Kind::CXXMethod:
+ case Decl::Kind::CXXConstructor:
+ case Decl::Kind::CXXDestructor:
+ case Decl::Kind::Function:
+ case Decl::Kind::Field:
+ if (WriteNamedDecl(ND, Symbols, RDO))
+ return true;
+ }
+
+ // While interface stubs are in the development stage, it's probably best to
+ // catch anything that's not a VarDecl or Template/FunctionDecl.
+ Instance.getDiagnostics().Report(diag::err_asm_invalid_type_in_input)
+ << "Expected a function or function template decl.";
+ return false;
+ }
+
+public:
+ InterfaceStubFunctionsConsumer(CompilerInstance &Instance, StringRef InFile,
+ StringRef Format)
+ : Instance(Instance), InFile(InFile), Format(Format) {}
+
+ void HandleTranslationUnit(ASTContext &context) override {
+ struct Visitor : public RecursiveASTVisitor<Visitor> {
+ bool VisitNamedDecl(NamedDecl *ND) {
+ if (const auto *FD = dyn_cast<FunctionDecl>(ND))
+ if (FD->isLateTemplateParsed()) {
+ LateParsedDecls.insert(FD);
+ return true;
+ }
+
+ if (const auto *VD = dyn_cast<ValueDecl>(ND)) {
+ ValueDecls.insert(VD);
+ return true;
+ }
+
+ NamedDecls.insert(ND);
+ return true;
+ }
+
+ std::set<const NamedDecl *> LateParsedDecls;
+ std::set<NamedDecl *> NamedDecls;
+ std::set<const ValueDecl *> ValueDecls;
+ } v;
+
+ v.TraverseDecl(context.getTranslationUnitDecl());
+
+ MangledSymbols Symbols;
+ auto OS = Instance.createDefaultOutputFile(/*Binary=*/false, InFile, "ifs");
+ if (!OS)
+ return;
+
+ if (Instance.getLangOpts().DelayedTemplateParsing) {
+ clang::Sema &S = Instance.getSema();
+ for (const auto *FD : v.LateParsedDecls) {
+ clang::LateParsedTemplate &LPT =
+ *S.LateParsedTemplateMap.find(cast<FunctionDecl>(FD))->second;
+ S.LateTemplateParser(S.OpaqueParser, LPT);
+ HandleNamedDecl(FD, Symbols, (FromTU | IsLate));
+ }
+ }
+
+ for (const NamedDecl *ND : v.ValueDecls)
+ HandleNamedDecl(ND, Symbols, FromTU);
+ for (const NamedDecl *ND : v.NamedDecls)
+ HandleNamedDecl(ND, Symbols, FromTU);
+
+ auto writeIfoYaml = [this](const llvm::Triple &T,
+ const MangledSymbols &Symbols,
+ const ASTContext &context, StringRef Format,
+ raw_ostream &OS) -> void {
+ OS << "--- !" << Format << "\n";
+ OS << "FileHeader:\n";
+ OS << " Class: ELFCLASS";
+ OS << (T.isArch64Bit() ? "64" : "32");
+ OS << "\n";
+ OS << " Data: ELFDATA2";
+ OS << (T.isLittleEndian() ? "LSB" : "MSB");
+ OS << "\n";
+ OS << " Type: ET_REL\n";
+ OS << " Machine: "
+ << llvm::StringSwitch<llvm::StringRef>(T.getArchName())
+ .Case("x86_64", "EM_X86_64")
+ .Case("i386", "EM_386")
+ .Case("i686", "EM_386")
+ .Case("aarch64", "EM_AARCH64")
+ .Case("amdgcn", "EM_AMDGPU")
+ .Case("r600", "EM_AMDGPU")
+ .Case("arm", "EM_ARM")
+ .Case("thumb", "EM_ARM")
+ .Case("avr", "EM_AVR")
+ .Case("mips", "EM_MIPS")
+ .Case("mipsel", "EM_MIPS")
+ .Case("mips64", "EM_MIPS")
+ .Case("mips64el", "EM_MIPS")
+ .Case("msp430", "EM_MSP430")
+ .Case("ppc", "EM_PPC")
+ .Case("ppc64", "EM_PPC64")
+ .Case("ppc64le", "EM_PPC64")
+ .Case("x86", T.isOSIAMCU() ? "EM_IAMCU" : "EM_386")
+ .Case("x86_64", "EM_X86_64")
+ .Default("EM_NONE")
+ << "\nSymbols:\n";
+ for (const auto &E : Symbols) {
+ const MangledSymbol &Symbol = E.second;
+ for (auto Name : Symbol.Names) {
+ OS << " - Name: "
+ << (Symbol.ParentName.empty() || Instance.getLangOpts().CPlusPlus
+ ? ""
+ : (Symbol.ParentName + "."))
+ << Name << "\n"
+ << " Type: STT_";
+ switch (Symbol.Type) {
+ default:
+ case llvm::ELF::STT_NOTYPE:
+ OS << "NOTYPE";
+ break;
+ case llvm::ELF::STT_OBJECT:
+ OS << "OBJECT";
+ break;
+ case llvm::ELF::STT_FUNC:
+ OS << "FUNC";
+ break;
+ }
+ OS << "\n Binding: STB_"
+ << ((Symbol.Binding == llvm::ELF::STB_WEAK) ? "WEAK" : "GLOBAL")
+ << "\n";
+ }
+ }
+ OS << "...\n";
+ OS.flush();
+ };
+
+ auto writeIfoElfAbiYaml =
+ [this](const llvm::Triple &T, const MangledSymbols &Symbols,
+ const ASTContext &context, StringRef Format,
+ raw_ostream &OS) -> void {
+ OS << "--- !" << Format << "\n";
+ OS << "TbeVersion: 1.0\n";
+ OS << "Arch: " << T.getArchName() << "\n";
+ 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
+ writeIfoElfAbiYaml(Instance.getTarget().getTriple(), Symbols, context,
+ Format, *OS);
+ }
+};
+
+std::unique_ptr<ASTConsumer>
+GenerateInterfaceYAMLExpV1Action::CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) {
+ return llvm::make_unique<InterfaceStubFunctionsConsumer>(
+ CI, InFile, "experimental-yaml-elf-v1");
+}
+
+std::unique_ptr<ASTConsumer>
+GenerateInterfaceTBEExpV1Action::CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) {
+ return llvm::make_unique<InterfaceStubFunctionsConsumer>(
+ CI, InFile, "experimental-tapi-elf-v1");
+}
Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=363948&r1=363947&r2=363948&view=diff
==============================================================================
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Thu Jun 20 09:59:48 2019
@@ -64,6 +64,10 @@ CreateFrontendBaseAction(CompilerInstanc
case GenerateHeaderModule:
return llvm::make_unique<GenerateHeaderModuleAction>();
case GeneratePCH: return llvm::make_unique<GeneratePCHAction>();
+ case GenerateInterfaceYAMLExpV1:
+ return llvm::make_unique<GenerateInterfaceYAMLExpV1Action>();
+ case GenerateInterfaceTBEExpV1:
+ return llvm::make_unique<GenerateInterfaceTBEExpV1Action>();
case InitOnly: return llvm::make_unique<InitOnlyAction>();
case ParseSyntaxOnly: return llvm::make_unique<SyntaxOnlyAction>();
case ModuleFileInfo: return llvm::make_unique<DumpModuleInfoAction>();
Added: cfe/trunk/test/InterfaceStubs/bad-format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/bad-format.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/bad-format.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/bad-format.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,7 @@
+// RUN: not %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=bar-format %s 2>&1 | FileCheck %s
+
+// CHECK: error: invalid value
+// CHECK: '-interface-stub-version=<experimental-tapi-elf-v1 |
+// CHECK: experimental-yaml-elf-v1>' in 'Must specify a valid interface
+// CHECK: stub format type using
Added: cfe/trunk/test/InterfaceStubs/class-template-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/class-template-specialization.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/class-template-specialization.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/class-template-specialization.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,42 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI2 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// For the following:
+// g()
+// n::S<int>::S()
+// n::S<int>::~S()
+// n::S<int>::func() const
+// n::S<int>::S(n::S<int> const&)
+
+// We expect these manglings:
+// CHECK-TAPI: Symbols:
+// CHECK-TAPI-NOT: _ZNK1n1SIiEclEv
+// CHECK-TAPI2: Symbols:
+// CHECK-TAPI2: _Z1g
+
+// CHECK-SYMBOLS-DAG: FUNC GLOBAL DEFAULT {{[0-9]}} _Z1g
+// CHECK-SYMBOLS-DAG: FUNC WEAK HIDDEN {{[0-9]}} _ZNK1n1SIiEclEv
+
+namespace n {
+template <typename T>
+struct __attribute__((__visibility__("default"))) S {
+ S() = default;
+ ~S() = default;
+ int __attribute__((__visibility__(("default")))) func() const {
+ return 1844;
+ }
+ int __attribute__((__visibility__(("hidden")))) operator()() const {
+ return 1863;
+ }
+};
+} // namespace n
+
+void g() { n::S<int>()(); }
Added: cfe/trunk/test/InterfaceStubs/externstatic.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/externstatic.c?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/externstatic.c (added)
+++ cfe/trunk/test/InterfaceStubs/externstatic.c Thu Jun 20 09:59:48 2019
@@ -0,0 +1,29 @@
+// RUN: %clang -DSTORAGE="extern" -target x86_64-unknown-linux-gnu -o - \
+// RUN: -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -std=c99 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-EXTERN %s
+// RUN: %clang -DSTORAGE="extern" -target x86_64-linux-gnu -O0 -o - -c -std=c99 \
+// RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-EXTERN %s
+
+// RUN: %clang -DSTORAGE="extern" -target x86_64-unknown-linux-gnu -o - \
+// RUN: -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -std=c99 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-EXTERN2 %s
+// RUN: %clang -DSTORAGE="extern" -target x86_64-linux-gnu -O0 -o - -c -std=c99 \
+// RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-EXTERN2 %s
+
+// RUN: %clang -DSTORAGE="static" -target x86_64-unknown-linux-gnu -o - \
+// RUN: -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -std=c99 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-STATIC %s
+// RUN: %clang -DSTORAGE="static" -target x86_64-linux-gnu -O0 -o - -c -std=c99 \
+// RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-STATIC %s
+
+// CHECK-EXTERN-NOT: foo
+// CHECK-STATIC-NOT: foo
+// CHECK-STATIC-NOT: bar
+
+// We want to emit extern function symbols.
+// CHECK-EXTERN2: bar
+STORAGE int foo;
+STORAGE int bar() { return 42; }
Added: cfe/trunk/test/InterfaceStubs/function-template-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/function-template-specialization.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/function-template-specialization.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/function-template-specialization.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,41 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DUSE_TEMPLATE_FUNCTION=1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-USES-TEMPLATE-FUNCTION %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DSPECIALIZE_TEMPLATE_FUNCTION=1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-SPECIALIZES-TEMPLATE-FUNCTION %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
+// RUN: %s | llvm-nm - 2>&1 | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
+// RUN: -DUSE_TEMPLATE_FUNCTION=1 %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-USES-TEMPLATE-FUNCTION %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
+// RUN: -DSPECIALIZE_TEMPLATE_FUNCTION=1 %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SPECIALIZES-TEMPLATE-FUNCTION %s
+
+// CHECK-NOT: _Z16templateFunctionIiET_S0_
+// CHECK-USES-TEMPLATE-FUNCTION-DAG: _Z16templateFunctionIiET_S0_
+// CHECK-SPECIALIZES-TEMPLATE-FUNCTION-DAG: _Z16templateFunctionIiET_S0_
+template <typename T>
+T templateFunction(T t) { return t; }
+
+#ifdef USE_TEMPLATE_FUNCTION
+int FortyTwo = templateFunction<int>(42);
+#endif
+
+#ifdef SPECIALIZE_TEMPLATE_FUNCTION
+template <>
+int templateFunction<int>(int t);
+// TODO: Make it so that -emit-interface-stubs does not emit
+// _Z16templateFunctionIiET_S0_ if there is no user of the specialization.
+int foo() { return templateFunction(42); }
+#endif
Added: cfe/trunk/test/InterfaceStubs/hidden-class-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/hidden-class-inheritance.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/hidden-class-inheritance.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/hidden-class-inheritance.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,153 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DPARENT_CLASS_VISIBILITY="" -DCHILD_CLASS_VISIBILITY="" \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: FileCheck -check-prefix=CHECK-X %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
+// RUN: -DPARENT_CLASS_VISIBILITY="" -DCHILD_CLASS_VISIBILITY="" \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-X-RE %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DPARENT_CLASS_VISIBILITY=HIDDEN -DCHILD_CLASS_VISIBILITY="" \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: FileCheck -check-prefix=CHECK-HP %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DPARENT_CLASS_VISIBILITY=HIDDEN -DCHILD_CLASS_VISIBILITY="" \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: FileCheck -check-prefix=CHECK-HP2 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
+// RUN: -DPARENT_CLASS_VISIBILITY=HIDDEN -DCHILD_CLASS_VISIBILITY="" \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-HP-RE %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DPARENT_CLASS_VISIBILITY="" -DCHILD_CLASS_VISIBILITY=HIDDEN \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: FileCheck -check-prefix=CHECK-HC %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DPARENT_CLASS_VISIBILITY="" -DCHILD_CLASS_VISIBILITY=HIDDEN \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: FileCheck -check-prefix=CHECK-HC2 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
+// RUN: -DPARENT_CLASS_VISIBILITY="" -DCHILD_CLASS_VISIBILITY=HIDDEN \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-HC-RE %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -DPARENT_CLASS_VISIBILITY=HIDDEN -DCHILD_CLASS_VISIBILITY=HIDDEN \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: FileCheck -check-prefix=CHECK-HP-HC %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
+// RUN: -DPARENT_CLASS_VISIBILITY=HIDDEN -DCHILD_CLASS_VISIBILITY=HIDDEN \
+// RUN: -DPARENT_METHOD_VISIBILITY="" -DCHILD_METHOD_VISIBILITY="" %s | \
+// RUN: llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-HP-HC-RE %s
+
+// CHECK-X-DAG: _ZN1CC2Ev
+// CHECK-X-DAG: _ZN1CD0Ev
+// CHECK-X-DAG: _ZN1CD2Ev
+// CHECK-X-DAG: _ZN1SC2Ev
+// CHECK-X-DAG: _ZN1SD0Ev
+// CHECK-X-DAG: _ZN1SD2Ev
+// CHECK-X-DAG: _ZN1C1mEv
+// CHECK-X-DAG: _ZN1S1nEv
+
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1C1mEv
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1CC2Ev
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1CD0Ev
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1CD2Ev
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1S1nEv
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1SC2Ev
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1SD0Ev
+// CHECK-X-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1SD2Ev
+
+// CHECK-HP2-DAG: _ZN1CC2Ev
+// CHECK-HP2-DAG: _ZN1CD0Ev
+// CHECK-HP2-DAG: _ZN1CD2Ev
+// CHECK-HP2-DAG: _ZN1C1mEv
+
+// CHECK-HP-NOT: _ZN1S1nEv
+// CHECK-HP-NOT: _ZN1SC2Ev
+// CHECK-HP-NOT: _ZN1SD0Ev
+// CHECK-HP-NOT: _ZN1SD2Ev
+
+// CHECK-HP-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1C1mEv
+// CHECK-HP-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1CC2Ev
+// CHECK-HP-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1CD0Ev
+// CHECK-HP-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1CD2Ev
+// CHECK-HP-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1S1nEv
+// CHECK-HP-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1SC2Ev
+// CHECK-HP-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1SD0Ev
+// CHECK-HP-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1SD2Ev
+
+// CHECK-HC2-DAG: _ZN1SC2Ev
+// CHECK-HC2-DAG: _ZN1SD0Ev
+// CHECK-HC2-DAG: _ZN1SD2Ev
+// CHECK-HC2-DAG: _ZN1S1nEv
+
+// CHECK-HC-NOT: _ZN1C1mEv
+// CHECK-HC-NOT: _ZN1CC2Ev
+// CHECK-HC-NOT: _ZN1CD0Ev
+// CHECK-HC-NOT: _ZN1CD2Ev
+
+// CHECK-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1C1mEv
+// CHECK-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1CC2Ev
+// CHECK-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1CD0Ev
+// CHECK-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1CD2Ev
+// CHECK-HC-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1S1nEv
+// CHECK-HC-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1SC2Ev
+// CHECK-HC-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1SD0Ev
+// CHECK-HC-RE: FUNC WEAK DEFAULT {{[0-9]+}} _ZN1SD2Ev
+
+// CHECK-HP-HC-NOT: _ZN1CC2Ev
+// CHECK-HP-HC-NOT: _ZN1CD0Ev
+// CHECK-HP-HC-NOT: _ZN1CD2Ev
+// CHECK-HP-HC-NOT: _ZN1SC2Ev
+// CHECK-HP-HC-NOT: _ZN1SD0Ev
+// CHECK-HP-HC-NOT: _ZN1SD2Ev
+// CHECK-HP-HC-NOT: _ZN1C1mEv
+// CHECK-HP-HC-NOT: _ZN1S1nEv
+
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1C1mEv
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1CC2Ev
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1CD0Ev
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1CD2Ev
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1S1nEv
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1SC2Ev
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1SD0Ev
+// CHECK-HP-HC-RE: FUNC WEAK HIDDEN {{[0-9]+}} _ZN1SD2Ev
+
+// TODO: clang+llvm does not materialize complete ctors and dtors for the
+// Itanium abi. Figure out why and add the check-not for these:
+// _ZN1CC1Ev
+// _ZN1CD1Ev
+// _ZN1SC1Ev
+// _ZN1SD1Ev
+
+#define HIDDEN __attribute__((__visibility__("hidden")))
+#define DEFAULT __attribute__((__visibility__("default")))
+
+struct PARENT_CLASS_VISIBILITY S {
+ virtual ~S() {}
+ virtual PARENT_METHOD_VISIBILITY void n() {}
+};
+
+class CHILD_CLASS_VISIBILITY C : public S {
+public:
+ virtual CHILD_METHOD_VISIBILITY void m() {}
+};
+
+void f() {
+ C c;
+ c.m();
+ c.n();
+}
Added: cfe/trunk/test/InterfaceStubs/inline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/inline.c?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/inline.c (added)
+++ cfe/trunk/test/InterfaceStubs/inline.c Thu Jun 20 09:59:48 2019
@@ -0,0 +1,67 @@
+// RUN: %clang -DINLINE=inline -target x86_64-unknown-linux-gnu -o - \
+// RUN: -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -std=gnu89 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-GNU %s
+// RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -O0 -o - -c \
+// RUN: -std=gnu89 -xc %s | llvm-nm - | FileCheck -check-prefix=CHECK-GNU %s
+
+// RUN: %clang -DINLINE="__attribute__((always_inline))" \
+// RUN: -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-GNU %s
+// RUN: %clang -DINLINE="__attribute__((always_inline))" \
+// RUN: -target x86_64-linux-gnu -O0 -o - -c -xc %s | \
+// RUN: llvm-nm - | FileCheck -check-prefix=CHECK-GNU %s
+
+// RUN: %clang -DINLINE=inline -target x86_64-unknown-linux-gnu -o - \
+// RUN: -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -std=c99 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-STD %s
+// RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -O0 -o - -c -std=c99 \
+// RUN: -xc %s | llvm-nm - 2>&1 | FileCheck -check-prefix=CHECK-STD %s
+
+// RUN: %clang -DINLINE="__attribute__((noinline))" \
+// RUN: -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -std=c99 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-NOINLINE %s
+// RUN: %clang -DINLINE="__attribute__((noinline))" -target x86_64-linux-gnu \
+// RUN: -O0 -o - -c -std=c99 -xc %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-NOINLINE %s
+
+// RUN: %clang -DINLINE="static" -target x86_64-unknown-linux-gnu -o - \
+// RUN: -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -std=c99 -xc %s | \
+// RUN: FileCheck -check-prefix=CHECK-STATIC %s
+// RUN: %clang -DINLINE="static" -target x86_64-linux-gnu -O0 -o - -c \
+// RUN: -std=c99 -xc %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-STATIC %s
+
+// CHECK-GNU-DAG: foo
+// CHECK-GNU-DAG: foo.var
+// CHECK-NOINLINE-DAG: foo
+// CHECK-NOINLINE-DAG: foo.var
+// CHECK-STATIC-NOT: foo
+// CHECK-STATIC-NOT: foo.var
+// CHECK-STD-NOT: foo
+#pragma clang diagnostic ignored "-Wstatic-local-in-inline"
+INLINE int foo() {
+ static int var = 42;
+ return var;
+}
+
+// RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -o - \
+// RUN: -emit-interface-stubs -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -std=gnu89 -xc %s | FileCheck -check-prefix=CHECK-TAPI %s
+
+// RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -o - \
+// RUN: -emit-interface-stubs -interface-stub-version=experimental-tapi-elf-v1 \
+// RUN: -std=gnu89 -xc %s | FileCheck -check-prefix=CHECK-SYMBOLS %s
+// RUN: %clang -DINLINE=inline -target x86_64-linux-gnu -o - \
+// RUN: -c -std=gnu89 -xc %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK-TAPI-DAG: foo: { Type: Func }
+// CHECK-TAPI-DAG: foo.var: { Type: Object, Size: 4 }
+// CHECK-SYMBOLS-DAG: foo
+// CHECK-SYMBOLS-DAG: foo.var
+#include "inline.h"
Added: cfe/trunk/test/InterfaceStubs/inline.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/inline.h?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/inline.h (added)
+++ cfe/trunk/test/InterfaceStubs/inline.h Thu Jun 20 09:59:48 2019
@@ -0,0 +1,4 @@
+INLINE int bar() {
+ static int var = 42;
+ return var;
+}
Added: cfe/trunk/test/InterfaceStubs/object.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/object.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/object.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/object.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,13 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK-TAPI: data: { Type: Object, Size: 4 }
+// CHECK-SYMBOLS: data
+int data = 42;
Added: cfe/trunk/test/InterfaceStubs/template-namespace-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/template-namespace-function.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/template-namespace-function.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/template-namespace-function.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,31 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG: _ZN3qux3barEii: { Type: Func }
+// CHECK-DAG: _ZN3baz3addIiEET_S1_S1_: { Type: Func }
+// CHECK-DAG: _Z4fbarff: { Type: Func }
+// CHECK-DAG: _ZN3baz3addIfEET_S1_S1_: { Type: Func }
+
+// Same symbols just different order.
+// CHECK-SYMBOLS-DAG: _Z4fbarff
+// CHECK-SYMBOLS-DAG: _ZN3baz3addIfEET_S1_S1_
+// CHECK-SYMBOLS-DAG: _ZN3baz3addIiEET_S1_S1_
+// CHECK-SYMBOLS-DAG: _ZN3qux3barEii
+
+namespace baz {
+template <typename T>
+T add(T a, T b) {
+ return a + b;
+}
+} // namespace baz
+
+namespace qux {
+int bar(int a, int b) { return baz::add<int>(a, b); }
+} // namespace qux
+
+float fbar(float a, float b) { return baz::add<float>(a, b); }
Added: cfe/trunk/test/InterfaceStubs/virtual.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/virtual.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/virtual.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/virtual.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,41 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI2 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN __attribute__((__visibility__(("hidden"))))
+#define DEFAULT __attribute__((__visibility__(("default"))))
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5func2Ev
+// CHECK-SYMBOLS-DAG: NOTYPE GLOBAL HIDDEN {{.*}} _ZNK1Q5func1Ev
+// CHECK-SYMBOLS-DAG: NOTYPE GLOBAL DEFAULT {{.*}} _ZNK1Q5func2Ev
+struct Q {
+ virtual HIDDEN int func1() const;
+ virtual DEFAULT int func2() const;
+} q;
+
+// CHECK-TAPI-NOT: _ZNK1S5func1Ev
+// CHECK-TAPI2-DAG: _ZNK1S5func2Ev
+// CHECK-SYMBOLS-DAG: FUNC WEAK HIDDEN {{.*}} _ZNK1S5func1Ev
+// CHECK-SYMBOLS-DAG: FUNC WEAK DEFAULT {{.*}} _ZNK1S5func2Ev
+struct S {
+ virtual HIDDEN int func1() const { return 42; }
+ virtual DEFAULT int func2() const { return 42; }
+} s;
+
+// CHECK-TAPI-NOT: _ZNK1R5func1Ev
+// CHECK-TAPI-NOT: _ZNK1R5func2Ev
+// CHECK-SYMBOLS-NOT: _ZNK1R5func1Ev
+// CHECK-SYMBOLS-NOT: _ZNK1R5func2Ev
+struct R {
+ virtual HIDDEN int func1() const = 0;
+ virtual DEFAULT int func2() const = 0;
+};
+
+int a = q.func1() + q.func2();
+
Added: cfe/trunk/test/InterfaceStubs/visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/visibility.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/visibility.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/visibility.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,45 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD2 %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD2 %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-CMD2-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-CMD-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-CMD-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT {{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT {{.*}} _Z9nothiddenv
Added: cfe/trunk/test/InterfaceStubs/weak.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/InterfaceStubs/weak.cpp?rev=363948&view=auto
==============================================================================
--- cfe/trunk/test/InterfaceStubs/weak.cpp (added)
+++ cfe/trunk/test/InterfaceStubs/weak.cpp Thu Jun 20 09:59:48 2019
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG: _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG: _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG: - Name: _Z8weakFuncv
+// CHECK-YAML-DAG: Type: STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG: - Name: _Z10strongFuncv
+// CHECK-YAML-DAG: Type: STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
More information about the cfe-commits
mailing list