forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][InstallAPI] Introduce basic driver to write out tbd files (l…
…lvm#81571) This introduces a basic outline of installapi as a clang driver option. It captures relevant information as cc1 args, which are common arguments already passed to the linker to encode into TBD file outputs. This is effectively an upstream for what already exists as `tapi installapi` in Xcode toolchains, but directly in Clang. This patch does not handle any AST traversing on input yet. InstallAPI is broadly an operation that takes a series of header files that represent a single dynamic library and generates a TBD file out of it which represents all the linkable symbols and necessary attributes for statically linking in clients. It is the linkable object in all Apple SDKs and when building dylibs in Xcode. `clang -installapi` also will support verification where it compares all the information recorded for the TBD files against the already built binary, to catch possible mismatches like when a declaration is missing a definition for an exported symbol.
- Loading branch information
1 parent
14b0d0d
commit 09e9895
Showing
25 changed files
with
357 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===--- InstallAPIOptions.h ------------------------------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_FRONTEND_INSTALLAPIOPTIONS_H | ||
#define LLVM_CLANG_FRONTEND_INSTALLAPIOPTIONS_H | ||
|
||
#include "llvm/TextAPI/PackedVersion.h" | ||
|
||
namespace clang { | ||
|
||
/// InstallAPIOptions - Options for controlling InstallAPI verification and | ||
/// TextAPI output. | ||
class InstallAPIOptions { | ||
public: | ||
/// The install name which is apart of the library's ID. | ||
std::string InstallName; | ||
|
||
/// The current version which is apart of the library's ID. | ||
llvm::MachO::PackedVersion CurrentVersion; | ||
}; | ||
} // namespace clang | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//===- InstallAPI/Context.h -------------------------------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Top level types for interacting with the generic clang driver and frontend | ||
// for InstallAPI operations. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H | ||
#define LLVM_CLANG_INSTALLAPI_CONTEXT_H | ||
|
||
#include "clang/AST/ASTConsumer.h" | ||
#include "clang/Basic/Diagnostic.h" | ||
#include "llvm/ADT/IntrusiveRefCntPtr.h" | ||
#include "llvm/TextAPI/InterfaceFile.h" | ||
#include "llvm/TextAPI/RecordVisitor.h" | ||
#include "llvm/TextAPI/RecordsSlice.h" | ||
|
||
namespace clang { | ||
namespace installapi { | ||
|
||
/// Struct used for generating validating InstallAPI. | ||
/// The attributes captured represent all necessary information | ||
/// to generate TextAPI output. | ||
struct InstallAPIContext { | ||
|
||
/// Library attributes that are typically passed as linker inputs. | ||
llvm::MachO::RecordsSlice::BinaryAttrs BA; | ||
|
||
/// Active target triple to parse. | ||
llvm::Triple TargetTriple{}; | ||
|
||
/// Output stream to write TextAPI file to. | ||
std::unique_ptr<llvm::raw_pwrite_stream> OS = nullptr; | ||
|
||
/// DiagnosticsEngine to report errors. | ||
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags = nullptr; | ||
|
||
/// File Path of output location. | ||
StringRef OutputLoc{}; | ||
|
||
/// What encoding to write output as. | ||
llvm::MachO::FileType FT = llvm::MachO::FileType::TBD_V5; | ||
}; | ||
|
||
class InstallAPIConsumer : public ASTConsumer { | ||
public: | ||
InstallAPIConsumer(InstallAPIContext InstallAPICtx) | ||
: Ctx(std::move(InstallAPICtx)) {} | ||
|
||
void HandleTranslationUnit(ASTContext &ASTContext) override; | ||
|
||
private: | ||
InstallAPIContext Ctx; | ||
}; | ||
|
||
} // namespace installapi | ||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_INSTALLAPI_CONTEXT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.