From 5476bd943203096f52fd49b15638bbe1b48e012c Mon Sep 17 00:00:00 2001 From: Puyan Lotfi Date: Fri, 6 Sep 2019 19:59:59 +0000 Subject: [PATCH] [llvm-ifs] Improving detection of PlatformKind from triple for TBD generation. It was pointed out that I had hard-coded PlatformKind. This is rectifying that. Differential Revision: https://reviews.llvm.org/D67255 llvm-svn: 371248 --- llvm/test/tools/llvm-ifs/ios-tbd.ifs | 22 ++++++++++++++++++ llvm/test/tools/llvm-ifs/macos-tbd.ifs | 22 ++++++++++++++++++ llvm/test/tools/llvm-ifs/tvos-tbd.ifs | 22 ++++++++++++++++++ llvm/test/tools/llvm-ifs/watchos-tbd.ifs | 22 ++++++++++++++++++ llvm/tools/llvm-ifs/llvm-ifs.cpp | 38 ++++++++++++++++++++++++++------ 5 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 llvm/test/tools/llvm-ifs/ios-tbd.ifs create mode 100644 llvm/test/tools/llvm-ifs/macos-tbd.ifs create mode 100644 llvm/test/tools/llvm-ifs/tvos-tbd.ifs create mode 100644 llvm/test/tools/llvm-ifs/watchos-tbd.ifs diff --git a/llvm/test/tools/llvm-ifs/ios-tbd.ifs b/llvm/test/tools/llvm-ifs/ios-tbd.ifs new file mode 100644 index 0000000..13671b0 --- /dev/null +++ b/llvm/test/tools/llvm-ifs/ios-tbd.ifs @@ -0,0 +1,22 @@ +# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s + +# CHECK: --- !tapi-tbd-v3 +# CHECK-NEXT: archs: [ arm64 ] +# CHECK-NEXT: platform: ios +# CHECK-NEXT: flags: [ flat_namespace, not_app_extension_safe ] +# CHECK-NEXT: install-name: '' +# CHECK-NEXT: current-version: 0 +# CHECK-NEXT: compatibility-version: 0 +# CHECK-NEXT: objc-constraint: none +# CHECK-NEXT: exports: +# CHECK-NEXT: - archs: [ arm64 ] +# CHECK-NEXT: symbols: [ __Z3fooi ] +# CHECK-NEXT: ... + +--- !experimental-ifs-v1 +IfsVersion: 1.0 +Triple: arm64-apple-ios +ObjectFileFormat: TBD +Symbols: + __Z3fooi: { Type: Func } +... diff --git a/llvm/test/tools/llvm-ifs/macos-tbd.ifs b/llvm/test/tools/llvm-ifs/macos-tbd.ifs new file mode 100644 index 0000000..bd84806 --- /dev/null +++ b/llvm/test/tools/llvm-ifs/macos-tbd.ifs @@ -0,0 +1,22 @@ +# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s + +# CHECK: --- !tapi-tbd-v3 +# CHECK-NEXT: archs: [ arm64 ] +# CHECK-NEXT: platform: macosx +# CHECK-NEXT: flags: [ flat_namespace, not_app_extension_safe ] +# CHECK-NEXT: install-name: '' +# CHECK-NEXT: current-version: 0 +# CHECK-NEXT: compatibility-version: 0 +# CHECK-NEXT: objc-constraint: none +# CHECK-NEXT: exports: +# CHECK-NEXT: - archs: [ arm64 ] +# CHECK-NEXT: symbols: [ __Z3fooi ] +# CHECK-NEXT: ... + +--- !experimental-ifs-v1 +IfsVersion: 1.0 +Triple: arm64-apple-macosx +ObjectFileFormat: TBD +Symbols: + __Z3fooi: { Type: Func } +... diff --git a/llvm/test/tools/llvm-ifs/tvos-tbd.ifs b/llvm/test/tools/llvm-ifs/tvos-tbd.ifs new file mode 100644 index 0000000..08c8478 --- /dev/null +++ b/llvm/test/tools/llvm-ifs/tvos-tbd.ifs @@ -0,0 +1,22 @@ +# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s + +# CHECK: --- !tapi-tbd-v3 +# CHECK-NEXT: archs: [ arm64 ] +# CHECK-NEXT: platform: tvos +# CHECK-NEXT: flags: [ flat_namespace, not_app_extension_safe ] +# CHECK-NEXT: install-name: '' +# CHECK-NEXT: current-version: 0 +# CHECK-NEXT: compatibility-version: 0 +# CHECK-NEXT: objc-constraint: none +# CHECK-NEXT: exports: +# CHECK-NEXT: - archs: [ arm64 ] +# CHECK-NEXT: symbols: [ __Z3fooi ] +# CHECK-NEXT: ... + +--- !experimental-ifs-v1 +IfsVersion: 1.0 +Triple: arm64-apple-tvos +ObjectFileFormat: TBD +Symbols: + __Z3fooi: { Type: Func } +... diff --git a/llvm/test/tools/llvm-ifs/watchos-tbd.ifs b/llvm/test/tools/llvm-ifs/watchos-tbd.ifs new file mode 100644 index 0000000..74a9d96 --- /dev/null +++ b/llvm/test/tools/llvm-ifs/watchos-tbd.ifs @@ -0,0 +1,22 @@ +# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s + +# CHECK: --- !tapi-tbd-v3 +# CHECK-NEXT: archs: [ arm64 ] +# CHECK-NEXT: platform: watchos +# CHECK-NEXT: flags: [ flat_namespace, not_app_extension_safe ] +# CHECK-NEXT: install-name: '' +# CHECK-NEXT: current-version: 0 +# CHECK-NEXT: compatibility-version: 0 +# CHECK-NEXT: objc-constraint: none +# CHECK-NEXT: exports: +# CHECK-NEXT: - archs: [ arm64 ] +# CHECK-NEXT: symbols: [ __Z3fooi ] +# CHECK-NEXT: ... + +--- !experimental-ifs-v1 +IfsVersion: 1.0 +Triple: arm64-apple-watchos +ObjectFileFormat: TBD +Symbols: + __Z3fooi: { Type: Func } +... diff --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp index 3377985..1746357 100644 --- a/llvm/tools/llvm-ifs/llvm-ifs.cpp +++ b/llvm/tools/llvm-ifs/llvm-ifs.cpp @@ -154,8 +154,8 @@ template <> struct CustomMappingTraits> { IO.mapRequired(Sym.Name.c_str(), const_cast(Sym)); } }; -} // End yaml namespace -} // End llvm namespace +} // namespace yaml +} // namespace llvm // A cumulative representation of ELF stubs. // Both textual and binary stubs will read into and write from this object. @@ -196,8 +196,8 @@ template <> struct MappingTraits { IO.mapRequired("Symbols", Stub.Symbols); } }; -} // End yaml namespace -} // End llvm namespace +} // namespace yaml +} // namespace llvm static Expected> readInputFile(StringRef FilePath) { // Read in file. @@ -224,7 +224,7 @@ int writeTbdStub(const llvm::Triple &T, const std::set &Symbols, [](const llvm::Triple &T) -> llvm::Expected { switch (T.getArch()) { default: - return createStringError(errc::not_supported, "Invalid Architecture."); + return createStringError(errc::not_supported, "Invalid Architecture.\n"); case llvm::Triple::ArchType::x86: return AK_i386; case llvm::Triple::ArchType::x86_64: @@ -236,15 +236,39 @@ int writeTbdStub(const llvm::Triple &T, const std::set &Symbols, } }(T); + auto PlatformKindOrError = + [](const llvm::Triple &T) -> llvm::Expected { + if (T.isMacOSX()) + return llvm::MachO::PlatformKind::macOS; + if (T.isTvOS()) + return llvm::MachO::PlatformKind::tvOS; + if (T.isWatchOS()) + return llvm::MachO::PlatformKind::watchOS; + // Note: put isiOS last because tvOS and watchOS are also iOS according + // to the Triple. + if (T.isiOS()) + return llvm::MachO::PlatformKind::iOS; + + // TODO: Add an option for ForceTriple, but keep ForceFormat for now. + if (ForceFormat == "TBD") + return llvm::MachO::PlatformKind::macOS; + + return createStringError(errc::not_supported, "Invalid Platform.\n"); + }(T); + if (!ArchOrError) return -1; + if (!PlatformKindOrError) + return -1; + Architecture Arch = ArchOrError.get(); + PlatformKind Plat = PlatformKindOrError.get(); InterfaceFile File; - File.setFileType(FileType::TBD_V3); + File.setFileType(FileType::TBD_V3); // Only supporting v3 for now. File.setArchitectures(Arch); - File.setPlatform(PlatformKind::macOS); + File.setPlatform(Plat); for (const auto &Symbol : Symbols) { auto Name = Symbol.Name; -- 2.7.4