[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/cyndyishida created https://github.com/llvm/llvm-project/pull/88750 Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. >From 3170f89b36ccf3ad6003f24decb282e23951d943 Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Thu, 11 Apr 2024 13:13:45 -0700 Subject: [PATCH] [InstallAPI] Add support for aliased exports Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. --- .../clang/Basic/DiagnosticInstallAPIKinds.td | 1 + clang/include/clang/Driver/Options.td | 1 + .../include/clang/InstallAPI/DylibVerifier.h | 15 +- clang/include/clang/InstallAPI/MachO.h| 1 + clang/lib/InstallAPI/DylibVerifier.cpp| 24 + clang/test/InstallAPI/alias_list.test | 461 ++ clang/tools/clang-installapi/Options.cpp | 26 +- clang/tools/clang-installapi/Options.h| 3 + llvm/include/llvm/TextAPI/Utils.h | 11 + llvm/lib/TextAPI/Utils.cpp| 34 ++ 10 files changed, 570 insertions(+), 7 deletions(-) create mode 100644 clang/test/InstallAPI/alias_list.test diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index 396bff0146a373..91a40cd589b385 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">; def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">; def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; +def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..8c38acb72362c7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Visibility<[ClangOption, CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; +def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>; def extract_api : Flag<["-"], "extract-api">, Visibility<[ClangOption, CC1Option]>, Group, HelpText<"Extract API information">; diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h b/clang/include/clang/InstallAPI/DylibVerifier.h index 31de212fc423a5..f1a949d8f99394 100644 --- a/clang/include/clang/InstallAPI/DylibVerifier.h +++ b/clang/include/clang/InstallAPI/DylibVerifier.h @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor { DylibVerifier() = default; DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports, -DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered, -bool Demangle, StringRef DSYMPath) - : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode), -Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath), +AliasMap Aliases, DiagnosticsEngine *Diag, +VerificationMode Mode, bool Zippered, bool Demangle, +StringRef DSYMPath) + : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), +Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered), +Demangle(Demangle), DSYMPath(DSYMPath), Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {} Result verify(GlobalRecord *R, const FrontendAttrs *FA); @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor { void setTarget(const Target &T); /// Release ownership over exports. - std::unique_ptr getExports() { return std::move(Exports); } + std::unique_ptr getExports(); /// Get result of verification. Result getState() const { return Ctx.FrontendState; } @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor { // Reexported interfaces apart of the library. ReexportedInterfaces Reexports; + // Symbol aliases. + AliasMap Aliases; + // Controls what clas
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Cyndy Ishida (cyndyishida) Changes Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. --- Patch is 24.16 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88750.diff 10 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticInstallAPIKinds.td (+1) - (modified) clang/include/clang/Driver/Options.td (+1) - (modified) clang/include/clang/InstallAPI/DylibVerifier.h (+10-5) - (modified) clang/include/clang/InstallAPI/MachO.h (+1) - (modified) clang/lib/InstallAPI/DylibVerifier.cpp (+24) - (added) clang/test/InstallAPI/alias_list.test (+461) - (modified) clang/tools/clang-installapi/Options.cpp (+24-2) - (modified) clang/tools/clang-installapi/Options.h (+3) - (modified) llvm/include/llvm/TextAPI/Utils.h (+11) - (modified) llvm/lib/TextAPI/Utils.cpp (+34) ``diff diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index 396bff0146a373..91a40cd589b385 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">; def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">; def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; +def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..8c38acb72362c7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Visibility<[ClangOption, CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; +def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>; def extract_api : Flag<["-"], "extract-api">, Visibility<[ClangOption, CC1Option]>, Group, HelpText<"Extract API information">; diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h b/clang/include/clang/InstallAPI/DylibVerifier.h index 31de212fc423a5..f1a949d8f99394 100644 --- a/clang/include/clang/InstallAPI/DylibVerifier.h +++ b/clang/include/clang/InstallAPI/DylibVerifier.h @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor { DylibVerifier() = default; DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports, -DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered, -bool Demangle, StringRef DSYMPath) - : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode), -Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath), +AliasMap Aliases, DiagnosticsEngine *Diag, +VerificationMode Mode, bool Zippered, bool Demangle, +StringRef DSYMPath) + : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), +Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered), +Demangle(Demangle), DSYMPath(DSYMPath), Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {} Result verify(GlobalRecord *R, const FrontendAttrs *FA); @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor { void setTarget(const Target &T); /// Release ownership over exports. - std::unique_ptr getExports() { return std::move(Exports); } + std::unique_ptr getExports(); /// Get result of verification. Result getState() const { return Ctx.FrontendState; } @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor { // Reexported interfaces apart of the library. ReexportedInterfaces Reexports; + // Symbol aliases. + AliasMap Aliases; + // Controls what class of violations to report. VerificationMode Mode = VerificationMode::Invalid; diff --git a/clang/include/clang/InstallAPI/MachO.h b/clang/include/clang/InstallAPI/MachO.h index 854399f54ba6c8..9da91a62e23311 100644 --- a/clang/include/clang/InstallAPI/MachO.h +++ b/clang/include/clang/InstallAPI/MachO.h @@ -23,6 +23,7 @@ #include "llvm/TextAPI/TextAPIWriter.h" #include "llvm/TextAPI/Utils.h" +using AliasMap = llvm::MachO::AliasMap; using Architecture = llvm::MachO::Architecture;
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff a06073f91e7532e68bbf6b903c2f5051f4c2 3170f89b36ccf3ad6003f24decb282e23951d943 -- clang/include/clang/InstallAPI/DylibVerifier.h clang/include/clang/InstallAPI/MachO.h clang/lib/InstallAPI/DylibVerifier.cpp clang/tools/clang-installapi/Options.cpp clang/tools/clang-installapi/Options.h llvm/include/llvm/TextAPI/Utils.h llvm/lib/TextAPI/Utils.cpp `` View the diff from clang-format here. ``diff diff --git a/llvm/include/llvm/TextAPI/Utils.h b/llvm/include/llvm/TextAPI/Utils.h index 01999107d6..6126be61d7 100644 --- a/llvm/include/llvm/TextAPI/Utils.h +++ b/llvm/include/llvm/TextAPI/Utils.h @@ -81,8 +81,8 @@ llvm::Expected createRegexFromGlob(llvm::StringRef Glob); using AliasEntry = std::pair; using AliasMap = std::map; -/// Parse input list and capture symbols and their alias. -/// \param Buffer Data contents of file for the alias list. +/// Parse input list and capture symbols and their alias. +/// \param Buffer Data contents of file for the alias list. /// \return Lookup able of symbol name to their alias. Expected parseAliasList(std::unique_ptr &Buffer); `` https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/cyndyishida updated https://github.com/llvm/llvm-project/pull/88750 >From d7a4e72f80a9dcd18770dec1e06fd54518b60233 Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Thu, 11 Apr 2024 13:13:45 -0700 Subject: [PATCH] [InstallAPI] Add support for aliased exports Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. --- .../clang/Basic/DiagnosticInstallAPIKinds.td | 1 + clang/include/clang/Driver/Options.td | 1 + .../include/clang/InstallAPI/DylibVerifier.h | 15 +- clang/include/clang/InstallAPI/MachO.h| 1 + clang/lib/InstallAPI/DylibVerifier.cpp| 24 + clang/test/InstallAPI/alias_list.test | 461 ++ clang/tools/clang-installapi/Options.cpp | 24 +- clang/tools/clang-installapi/Options.h| 3 + llvm/include/llvm/TextAPI/Utils.h | 12 + llvm/lib/TextAPI/Utils.cpp| 34 ++ 10 files changed, 569 insertions(+), 7 deletions(-) create mode 100644 clang/test/InstallAPI/alias_list.test diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index 396bff0146a373..91a40cd589b385 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">; def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">; def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; +def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..8c38acb72362c7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Visibility<[ClangOption, CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; +def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>; def extract_api : Flag<["-"], "extract-api">, Visibility<[ClangOption, CC1Option]>, Group, HelpText<"Extract API information">; diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h b/clang/include/clang/InstallAPI/DylibVerifier.h index 31de212fc423a5..f1a949d8f99394 100644 --- a/clang/include/clang/InstallAPI/DylibVerifier.h +++ b/clang/include/clang/InstallAPI/DylibVerifier.h @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor { DylibVerifier() = default; DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports, -DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered, -bool Demangle, StringRef DSYMPath) - : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode), -Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath), +AliasMap Aliases, DiagnosticsEngine *Diag, +VerificationMode Mode, bool Zippered, bool Demangle, +StringRef DSYMPath) + : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), +Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered), +Demangle(Demangle), DSYMPath(DSYMPath), Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {} Result verify(GlobalRecord *R, const FrontendAttrs *FA); @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor { void setTarget(const Target &T); /// Release ownership over exports. - std::unique_ptr getExports() { return std::move(Exports); } + std::unique_ptr getExports(); /// Get result of verification. Result getState() const { return Ctx.FrontendState; } @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor { // Reexported interfaces apart of the library. ReexportedInterfaces Reexports; + // Symbol aliases. + AliasMap Aliases; + // Controls what class of violations to report. VerificationMode Mode = VerificationMode::Invalid; diff --git a/clang/include/clang/InstallAPI/MachO.h b/clang/include/clang/InstallAPI/MachO.h index 854399f54ba6c8..9da91a62e23311 100644 --- a/clang/include/clang/InstallAPI/MachO.h +++ b/clang/include/clang/InstallAPI/MachO.h @@ -23,6 +23,7 @@ #include "llvm/TextAPI/TextAPIWriter.h" #include
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/cyndyishida updated https://github.com/llvm/llvm-project/pull/88750 >From b2b54ad8ccf930a19327563a64c52c9f4013103f Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Thu, 11 Apr 2024 13:13:45 -0700 Subject: [PATCH] [InstallAPI] Add support for aliased exports Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. --- .../clang/Basic/DiagnosticInstallAPIKinds.td | 1 + clang/include/clang/Driver/Options.td | 1 + .../include/clang/InstallAPI/DylibVerifier.h | 15 +- clang/include/clang/InstallAPI/MachO.h| 1 + clang/lib/InstallAPI/DylibVerifier.cpp| 24 + clang/test/InstallAPI/alias_list.test | 461 ++ clang/tools/clang-installapi/Options.cpp | 24 +- clang/tools/clang-installapi/Options.h| 3 + llvm/include/llvm/TextAPI/Utils.h | 12 + llvm/lib/TextAPI/Utils.cpp| 34 ++ 10 files changed, 569 insertions(+), 7 deletions(-) create mode 100644 clang/test/InstallAPI/alias_list.test diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index 396bff0146a373..91a40cd589b385 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">; def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">; def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; +def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..8c38acb72362c7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Visibility<[ClangOption, CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; +def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>; def extract_api : Flag<["-"], "extract-api">, Visibility<[ClangOption, CC1Option]>, Group, HelpText<"Extract API information">; diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h b/clang/include/clang/InstallAPI/DylibVerifier.h index 31de212fc423a5..f1a949d8f99394 100644 --- a/clang/include/clang/InstallAPI/DylibVerifier.h +++ b/clang/include/clang/InstallAPI/DylibVerifier.h @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor { DylibVerifier() = default; DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports, -DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered, -bool Demangle, StringRef DSYMPath) - : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode), -Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath), +AliasMap Aliases, DiagnosticsEngine *Diag, +VerificationMode Mode, bool Zippered, bool Demangle, +StringRef DSYMPath) + : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), +Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered), +Demangle(Demangle), DSYMPath(DSYMPath), Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {} Result verify(GlobalRecord *R, const FrontendAttrs *FA); @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor { void setTarget(const Target &T); /// Release ownership over exports. - std::unique_ptr getExports() { return std::move(Exports); } + std::unique_ptr getExports(); /// Get result of verification. Result getState() const { return Ctx.FrontendState; } @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor { // Reexported interfaces apart of the library. ReexportedInterfaces Reexports; + // Symbol aliases. + AliasMap Aliases; + // Controls what class of violations to report. VerificationMode Mode = VerificationMode::Invalid; diff --git a/clang/include/clang/InstallAPI/MachO.h b/clang/include/clang/InstallAPI/MachO.h index 854399f54ba6c8..9da91a62e23311 100644 --- a/clang/include/clang/InstallAPI/MachO.h +++ b/clang/include/clang/InstallAPI/MachO.h @@ -23,6 +23,7 @@ #include "llvm/TextAPI/TextAPIWriter.h" #include
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
@@ -973,5 +978,24 @@ bool DylibVerifier::verifyBinaryAttrs(const ArrayRef ProvidedTargets, return true; } +std::unique_ptr DylibVerifier::getExports() { + for (const auto &[Alias, Base] : Aliases) { ributzka wrote: This loop runs every time someone calls `getExports()`. Could this be cached, so it only happens once? https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
@@ -107,6 +107,9 @@ struct LinkerOptions { /// \brief Additional library search paths. PathSeq LibPaths; + /// \brief List of aliased symbol exports. ributzka wrote: ```suggestion /// \brief List of alias symbol files. ``` https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
@@ -973,5 +978,24 @@ bool DylibVerifier::verifyBinaryAttrs(const ArrayRef ProvidedTargets, return true; } +std::unique_ptr DylibVerifier::getExports() { + for (const auto &[Alias, Base] : Aliases) { cyndyishida wrote: `getExports()` only gets called once for the whole lifetime of InstallAPI as it releases ownership over the exports to forward along to write out the final TBD file. https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/cyndyishida updated https://github.com/llvm/llvm-project/pull/88750 >From b2b54ad8ccf930a19327563a64c52c9f4013103f Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Thu, 11 Apr 2024 13:13:45 -0700 Subject: [PATCH 1/2] [InstallAPI] Add support for aliased exports Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. --- .../clang/Basic/DiagnosticInstallAPIKinds.td | 1 + clang/include/clang/Driver/Options.td | 1 + .../include/clang/InstallAPI/DylibVerifier.h | 15 +- clang/include/clang/InstallAPI/MachO.h| 1 + clang/lib/InstallAPI/DylibVerifier.cpp| 24 + clang/test/InstallAPI/alias_list.test | 461 ++ clang/tools/clang-installapi/Options.cpp | 24 +- clang/tools/clang-installapi/Options.h| 3 + llvm/include/llvm/TextAPI/Utils.h | 12 + llvm/lib/TextAPI/Utils.cpp| 34 ++ 10 files changed, 569 insertions(+), 7 deletions(-) create mode 100644 clang/test/InstallAPI/alias_list.test diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index 396bff0146a373..91a40cd589b385 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">; def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">; def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; +def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..8c38acb72362c7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Visibility<[ClangOption, CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; +def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>; def extract_api : Flag<["-"], "extract-api">, Visibility<[ClangOption, CC1Option]>, Group, HelpText<"Extract API information">; diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h b/clang/include/clang/InstallAPI/DylibVerifier.h index 31de212fc423a5..f1a949d8f99394 100644 --- a/clang/include/clang/InstallAPI/DylibVerifier.h +++ b/clang/include/clang/InstallAPI/DylibVerifier.h @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor { DylibVerifier() = default; DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports, -DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered, -bool Demangle, StringRef DSYMPath) - : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode), -Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath), +AliasMap Aliases, DiagnosticsEngine *Diag, +VerificationMode Mode, bool Zippered, bool Demangle, +StringRef DSYMPath) + : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), +Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered), +Demangle(Demangle), DSYMPath(DSYMPath), Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {} Result verify(GlobalRecord *R, const FrontendAttrs *FA); @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor { void setTarget(const Target &T); /// Release ownership over exports. - std::unique_ptr getExports() { return std::move(Exports); } + std::unique_ptr getExports(); /// Get result of verification. Result getState() const { return Ctx.FrontendState; } @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor { // Reexported interfaces apart of the library. ReexportedInterfaces Reexports; + // Symbol aliases. + AliasMap Aliases; + // Controls what class of violations to report. VerificationMode Mode = VerificationMode::Invalid; diff --git a/clang/include/clang/InstallAPI/MachO.h b/clang/include/clang/InstallAPI/MachO.h index 854399f54ba6c8..9da91a62e23311 100644 --- a/clang/include/clang/InstallAPI/MachO.h +++ b/clang/include/clang/InstallAPI/MachO.h @@ -23,6 +23,7 @@ #include "llvm/TextAPI/TextAPIWriter.h" #incl
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
@@ -973,5 +978,24 @@ bool DylibVerifier::verifyBinaryAttrs(const ArrayRef ProvidedTargets, return true; } +std::unique_ptr DylibVerifier::getExports() { + for (const auto &[Alias, Base] : Aliases) { ributzka wrote: In that case I would update the function name to `takeExports`. https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/cyndyishida updated https://github.com/llvm/llvm-project/pull/88750 >From b2b54ad8ccf930a19327563a64c52c9f4013103f Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Thu, 11 Apr 2024 13:13:45 -0700 Subject: [PATCH 1/3] [InstallAPI] Add support for aliased exports Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. --- .../clang/Basic/DiagnosticInstallAPIKinds.td | 1 + clang/include/clang/Driver/Options.td | 1 + .../include/clang/InstallAPI/DylibVerifier.h | 15 +- clang/include/clang/InstallAPI/MachO.h| 1 + clang/lib/InstallAPI/DylibVerifier.cpp| 24 + clang/test/InstallAPI/alias_list.test | 461 ++ clang/tools/clang-installapi/Options.cpp | 24 +- clang/tools/clang-installapi/Options.h| 3 + llvm/include/llvm/TextAPI/Utils.h | 12 + llvm/lib/TextAPI/Utils.cpp| 34 ++ 10 files changed, 569 insertions(+), 7 deletions(-) create mode 100644 clang/test/InstallAPI/alias_list.test diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index 396bff0146a373..91a40cd589b385 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">; def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">; def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; +def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..8c38acb72362c7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Visibility<[ClangOption, CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; +def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>; def extract_api : Flag<["-"], "extract-api">, Visibility<[ClangOption, CC1Option]>, Group, HelpText<"Extract API information">; diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h b/clang/include/clang/InstallAPI/DylibVerifier.h index 31de212fc423a5..f1a949d8f99394 100644 --- a/clang/include/clang/InstallAPI/DylibVerifier.h +++ b/clang/include/clang/InstallAPI/DylibVerifier.h @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor { DylibVerifier() = default; DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports, -DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered, -bool Demangle, StringRef DSYMPath) - : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode), -Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath), +AliasMap Aliases, DiagnosticsEngine *Diag, +VerificationMode Mode, bool Zippered, bool Demangle, +StringRef DSYMPath) + : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), +Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered), +Demangle(Demangle), DSYMPath(DSYMPath), Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {} Result verify(GlobalRecord *R, const FrontendAttrs *FA); @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor { void setTarget(const Target &T); /// Release ownership over exports. - std::unique_ptr getExports() { return std::move(Exports); } + std::unique_ptr getExports(); /// Get result of verification. Result getState() const { return Ctx.FrontendState; } @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor { // Reexported interfaces apart of the library. ReexportedInterfaces Reexports; + // Symbol aliases. + AliasMap Aliases; + // Controls what class of violations to report. VerificationMode Mode = VerificationMode::Invalid; diff --git a/clang/include/clang/InstallAPI/MachO.h b/clang/include/clang/InstallAPI/MachO.h index 854399f54ba6c8..9da91a62e23311 100644 --- a/clang/include/clang/InstallAPI/MachO.h +++ b/clang/include/clang/InstallAPI/MachO.h @@ -23,6 +23,7 @@ #include "llvm/TextAPI/TextAPIWriter.h" #incl
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
cyndyishida wrote: ping, is there anything else needed to land this patch? https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
@@ -259,7 +259,10 @@ bool Options::processLinkerOptions(InputArgList &Args) { if (auto *Arg = Args.getLastArg(drv::OPT_umbrella)) LinkerOpts.ParentUmbrella = Arg->getValue(); - LinkerOpts.IsDylib = Args.hasArg(drv::OPT_dynamiclib); zixu-w wrote: Is this expected to get removed? https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/cyndyishida updated https://github.com/llvm/llvm-project/pull/88750 >From b2b54ad8ccf930a19327563a64c52c9f4013103f Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Thu, 11 Apr 2024 13:13:45 -0700 Subject: [PATCH 1/4] [InstallAPI] Add support for aliased exports Apple's ld supports alias_lists, described as ``` -alias_list filename The specified filename contains a list of aliases. The symbol name and its alias are on one line, separated by whitespace. Lines starting with # are ignored. ``` To handle this for installapi-produced TBD files, pass along the same input and account for it in verification. --- .../clang/Basic/DiagnosticInstallAPIKinds.td | 1 + clang/include/clang/Driver/Options.td | 1 + .../include/clang/InstallAPI/DylibVerifier.h | 15 +- clang/include/clang/InstallAPI/MachO.h| 1 + clang/lib/InstallAPI/DylibVerifier.cpp| 24 + clang/test/InstallAPI/alias_list.test | 461 ++ clang/tools/clang-installapi/Options.cpp | 24 +- clang/tools/clang-installapi/Options.h| 3 + llvm/include/llvm/TextAPI/Utils.h | 12 + llvm/lib/TextAPI/Utils.cpp| 34 ++ 10 files changed, 569 insertions(+), 7 deletions(-) create mode 100644 clang/test/InstallAPI/alias_list.test diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index 396bff0146a373..91a40cd589b385 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">; def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">; def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; +def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index e24626913add76..8c38acb72362c7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">, def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Visibility<[ClangOption, CC1Option]>; def exported__symbols__list : Separate<["-"], "exported_symbols_list">; +def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>; def extract_api : Flag<["-"], "extract-api">, Visibility<[ClangOption, CC1Option]>, Group, HelpText<"Extract API information">; diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h b/clang/include/clang/InstallAPI/DylibVerifier.h index 31de212fc423a5..f1a949d8f99394 100644 --- a/clang/include/clang/InstallAPI/DylibVerifier.h +++ b/clang/include/clang/InstallAPI/DylibVerifier.h @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor { DylibVerifier() = default; DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports, -DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered, -bool Demangle, StringRef DSYMPath) - : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode), -Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath), +AliasMap Aliases, DiagnosticsEngine *Diag, +VerificationMode Mode, bool Zippered, bool Demangle, +StringRef DSYMPath) + : Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), +Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered), +Demangle(Demangle), DSYMPath(DSYMPath), Exports(std::make_unique()), Ctx(VerifierContext{Diag}) {} Result verify(GlobalRecord *R, const FrontendAttrs *FA); @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor { void setTarget(const Target &T); /// Release ownership over exports. - std::unique_ptr getExports() { return std::move(Exports); } + std::unique_ptr getExports(); /// Get result of verification. Result getState() const { return Ctx.FrontendState; } @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor { // Reexported interfaces apart of the library. ReexportedInterfaces Reexports; + // Symbol aliases. + AliasMap Aliases; + // Controls what class of violations to report. VerificationMode Mode = VerificationMode::Invalid; diff --git a/clang/include/clang/InstallAPI/MachO.h b/clang/include/clang/InstallAPI/MachO.h index 854399f54ba6c8..9da91a62e23311 100644 --- a/clang/include/clang/InstallAPI/MachO.h +++ b/clang/include/clang/InstallAPI/MachO.h @@ -23,6 +23,7 @@ #include "llvm/TextAPI/TextAPIWriter.h" #incl
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
@@ -259,7 +259,10 @@ bool Options::processLinkerOptions(InputArgList &Args) { if (auto *Arg = Args.getLastArg(drv::OPT_umbrella)) LinkerOpts.ParentUmbrella = Arg->getValue(); - LinkerOpts.IsDylib = Args.hasArg(drv::OPT_dynamiclib); cyndyishida wrote: nope, looks like I was missing some test coverage, added one implicitly here https://github.com/llvm/llvm-project/pull/88750/files#diff-0b1bbd3584706760de8a4030db1b04120c2c7c1f640681be80114f59278988bfR22 https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/zixu-w approved this pull request. https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstallAPI] Add support for aliased exports (PR #88750)
https://github.com/cyndyishida closed https://github.com/llvm/llvm-project/pull/88750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits