Merge "Update LD_SHOW_AUXV for recent AT_* changes." into main
diff --git a/docs/clang_fortify_anatomy.md b/docs/clang_fortify_anatomy.md
index 4b95fdc..46d3a71 100644
--- a/docs/clang_fortify_anatomy.md
+++ b/docs/clang_fortify_anatomy.md
@@ -147,8 +147,7 @@
void* mempcpy(void* __dst, const void* __src, size_t __n) __INTRODUCED_IN(23);
```
-Which is annotated with nothing special, except for Bionic's versioner, which
-is Android-specific (and orthogonal to FORTIFY anyway), so it will be ignored.
+Which is annotated with nothing special, so it will be ignored.
The [source for `mempcpy`] in Bionic's headers for is:
```c
diff --git a/libc/Android.bp b/libc/Android.bp
index 776f101..3b7ba31 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2978,13 +2978,6 @@
},
}
-// headers that will be placed on the include path when running versioner in bazel
-// this module should be a no-op in soong
-filegroup {
- name: "versioner-dependencies",
- srcs: ["versioner-dependencies/**/*"],
-}
-
filegroup {
name: "linux_capability_header",
srcs: ["kernel/uapi/linux/capability.h"],
diff --git a/libc/versioner-dependencies/arm/kernel_uapi_asm-arm b/libc/versioner-dependencies/arm/kernel_uapi_asm-arm
deleted file mode 120000
index 3c7584d..0000000
--- a/libc/versioner-dependencies/arm/kernel_uapi_asm-arm
+++ /dev/null
@@ -1 +0,0 @@
-../../kernel/uapi/asm-arm
\ No newline at end of file
diff --git a/libc/versioner-dependencies/arm64/kernel_uapi_asm-arm64 b/libc/versioner-dependencies/arm64/kernel_uapi_asm-arm64
deleted file mode 120000
index 7ee6fd2..0000000
--- a/libc/versioner-dependencies/arm64/kernel_uapi_asm-arm64
+++ /dev/null
@@ -1 +0,0 @@
-../../kernel/uapi/asm-arm64
\ No newline at end of file
diff --git a/libc/versioner-dependencies/common/clang-builtins b/libc/versioner-dependencies/common/clang-builtins
deleted file mode 120000
index 148dd2b..0000000
--- a/libc/versioner-dependencies/common/clang-builtins
+++ /dev/null
@@ -1 +0,0 @@
-../../../../prebuilts/clang-tools/linux-x86/clang-headers
\ No newline at end of file
diff --git a/libc/versioner-dependencies/common/kernel_android_uapi b/libc/versioner-dependencies/common/kernel_android_uapi
deleted file mode 120000
index fd78315..0000000
--- a/libc/versioner-dependencies/common/kernel_android_uapi
+++ /dev/null
@@ -1 +0,0 @@
-../../kernel/android/uapi/
\ No newline at end of file
diff --git a/libc/versioner-dependencies/common/kernel_uapi b/libc/versioner-dependencies/common/kernel_uapi
deleted file mode 120000
index d5cb8ee..0000000
--- a/libc/versioner-dependencies/common/kernel_uapi
+++ /dev/null
@@ -1 +0,0 @@
-../../kernel/uapi/
\ No newline at end of file
diff --git a/libc/versioner-dependencies/riscv64/kernel_uapi_asm-riscv64 b/libc/versioner-dependencies/riscv64/kernel_uapi_asm-riscv64
deleted file mode 120000
index 61353cb..0000000
--- a/libc/versioner-dependencies/riscv64/kernel_uapi_asm-riscv64
+++ /dev/null
@@ -1 +0,0 @@
-../../kernel/uapi/asm-riscv/
\ No newline at end of file
diff --git a/libc/versioner-dependencies/x86/kernel_uapi_asm-x86 b/libc/versioner-dependencies/x86/kernel_uapi_asm-x86
deleted file mode 120000
index 1b7a73d..0000000
--- a/libc/versioner-dependencies/x86/kernel_uapi_asm-x86
+++ /dev/null
@@ -1 +0,0 @@
-../../kernel/uapi/asm-x86/
\ No newline at end of file
diff --git a/libc/versioner-dependencies/x86_64/kernel_uapi_asm-x86 b/libc/versioner-dependencies/x86_64/kernel_uapi_asm-x86
deleted file mode 120000
index 1b7a73d..0000000
--- a/libc/versioner-dependencies/x86_64/kernel_uapi_asm-x86
+++ /dev/null
@@ -1 +0,0 @@
-../../kernel/uapi/asm-x86/
\ No newline at end of file
diff --git a/tools/NOTICE b/tools/NOTICE
index a4ec954..e69de29 100644
--- a/tools/NOTICE
+++ b/tools/NOTICE
@@ -1,32 +0,0 @@
-Copyright (C) 2016 The Android Open Source Project
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
--------------------------------------------------------------------
-
-Copyright (C) 2018 The Android Open Source Project
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
--------------------------------------------------------------------
-
diff --git a/tools/versioner/Android.bp b/tools/versioner/Android.bp
deleted file mode 100644
index cc4dbfa..0000000
--- a/tools/versioner/Android.bp
+++ /dev/null
@@ -1,7 +0,0 @@
-package {
- default_applicable_licenses: ["bionic_tools_license"],
-}
-
-subdirs = [
- "src",
-]
diff --git a/tools/versioner/README.md b/tools/versioner/README.md
deleted file mode 100644
index edb32be..0000000
--- a/tools/versioner/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-## versioner
-Use clang to verify the correctness of bionic's availability attributes against the NDK platform definitions.
-
-#### Build
-Build with `LLVM_BUILD_HOST_TOOLS=true mma -j48`
-
-#### Use
-`versioner -p platforms current dependencies`
diff --git a/tools/versioner/current b/tools/versioner/current
deleted file mode 120000
index 234dfe7..0000000
--- a/tools/versioner/current
+++ /dev/null
@@ -1 +0,0 @@
-../../libc/include
\ No newline at end of file
diff --git a/tools/versioner/dependencies b/tools/versioner/dependencies
deleted file mode 120000
index 4ec3391..0000000
--- a/tools/versioner/dependencies
+++ /dev/null
@@ -1 +0,0 @@
-../../libc/versioner-dependencies
\ No newline at end of file
diff --git a/tools/versioner/platforms/crtbegin.map.txt b/tools/versioner/platforms/crtbegin.map.txt
deleted file mode 100644
index b844c1e..0000000
--- a/tools/versioner/platforms/crtbegin.map.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-# This file lists the libc functions are included in `crtbegin.o` and not
-# exported by `libc.so`.
-
-CRTBEGIN {
- global:
- atexit; # arm64 x86 x86_64
-};
diff --git a/tools/versioner/platforms/libc.map.txt b/tools/versioner/platforms/libc.map.txt
deleted file mode 120000
index 8527b2e..0000000
--- a/tools/versioner/platforms/libc.map.txt
+++ /dev/null
@@ -1 +0,0 @@
-../../../libc/libc.map.txt
\ No newline at end of file
diff --git a/tools/versioner/run_tests.py b/tools/versioner/run_tests.py
deleted file mode 100755
index 396f895..0000000
--- a/tools/versioner/run_tests.py
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import subprocess
-import sys
-
-red = '\033[91m'
-green = '\033[92m'
-bold = '\033[1m'
-reset = '\033[0m'
-prefix_pass = bold + "[" + green + "PASS" + reset + bold + "]" + reset
-prefix_fail = bold + "[" + red + "FAIL" + reset + bold + "]" + reset
-
-
-def indent(text, spaces=4):
- text = text.decode("utf-8")
- prefix = " "
- return "\n".join([prefix + line for line in text.split("\n")])
-
-
-def run_test(test_name, path):
- os.chdir(path)
- process = subprocess.Popen(
- ["/bin/sh", "run.sh"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- (output, _) = process.communicate()
-
- if os.path.exists("expected_fail"):
- with open("expected_fail", "rb") as f:
- expected_output = f.read()
- if process.returncode == 0:
- print("{} {}: unexpected success:".format(prefix_fail, test_name))
- print("")
- print(" Expected:")
- print(indent(expected_output))
- print(" Actual:")
- print(indent(output))
- return False
- elif not output.endswith(expected_output):
- print("{} {}: expected output mismatch".format(
- prefix_fail, test_name))
- print("")
- print(" Expected:")
- print(indent(expected_output))
- print(" Actual:")
- print(indent(output))
- return False
- elif process.returncode != 0:
- print("{} {}: unexpected failure:".format(prefix_fail, test_name))
- print("")
- print(indent(output))
- return False
-
- print("{} {}".format(prefix_pass, test_name))
- return True
-
-
-def usage():
- print("Usage: run_tests.py [-f]")
- print(" -f\t\tdon't run slow tests")
- sys.exit(0)
-
-
-root_dir = os.path.dirname(os.path.realpath(__file__))
-test_dir = os.path.join(root_dir, "tests")
-tests = os.listdir(test_dir)
-run_slow = True
-
-if len(sys.argv) > 2:
- usage()
-elif len(sys.argv) == 2:
- if sys.argv[1] != "-f":
- usage()
- run_slow = False
-
-success = True
-for test in sorted(tests):
- if test.startswith("slow") and not run_slow:
- continue
- path = os.path.join(test_dir, test)
- if not os.path.isdir(path):
- continue
- if not run_test(test, path):
- success = False
-
-sys.exit(0 if success else 1)
diff --git a/tools/versioner/src/Android.bp b/tools/versioner/src/Android.bp
deleted file mode 100644
index 6551e77..0000000
--- a/tools/versioner/src/Android.bp
+++ /dev/null
@@ -1,46 +0,0 @@
-package {
- default_applicable_licenses: ["bionic_tools_license"],
-}
-
-cc_binary_host {
- name: "versioner",
-
- defaults: ["llvm-build-host-tools-defaults"],
-
- srcs: [
- "versioner.cpp",
- "Arch.cpp",
- "CompilationType.cpp",
- "DeclarationDatabase.cpp",
- "Driver.cpp",
- "Preprocessor.cpp",
- "SymbolDatabase.cpp",
- "SymbolFileParser.cpp",
- "Utils.cpp",
- "VFS.cpp",
- ],
-
- shared_libs: [
- "libclang-cpp_host",
- "libbase",
- ],
-
- cflags: [
- "-Wall",
- "-Wextra",
- "-Werror",
- "-Wno-unused-parameter",
- "-fno-omit-frame-pointer",
- ],
-
- target: {
- host: {
- cppflags: [
- "-fno-rtti",
- ],
- },
- windows: {
- enabled: false,
- },
- },
-}
diff --git a/tools/versioner/src/Arch.cpp b/tools/versioner/src/Arch.cpp
deleted file mode 100644
index d4d0208..0000000
--- a/tools/versioner/src/Arch.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Arch.h"
-
-#include <err.h>
-
-#include <string>
-
-std::string to_string(const Arch& arch) {
- switch (arch) {
- case Arch::arm:
- return "arm";
-
- case Arch::arm64:
- return "arm64";
-
- case Arch::riscv64:
- return "riscv64";
-
- case Arch::x86:
- return "x86";
-
- case Arch::x86_64:
- return "x86_64";
- }
-
- errx(1, "unknown arch '%zu'", size_t(arch));
-}
-
-static const std::unordered_map<std::string, Arch> arch_name_map{
- {"arm", Arch::arm},
- {"arm64", Arch::arm64},
- {"riscv64", Arch::riscv64},
- {"x86", Arch::x86},
- {"x86_64", Arch::x86_64},
-};
-
-std::optional<Arch> arch_from_string(const std::string& name) {
- auto it = arch_name_map.find(name);
- if (it == arch_name_map.end()) {
- return std::nullopt;
- }
- return std::make_optional(it->second);
-}
diff --git a/tools/versioner/src/Arch.h b/tools/versioner/src/Arch.h
deleted file mode 100644
index fd98abc..0000000
--- a/tools/versioner/src/Arch.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdlib.h>
-
-#include <array>
-#include <initializer_list>
-#include <optional>
-#include <set>
-#include <string>
-#include <unordered_map>
-
-enum class Arch : size_t {
- arm = 0,
- arm64,
- riscv64,
- x86,
- x86_64,
-};
-
-std::string to_string(const Arch& arch);
-std::optional<Arch> arch_from_string(const std::string& name);
-
-template <typename T>
-class ArchMapIterator;
-
-template <typename T>
-class ArchMap {
- public:
- ArchMap() {
- }
-
- ArchMap(std::initializer_list<std::pair<Arch, T>> initializer) {
- for (auto& pair : initializer) {
- this->operator[](pair.first) = pair.second;
- }
- }
-
- T& operator[](Arch arch) {
- return data_[size_t(arch)];
- }
-
- const T& operator[](Arch arch) const {
- return data_[size_t(arch)];
- }
-
- bool operator==(const ArchMap& other) const {
- for (size_t i = 0; i < data_.size(); ++i) {
- if (data_[i] != other.data_[i]) {
- return false;
- }
- }
- return true;
- }
-
- ArchMapIterator<T> begin() const {
- return ArchMapIterator<T>(*this, Arch::arm);
- }
-
- ArchMapIterator<T> end() const {
- return ArchMapIterator<T>(*this, Arch(size_t(Arch::x86_64) + 1));
- }
-
- private:
- std::array<T, size_t(Arch::x86_64) + 1> data_ = {};
-};
-
-template <typename T>
-class ArchMapIterator {
- const ArchMap<T>& map_;
- Arch arch_ = Arch::arm;
-
- public:
- ArchMapIterator() = delete;
-
- ArchMapIterator(const ArchMap<T>& map, Arch arch) : map_(map), arch_(arch) {
- }
-
- bool operator==(const ArchMapIterator<T>& rhs) const {
- return map_ == rhs.map_ && arch_ == rhs.arch_;
- }
-
- bool operator!=(const ArchMapIterator<T>& rhs) const {
- return !(*this == rhs);
- }
-
- ArchMapIterator& operator++() {
- arch_ = Arch(size_t(arch_) + 1);
- return *this;
- }
-
- ArchMapIterator operator++(int) {
- ArchMapIterator result = *this;
- ++*this;
- return result;
- }
-
- std::pair<const Arch&, const T&> operator*() const {
- return std::tie(arch_, map_[arch_]);
- }
-
- std::pair<const Arch&, const T&> operator->() const {
- return std::tie(arch_, map_[arch_]);
- }
-};
-
-static const std::set<Arch> supported_archs = {
- Arch::arm,
- Arch::arm64,
- Arch::riscv64,
- Arch::x86,
- Arch::x86_64,
-};
-
-static ArchMap<std::string> arch_targets = {
- { Arch::arm, "arm-linux-androideabi" },
- { Arch::arm64, "aarch64-linux-android" },
- { Arch::riscv64, "riscv64-linux-android" },
- { Arch::x86, "i686-linux-android" },
- { Arch::x86_64, "x86_64-linux-android" },
-};
-
-static const std::set<int> default_levels = {
- 14, 15, 16, 17, 18, 19, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34,
-};
-
-static const ArchMap<int> arch_min_api = {
- { Arch::arm, 9 },
- { Arch::arm64, 21 },
- { Arch::riscv64, 10000 },
- { Arch::x86, 9 },
- { Arch::x86_64, 21 },
-};
-
-static const std::unordered_map<std::string, int> api_codename_map{
- {"G", 9},
- {"I", 14},
- {"J", 16},
- {"J-MR1", 17},
- {"J-MR2", 18},
- {"K", 19},
- {"L", 21},
- {"L-MR1", 22},
- {"M", 23},
- {"N", 24},
- {"N-MR1", 25},
- {"O", 26},
- {"O-MR1", 27},
- {"P", 28},
- {"Q", 29},
- {"R", 30},
- {"S", 31},
- {"T", 33},
- {"U", 34},
-};
diff --git a/tools/versioner/src/CompilationType.cpp b/tools/versioner/src/CompilationType.cpp
deleted file mode 100644
index 7e7bb5d..0000000
--- a/tools/versioner/src/CompilationType.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "CompilationType.h"
-
-#include <sstream>
-#include <string>
-
-std::string to_string(const CompilationType& type) {
- std::stringstream ss;
- ss << to_string(type.arch) << "-" << type.api_level << " [" << (type.cpp ? "c++" : "c")
- << ", fob = " << type.file_offset_bits << "]";
- return ss.str();
-}
diff --git a/tools/versioner/src/CompilationType.h b/tools/versioner/src/CompilationType.h
deleted file mode 100644
index 2f4cf5c..0000000
--- a/tools/versioner/src/CompilationType.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdint.h>
-
-#include <functional>
-#include <utility>
-
-#include "Arch.h"
-
-struct CompilationType {
- Arch arch;
- bool cpp;
- int api_level;
- int file_offset_bits;
-
- private:
- auto tie() const {
- return std::tie(arch, cpp, api_level, file_offset_bits);
- }
-
- public:
- bool operator<(const CompilationType& other) const {
- return tie() < other.tie();
- }
-
- bool operator==(const CompilationType& other) const {
- return tie() == other.tie();
- }
-};
-
-namespace std {
-template <>
-struct hash<CompilationType> {
- size_t operator()(CompilationType type) const {
- struct {
- int32_t arch : 3;
- int32_t cpp : 1;
- int32_t api_level : 6;
- int32_t file_offset_bits : 1;
- int32_t padding : 21;
- } packed;
- packed.arch = static_cast<int32_t>(type.arch);
- packed.cpp = type.cpp;
- packed.api_level = type.api_level;
- packed.file_offset_bits = (type.file_offset_bits == 64);
- packed.padding = 0;
- int32_t value;
- memcpy(&value, &packed, sizeof(value));
- return std::hash<int32_t>()(value);
- }
-};
-}
-
-std::string to_string(const CompilationType& type);
diff --git a/tools/versioner/src/DeclarationDatabase.cpp b/tools/versioner/src/DeclarationDatabase.cpp
deleted file mode 100644
index 9794286..0000000
--- a/tools/versioner/src/DeclarationDatabase.cpp
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "DeclarationDatabase.h"
-
-#include <err.h>
-
-#include <iostream>
-#include <map>
-#include <mutex>
-#include <set>
-#include <sstream>
-#include <string>
-#include <utility>
-
-#include <clang/AST/AST.h>
-#include <clang/AST/Attr.h>
-#include <clang/AST/Mangle.h>
-#include <clang/AST/RecursiveASTVisitor.h>
-#include <clang/Frontend/ASTUnit.h>
-#include <llvm/Support/raw_ostream.h>
-
-using namespace clang;
-
-static bool shouldMangle(MangleContext* mangler, NamedDecl* decl) {
- // Passing a decl with static linkage to the mangler gives incorrect results.
- // Check some things ourselves before handing it off to the mangler.
- if (auto FD = dyn_cast<FunctionDecl>(decl)) {
- if (FD->isExternC()) {
- return false;
- }
-
- if (FD->isInExternCContext()) {
- return false;
- }
- }
-
- return mangler->shouldMangleDeclName(decl);
-}
-
-class Visitor : public RecursiveASTVisitor<Visitor> {
- HeaderDatabase& database;
- CompilationType type;
- SourceManager& src_manager;
- std::unique_ptr<MangleContext> mangler;
-
- public:
- Visitor(HeaderDatabase& database, CompilationType type, ASTContext& ctx)
- : database(database), type(type), src_manager(ctx.getSourceManager()) {
- mangler.reset(ItaniumMangleContext::create(ctx, ctx.getDiagnostics()));
- }
-
- std::string getDeclName(NamedDecl* decl) {
- if (auto var_decl = dyn_cast<VarDecl>(decl)) {
- if (!var_decl->isFileVarDecl()) {
- return "<local var>";
- }
- }
-
- // <math.h> maps fool onto foo on 32-bit, since long double is the same as double.
- if (auto asm_attr = decl->getAttr<AsmLabelAttr>()) {
- return asm_attr->getLabel().str();
- }
-
- // The decl might not have a name (e.g. bitfields).
- if (auto identifier = decl->getIdentifier()) {
- if (shouldMangle(mangler.get(), decl)) {
- std::string mangled;
- llvm::raw_string_ostream ss(mangled);
- mangler->mangleName(decl, ss);
- return mangled;
- }
-
- return identifier->getName().str();
- }
-
- return "<unnamed>";
- }
-
- bool VisitDeclaratorDecl(DeclaratorDecl* decl, SourceRange range) {
- // Skip declarations inside of functions (function arguments, variable declarations inside of
- // inline functions, etc).
- if (decl->getParentFunctionOrMethod()) {
- return true;
- }
-
- auto named_decl = dyn_cast<NamedDecl>(decl);
- if (!named_decl) {
- return true;
- }
-
- std::string declaration_name = getDeclName(named_decl);
- bool is_extern = named_decl->getFormalLinkage() == Linkage::External;
- bool is_definition = false;
- bool no_guard = false;
- bool fortify_inline = false;
-
- if (auto function_decl = dyn_cast<FunctionDecl>(decl)) {
- is_definition = function_decl->isThisDeclarationADefinition();
- } else if (auto var_decl = dyn_cast<VarDecl>(decl)) {
- if (!var_decl->isFileVarDecl()) {
- return true;
- }
-
- switch (var_decl->isThisDeclarationADefinition()) {
- case VarDecl::DeclarationOnly:
- is_definition = false;
- break;
-
- case VarDecl::Definition:
- is_definition = true;
- break;
-
- case VarDecl::TentativeDefinition:
- // Forbid tentative definitions in headers.
- fprintf(stderr, "ERROR: declaration '%s' is a tentative definition\n",
- declaration_name.c_str());
- decl->dump();
- abort();
- }
- } else {
- // We only care about function and variable declarations.
- return true;
- }
-
- if (decl->hasAttr<UnavailableAttr>()) {
- // Skip declarations that exist only for compile-time diagnostics.
- return true;
- }
-
- DeclarationAvailability availability;
-
- // Find and parse __ANDROID_AVAILABILITY_DUMP__ annotations.
- for (const AnnotateAttr* attr : decl->specific_attrs<AnnotateAttr>()) {
- llvm::StringRef annotation = attr->getAnnotation();
- if (annotation == "versioner_no_guard") {
- no_guard = true;
- } else if (annotation == "versioner_fortify_inline") {
- fortify_inline = true;
- } else {
- llvm::SmallVector<llvm::StringRef, 2> fragments;
- annotation.split(fragments, "=");
- if (fragments.size() != 2) {
- continue;
- }
-
- auto& global_availability = availability.global_availability;
- auto& arch_availability = availability.arch_availability;
- std::map<std::string, std::vector<int*>> prefix_map = {
- { "introduced_in", { &global_availability.introduced } },
- { "deprecated_in", { &global_availability.deprecated } },
- { "obsoleted_in", { &global_availability.obsoleted } },
- { "introduced_in_arm", { &arch_availability[Arch::arm].introduced } },
- { "introduced_in_x86", { &arch_availability[Arch::x86].introduced } },
- { "introduced_in_32",
- { &arch_availability[Arch::arm].introduced,
- &arch_availability[Arch::x86].introduced } },
- { "introduced_in_64",
- { &arch_availability[Arch::arm64].introduced,
- &arch_availability[Arch::riscv64].introduced,
- &arch_availability[Arch::x86_64].introduced } },
- };
-
- if (auto it = prefix_map.find(fragments[0].str()); it != prefix_map.end()) {
- int value;
- if (fragments[1].getAsInteger(10, value)) {
- errx(1, "invalid __ANDROID_AVAILABILITY_DUMP__ annotation: '%s'",
- annotation.str().c_str());
- }
-
- for (int* ptr : it->second) {
- *ptr = value;
- }
- }
- }
- }
-
- auto symbol_it = database.symbols.find(declaration_name);
- if (symbol_it == database.symbols.end()) {
- Symbol symbol = {.name = declaration_name };
- bool unused;
- std::tie(symbol_it, unused) = database.symbols.insert({declaration_name, symbol});
- }
-
- auto expansion_range = src_manager.getExpansionRange(range);
- auto filename = src_manager.getFilename(expansion_range.getBegin());
- if (filename != src_manager.getFilename(expansion_range.getEnd())) {
- errx(1, "expansion range filenames don't match");
- }
-
- Location location = {
- .filename = filename.str(),
- .start = {
- .line = src_manager.getExpansionLineNumber(expansion_range.getBegin()),
- .column = src_manager.getExpansionColumnNumber(expansion_range.getBegin()),
- },
- .end = {
- .line = src_manager.getExpansionLineNumber(expansion_range.getEnd()),
- .column = src_manager.getExpansionColumnNumber(expansion_range.getEnd()),
- }
- };
-
- // Find or insert an entry for the declaration.
- if (auto declaration_it = symbol_it->second.declarations.find(location);
- declaration_it != symbol_it->second.declarations.end()) {
- if (declaration_it->second.is_extern != is_extern ||
- declaration_it->second.is_definition != is_definition ||
- declaration_it->second.no_guard != no_guard ||
- declaration_it->second.fortify_inline != fortify_inline) {
- errx(1, "varying declaration of '%s' at %s:%u:%u", declaration_name.c_str(),
- location.filename.c_str(), location.start.line, location.start.column);
- }
- declaration_it->second.availability.insert(std::make_pair(type, availability));
- } else {
- Declaration declaration;
- declaration.name = declaration_name;
- declaration.location = location;
- declaration.is_extern = is_extern;
- declaration.is_definition = is_definition;
- declaration.no_guard = no_guard;
- declaration.fortify_inline = fortify_inline;
- declaration.availability.insert(std::make_pair(type, availability));
- symbol_it->second.declarations.insert(std::make_pair(location, declaration));
- }
-
- return true;
- }
-
- bool VisitDeclaratorDecl(DeclaratorDecl* decl) {
- return VisitDeclaratorDecl(decl, decl->getSourceRange());
- }
-
- bool TraverseLinkageSpecDecl(LinkageSpecDecl* decl) {
- // Make sure that we correctly calculate the SourceRange of a declaration that has a non-braced
- // extern "C"/"C++".
- if (!decl->hasBraces()) {
- DeclaratorDecl* child = nullptr;
- for (auto child_decl : decl->decls()) {
- if (child != nullptr) {
- errx(1, "LinkageSpecDecl has multiple children");
- }
-
- if (DeclaratorDecl* declarator_decl = dyn_cast<DeclaratorDecl>(child_decl)) {
- child = declarator_decl;
- } else {
- errx(1, "child of LinkageSpecDecl is not a DeclaratorDecl");
- }
- }
-
- return VisitDeclaratorDecl(child, decl->getSourceRange());
- }
-
- for (auto child : decl->decls()) {
- if (!TraverseDecl(child)) {
- return false;
- }
- }
- return true;
- }
-};
-
-bool DeclarationAvailability::merge(const DeclarationAvailability& other) {
-#define check_avail(expr) error |= (!this->expr.empty() && this->expr != other.expr);
- bool error = false;
-
- if (!other.global_availability.empty()) {
- check_avail(global_availability);
- this->global_availability = other.global_availability;
- }
-
- for (Arch arch : supported_archs) {
- if (!other.arch_availability[arch].empty()) {
- check_avail(arch_availability[arch]);
- this->arch_availability[arch] = other.arch_availability[arch];
- }
- }
-#undef check_avail
-
- return !error;
-}
-
-bool Declaration::calculateAvailability(DeclarationAvailability* output) const {
- DeclarationAvailability avail;
- for (const auto& it : this->availability) {
- if (!avail.merge(it.second)) {
- return false;
- }
- }
- *output = avail;
- return true;
-}
-
-bool Symbol::calculateAvailability(DeclarationAvailability* output) const {
- DeclarationAvailability avail;
- for (const auto& it : this->declarations) {
- // Don't merge availability for inline functions (because they shouldn't have any).
- if (it.second.is_definition) {
- continue;
- }
-
- DeclarationAvailability decl_availability;
- if (!it.second.calculateAvailability(&decl_availability)) {
- return false;
- abort();
- }
-
- if (!avail.merge(decl_availability)) {
- return false;
- }
- }
- *output = avail;
- return true;
-}
-
-bool Symbol::hasDeclaration(const CompilationType& type) const {
- for (const auto& decl_it : this->declarations) {
- for (const auto& compilation_it : decl_it.second.availability) {
- if (compilation_it.first == type) {
- return true;
- }
- }
- }
- return false;
-}
-
-void HeaderDatabase::parseAST(CompilationType type, ASTContext& ctx) {
- std::unique_lock<std::mutex> lock(this->mutex);
- Visitor visitor(*this, type, ctx);
- visitor.TraverseDecl(ctx.getTranslationUnitDecl());
-}
-
-std::string to_string(const AvailabilityValues& av) {
- std::stringstream ss;
-
- if (av.introduced != 0) {
- ss << "introduced = " << av.introduced << ", ";
- }
-
- if (av.deprecated != 0) {
- ss << "deprecated = " << av.deprecated << ", ";
- }
-
- if (av.obsoleted != 0) {
- ss << "obsoleted = " << av.obsoleted << ", ";
- }
-
- std::string result = ss.str();
- if (!result.empty()) {
- result = result.substr(0, result.length() - 2);
- }
- return result;
-}
-
-std::string to_string(const DeclarationType& type) {
- switch (type) {
- case DeclarationType::function:
- return "function";
- case DeclarationType::variable:
- return "variable";
- case DeclarationType::inconsistent:
- return "inconsistent";
- }
- abort();
-}
-
-std::string to_string(const DeclarationAvailability& decl_av) {
- std::stringstream ss;
- if (!decl_av.global_availability.empty()) {
- ss << to_string(decl_av.global_availability) << ", ";
- }
-
- for (const auto& it : decl_av.arch_availability) {
- if (!it.second.empty()) {
- ss << to_string(it.first) << ": " << to_string(it.second) << ", ";
- }
- }
-
- std::string result = ss.str();
- if (result.size() == 0) {
- return "no availability";
- }
-
- return result.substr(0, result.length() - 2);
-}
-
-std::string to_string(const Location& loc) {
- std::stringstream ss;
- ss << loc.filename << ":" << loc.start.line << ":" << loc.start.column;
- return ss.str();
-}
diff --git a/tools/versioner/src/DeclarationDatabase.h b/tools/versioner/src/DeclarationDatabase.h
deleted file mode 100644
index 9a45227..0000000
--- a/tools/versioner/src/DeclarationDatabase.h
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdio.h>
-
-#include <map>
-#include <mutex>
-#include <set>
-#include <string>
-#include <vector>
-
-#include <llvm/ADT/StringRef.h>
-
-#include "Arch.h"
-#include "CompilationType.h"
-#include "Utils.h"
-
-namespace clang {
-class ASTContext;
-class Decl;
-}
-
-enum class DeclarationType {
- function,
- variable,
- inconsistent,
-};
-
-struct AvailabilityValues {
- int introduced = 0;
- int deprecated = 0;
- int obsoleted = 0;
-
- bool empty() const {
- return !(introduced || deprecated || obsoleted);
- }
-
- bool operator==(const AvailabilityValues& rhs) const {
- return std::tie(introduced, deprecated, obsoleted) ==
- std::tie(rhs.introduced, rhs.deprecated, rhs.obsoleted);
- }
-
- bool operator!=(const AvailabilityValues& rhs) const {
- return !(*this == rhs);
- }
-};
-
-std::string to_string(const AvailabilityValues& av);
-
-struct DeclarationAvailability {
- AvailabilityValues global_availability;
- ArchMap<AvailabilityValues> arch_availability;
-
- bool empty() const {
- if (!global_availability.empty()) {
- return false;
- }
-
- for (const auto& it : arch_availability) {
- if (!it.second.empty()) {
- return false;
- }
- }
-
- return true;
- }
-
- bool operator==(const DeclarationAvailability& rhs) const {
- return std::tie(global_availability, arch_availability) ==
- std::tie(rhs.global_availability, rhs.arch_availability);
- }
-
- bool operator!=(const DeclarationAvailability& rhs) const {
- return !(*this == rhs);
- }
-
- // Returns false if the availability declarations conflict.
- bool merge(const DeclarationAvailability& other);
-};
-
-std::string to_string(const DeclarationAvailability& decl_av);
-
-struct FileLocation {
- unsigned line;
- unsigned column;
-
- bool operator<(const FileLocation& rhs) const {
- return std::tie(line, column) < std::tie(rhs.line, rhs.column);
- }
-
- bool operator==(const FileLocation& rhs) const {
- return std::tie(line, column) == std::tie(rhs.line, rhs.column);
- }
-};
-
-struct Location {
- std::string filename;
- FileLocation start;
- FileLocation end;
-
- bool operator<(const Location& rhs) const {
- return std::tie(filename, start, end) < std::tie(rhs.filename, rhs.start, rhs.end);
- }
-};
-
-std::string to_string(const Location& loc);
-
-struct Declaration {
- std::string name;
- Location location;
-
- bool is_extern;
- bool is_definition;
- bool no_guard;
- bool fortify_inline;
- std::map<CompilationType, DeclarationAvailability> availability;
-
- bool calculateAvailability(DeclarationAvailability* output) const;
- bool operator<(const Declaration& rhs) const {
- return location < rhs.location;
- }
-
- void dump(const std::string& base_path = "", FILE* out = stdout, unsigned indent = 0) const {
- std::string indent_str(indent, ' ');
- fprintf(out, "%s", indent_str.c_str());
-
- fprintf(out, "%s ", is_extern ? "extern" : "static");
- fprintf(out, "%s ", is_definition ? "definition" : "declaration");
- if (no_guard) {
- fprintf(out, "no_guard ");
- }
- if (fortify_inline) {
- fprintf(out, "fortify_inline ");
- }
- fprintf(out, "@ %s:%u:%u", StripPrefix(location.filename, base_path).str().c_str(),
- location.start.line, location.start.column);
-
- if (!availability.empty()) {
- DeclarationAvailability avail;
-
- fprintf(out, "\n%s ", indent_str.c_str());
- if (!calculateAvailability(&avail)) {
- fprintf(out, "invalid availability\n");
- } else {
- fprintf(out, "%s\n", to_string(avail).c_str());
- }
- }
- }
-};
-
-struct Symbol {
- std::string name;
- std::map<Location, Declaration> declarations;
-
- bool calculateAvailability(DeclarationAvailability* output) const;
- bool hasDeclaration(const CompilationType& type) const;
-
- bool operator<(const Symbol& rhs) const {
- return name < rhs.name;
- }
-
- bool operator==(const Symbol& rhs) const {
- return name == rhs.name;
- }
-
- void dump(const std::string& base_path = "", FILE* out = stdout) const {
- DeclarationAvailability availability;
- bool valid_availability = calculateAvailability(&availability);
- fprintf(out, " %s: ", name.c_str());
-
- if (valid_availability) {
- fprintf(out, "%s\n", to_string(availability).c_str());
- } else {
- fprintf(out, "invalid\n");
- }
-
- for (auto& it : declarations) {
- it.second.dump(base_path, out, 4);
- }
- }
-};
-
-class HeaderDatabase {
- std::mutex mutex;
-
- public:
- std::map<std::string, Symbol> symbols;
-
- void parseAST(CompilationType type, clang::ASTContext& ast);
-
- void dump(const std::string& base_path = "", FILE* out = stdout) const {
- fprintf(out, "HeaderDatabase contains %zu symbols:\n", symbols.size());
- for (const auto& pair : symbols) {
- pair.second.dump(base_path, out);
- }
- }
-};
diff --git a/tools/versioner/src/Driver.cpp b/tools/versioner/src/Driver.cpp
deleted file mode 100644
index 79672ac..0000000
--- a/tools/versioner/src/Driver.cpp
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Driver.h"
-
-#include <err.h>
-#include <string.h>
-
-#include <chrono>
-#include <mutex>
-#include <string>
-#include <thread>
-#include <unordered_map>
-#include <vector>
-
-#include <clang/AST/ASTConsumer.h>
-#include <clang/Basic/Diagnostic.h>
-#include <clang/Basic/TargetInfo.h>
-#include <clang/Driver/Compilation.h>
-#include <clang/Driver/Driver.h>
-#include <clang/Frontend/CompilerInstance.h>
-#include <clang/Frontend/CompilerInvocation.h>
-#include <clang/Frontend/FrontendAction.h>
-#include <clang/Frontend/FrontendActions.h>
-#include <clang/Frontend/TextDiagnosticPrinter.h>
-#include <clang/Frontend/Utils.h>
-#include <clang/FrontendTool/Utils.h>
-#include <llvm/ADT/IntrusiveRefCntPtr.h>
-#include <llvm/ADT/SmallVector.h>
-#include <llvm/ADT/StringRef.h>
-#include <llvm/Option/Option.h>
-#include <llvm/TargetParser/Host.h>
-#include <llvm/Support/VirtualFileSystem.h>
-
-#include "Arch.h"
-#include "DeclarationDatabase.h"
-#include "versioner.h"
-
-using namespace std::chrono_literals;
-using namespace std::string_literals;
-
-using namespace clang;
-
-class VersionerASTConsumer : public clang::ASTConsumer {
- public:
- HeaderDatabase* header_database;
- CompilationType type;
-
- VersionerASTConsumer(HeaderDatabase* header_database, CompilationType type)
- : header_database(header_database), type(type) {
- }
-
- void HandleTranslationUnit(ASTContext& ctx) override {
- header_database->parseAST(type, ctx);
- }
-};
-
-class VersionerASTAction : public clang::ASTFrontendAction {
- public:
- HeaderDatabase* header_database;
- CompilationType type;
-
- VersionerASTAction(HeaderDatabase* header_database, CompilationType type)
- : header_database(header_database), type(type) {
- }
-
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance&, llvm::StringRef) override {
- return std::make_unique<VersionerASTConsumer>(header_database, type);
- }
-};
-
-static IntrusiveRefCntPtr<DiagnosticsEngine> constructDiags() {
- IntrusiveRefCntPtr<DiagnosticOptions> diag_opts(new DiagnosticOptions());
- auto diag_printer = std::make_unique<TextDiagnosticPrinter>(llvm::errs(), diag_opts.get());
- IntrusiveRefCntPtr<DiagnosticIDs> diag_ids(new DiagnosticIDs());
- IntrusiveRefCntPtr<DiagnosticsEngine> diags(
- new DiagnosticsEngine(diag_ids.get(), diag_opts.get(), diag_printer.release()));
- return diags;
-}
-
-// clang's driver is slow compared to the work it performs to compile our headers.
-// Run it once to generate flags for each target, and memoize the results.
-static std::unordered_map<CompilationType, std::vector<std::string>> cc1_flags;
-static const char* filename_placeholder = "__VERSIONER_PLACEHOLDER__";
-static void generateTargetCC1Flags(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
- CompilationType type,
- const std::vector<std::string>& include_dirs) {
- std::vector<std::string> cmd = { "versioner" };
- if (type.cpp) {
- cmd.push_back("-std=gnu++11");
- cmd.push_back("-x");
- cmd.push_back("c++");
- } else {
- cmd.push_back("-std=gnu11");
- cmd.push_back("-x");
- cmd.push_back("c");
- }
-
- cmd.push_back("-fsyntax-only");
-
- cmd.push_back("-Wall");
- cmd.push_back("-Wextra");
- cmd.push_back("-Weverything");
- cmd.push_back("-Werror");
- cmd.push_back("-Wundef");
- cmd.push_back("-Wno-unused-macros");
- cmd.push_back("-Wno-unused-function");
- cmd.push_back("-Wno-unused-variable");
- cmd.push_back("-Wno-unknown-attributes");
- cmd.push_back("-Wno-pragma-once-outside-header");
-
- cmd.push_back("-target");
- cmd.push_back(arch_targets[type.arch]);
-
- cmd.push_back("-DANDROID");
- cmd.push_back("-D__BIONIC_VERSIONER=1");
- cmd.push_back("-D__ANDROID_API__="s + std::to_string(type.api_level));
- cmd.push_back("-D_FORTIFY_SOURCE=2");
- cmd.push_back("-D_GNU_SOURCE");
- cmd.push_back("-D_FILE_OFFSET_BITS="s + std::to_string(type.file_offset_bits));
-
- cmd.push_back("-nostdinc");
-
- if (add_include) {
- cmd.push_back("-include");
- cmd.push_back("android/versioning.h");
- }
-
- for (const auto& dir : include_dirs) {
- cmd.push_back("-isystem");
- cmd.push_back(dir);
- }
-
- cmd.push_back("-include");
- cmd.push_back(filename_placeholder);
- cmd.push_back("-");
-
- auto diags = constructDiags();
- driver::Driver driver("versioner", llvm::sys::getDefaultTargetTriple(), *diags, "versioner", vfs);
- driver.setCheckInputsExist(false);
-
- llvm::SmallVector<const char*, 32> driver_args;
- for (const std::string& str : cmd) {
- driver_args.push_back(str.c_str());
- }
-
- std::unique_ptr<driver::Compilation> Compilation(driver.BuildCompilation(driver_args));
- const driver::JobList& jobs = Compilation->getJobs();
- if (jobs.size() != 1) {
- errx(1, "driver returned %zu jobs for %s", jobs.size(), to_string(type).c_str());
- }
-
- const driver::Command& driver_cmd = llvm::cast<driver::Command>(*jobs.begin());
- const llvm::opt::ArgStringList& cc_args = driver_cmd.getArguments();
-
- if (cc_args.size() == 0) {
- errx(1, "driver returned empty command for %s", to_string(type).c_str());
- }
-
- std::vector<std::string> result(cc_args.begin(), cc_args.end());
-
- {
- static std::mutex cc1_init_mutex;
- std::unique_lock<std::mutex> lock(cc1_init_mutex);
- if (cc1_flags.count(type) > 0) {
- errx(1, "attemped to generate cc1 flags for existing CompilationType %s",
- to_string(type).c_str());
- }
-
- cc1_flags.emplace(std::make_pair(type, std::move(result)));
- }
-}
-
-static std::vector<const char*> getCC1Command(CompilationType type, const std::string& filename) {
- const auto& target_flag_it = cc1_flags.find(type);
- if (target_flag_it == cc1_flags.end()) {
- errx(1, "failed to find target flags for CompilationType %s", to_string(type).c_str());
- }
-
- std::vector<const char*> result;
- for (const std::string& flag : target_flag_it->second) {
- if (flag == "-disable-free") {
- continue;
- } else if (flag == filename_placeholder) {
- result.push_back(filename.c_str());
- } else {
- result.push_back(flag.c_str());
- }
- }
- return result;
-}
-
-void initializeTargetCC1FlagCache(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
- const std::set<CompilationType>& types,
- const std::unordered_map<Arch, CompilationRequirements>& reqs) {
- if (!cc1_flags.empty()) {
- errx(1, "reinitializing target CC1 flag cache?");
- }
-
- auto start = std::chrono::high_resolution_clock::now();
- std::vector<std::thread> threads;
- for (const CompilationType type : types) {
- threads.emplace_back([type, &vfs, &reqs]() {
- const auto& arch_req_it = reqs.find(type.arch);
- if (arch_req_it == reqs.end()) {
- errx(1, "CompilationRequirement map missing entry for CompilationType %s",
- to_string(type).c_str());
- }
-
- generateTargetCC1Flags(vfs, type, arch_req_it->second.dependencies);
- });
- }
- for (auto& thread : threads) {
- thread.join();
- }
- auto end = std::chrono::high_resolution_clock::now();
-
- if (verbose) {
- auto diff = (end - start) / 1.0ms;
- printf("Generated compiler flags for %zu targets in %0.2Lfms\n", types.size(), diff);
- }
-
- if (cc1_flags.empty()) {
- errx(1, "failed to initialize target CC1 flag cache");
- }
-}
-
-void compileHeader(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
- HeaderDatabase* header_database, CompilationType type,
- const std::string& filename) {
- auto diags = constructDiags();
- std::vector<const char*> cc1_flags = getCC1Command(type, filename);
- auto invocation = std::make_unique<CompilerInvocation>();
- if (!CompilerInvocation::CreateFromArgs(*invocation.get(), cc1_flags, *diags)) {
- errx(1, "failed to create CompilerInvocation");
- }
-
- clang::CompilerInstance Compiler;
-
- Compiler.setInvocation(std::move(invocation));
- Compiler.setDiagnostics(diags.get());
- Compiler.createFileManager(vfs);
-
- VersionerASTAction versioner_action(header_database, type);
- if (!Compiler.ExecuteAction(versioner_action)) {
- errx(1, "compilation generated warnings or errors");
- }
-
- if (diags->getNumWarnings() || diags->hasErrorOccurred()) {
- errx(1, "compilation generated warnings or errors");
- }
-}
diff --git a/tools/versioner/src/Driver.h b/tools/versioner/src/Driver.h
deleted file mode 100644
index 99e57ae..0000000
--- a/tools/versioner/src/Driver.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <set>
-#include <string>
-#include <unordered_map>
-
-#include <llvm/ADT/IntrusiveRefCntPtr.h>
-
-#include "Arch.h"
-#include "DeclarationDatabase.h"
-#include "VFS.h"
-
-struct CompilationRequirements {
- std::vector<std::string> headers;
- std::vector<std::string> dependencies;
-};
-
-void initializeTargetCC1FlagCache(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
- const std::set<CompilationType>& types,
- const std::unordered_map<Arch, CompilationRequirements>& reqs);
-
-void compileHeader(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
- HeaderDatabase* header_database, CompilationType type,
- const std::string& filename);
diff --git a/tools/versioner/src/Preprocessor.cpp b/tools/versioner/src/Preprocessor.cpp
deleted file mode 100644
index 74d5ba0..0000000
--- a/tools/versioner/src/Preprocessor.cpp
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Preprocessor.h"
-
-#include <err.h>
-#include <fcntl.h>
-#include <fts.h>
-#include <libgen.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <deque>
-#include <fstream>
-#include <string>
-#include <unordered_map>
-
-#include <llvm/ADT/StringRef.h>
-#include <llvm/ADT/Twine.h>
-#include <llvm/Support/FileSystem.h>
-#include <llvm/Support/Path.h>
-
-#include "Arch.h"
-#include "DeclarationDatabase.h"
-#include "versioner.h"
-
-using namespace std::string_literals;
-
-static DeclarationAvailability calculateRequiredGuard(const Declaration& declaration) {
- // To avoid redundant macro guards, the availability calculated by this function is the set
- // difference of 'targets marked-available' from 'targets the declaration is visible in'.
- // For example, a declaration that is visible always and introduced in 9 would return introduced
- // in 9, but the same declaration, except only visible in 9+ would return an empty
- // DeclarationAvailability.
-
- // This currently only handles __INTRODUCED_IN.
- // TODO: Do the same for __REMOVED_IN.
- int global_min_api_visible = 0;
- ArchMap<int> arch_visibility;
-
- for (const auto& it : declaration.availability) {
- const CompilationType& type = it.first;
-
- if (global_min_api_visible == 0 || global_min_api_visible > type.api_level) {
- global_min_api_visible = type.api_level;
- }
-
- if (arch_visibility[type.arch] == 0 || arch_visibility[type.arch] > type.api_level) {
- arch_visibility[type.arch] = type.api_level;
- }
- }
-
- DeclarationAvailability decl_av;
- if (!declaration.calculateAvailability(&decl_av)) {
- fprintf(stderr, "versioner: failed to calculate availability while preprocessing:\n");
- declaration.dump("", stderr, 2);
- exit(1);
- }
-
- D("Calculating required guard for %s:\n", declaration.name.c_str());
- D(" Declaration availability: %s\n", to_string(decl_av).c_str());
-
- if (verbose) {
- std::string arch_visibility_str;
- for (Arch arch : supported_archs) {
- if (arch_visibility[arch] != 0) {
- arch_visibility_str += to_string(arch);
- arch_visibility_str += ": ";
- arch_visibility_str += std::to_string(arch_visibility[arch]);
- arch_visibility_str += ", ";
- }
- }
- if (!arch_visibility_str.empty()) {
- arch_visibility_str.resize(arch_visibility_str.size() - 2);
- }
- D(" Declaration visibility: global = %d, arch = %s\n", global_min_api_visible,
- arch_visibility_str.c_str());
- }
-
- DeclarationAvailability result = decl_av;
- if (result.global_availability.introduced <= global_min_api_visible) {
- result.global_availability.introduced = 0;
- }
-
- for (Arch arch : supported_archs) {
- if (result.arch_availability[arch].introduced <= arch_visibility[arch] ||
- result.arch_availability[arch].introduced <= arch_min_api[arch]) {
- result.arch_availability[arch].introduced = 0;
- }
- }
-
- D(" Calculated result: %s\n", to_string(result).c_str());
- D("\n");
-
- return result;
-}
-
-static std::deque<std::string> readFileLines(const std::string& path) {
- std::ifstream is(path.c_str());
- std::deque<std::string> result;
- std::string line;
-
- while (std::getline(is, line)) {
- result.push_back(std::move(line));
- }
-
- return result;
-}
-
-static void writeFileLines(const std::string& path, const std::deque<std::string>& lines) {
- if (!mkdirs(dirname(path))) {
- err(1, "failed to create directory '%s'", dirname(path).c_str());
- }
-
- std::ofstream os(path.c_str(), std::ios_base::out | std::ios_base::trunc);
-
- for (const std::string& line : lines) {
- os << line << "\n";
- }
-}
-
-using GuardMap = std::map<Location, DeclarationAvailability>;
-
-static std::string generateGuardCondition(const DeclarationAvailability& avail) {
- // Logically orred expressions that constitute the macro guard.
- std::vector<std::string> expressions;
- static const std::vector<std::pair<std::string, std::set<Arch>>> arch_sets = {
- {"!defined(__LP64__)", {Arch::arm, Arch::x86}},
- {"defined(__LP64__)", {Arch::arm64, Arch::riscv64, Arch::x86_64}},
- };
- std::map<Arch, std::string> individual_archs = {
- { Arch::arm, "defined(__arm__)" },
- { Arch::arm64, "defined(__aarch64__)" },
- { Arch::riscv64, "defined(__riscv)" },
- { Arch::x86, "defined(__i386__)" },
- { Arch::x86_64, "defined(__x86_64__)" },
- };
-
- auto generate_guard = [](const std::string& arch_expr, int min_version) {
- if (min_version == 0) {
- return arch_expr;
- }
- return arch_expr + " && __ANDROID_API__ >= " + std::to_string(min_version);
- };
-
- D("Generating guard for availability: %s\n", to_string(avail).c_str());
- if (!avail.global_availability.empty()) {
- for (Arch arch : supported_archs) {
- if (!avail.arch_availability[arch].empty()) {
- errx(1, "attempted to generate guard with global and per-arch values: %s",
- to_string(avail).c_str());
- }
- }
-
- if (avail.global_availability.introduced == 0) {
- // We currently get here for the "__sF" symbol because it's marked __REMOVED_IN(23). This
- // symbol is the only use of __REMOVED_IN, and it's already guarded manually, so there's no
- // need to do anything.
- fprintf(stderr, "warning: attempted to generate guard with empty availability: %s\n",
- to_string(avail).c_str());
- return "";
- }
-
- if (avail.global_availability.introduced <= 9) {
- return "";
- }
-
- return "__ANDROID_API__ >= "s + std::to_string(avail.global_availability.introduced);
- }
-
- for (const auto& it : arch_sets) {
- const std::string& arch_expr = it.first;
- const std::set<Arch>& archs = it.second;
-
- D(" Checking arch set '%s'\n", arch_expr.c_str());
-
- int version = 0;
-
- // Find the architectures that need to check __ANDROID_API__ and verify that they check against
- // the same API level.
- for (Arch arch : archs) {
- const int arch_version = avail.arch_availability[arch].introduced;
- if (arch_version == 0) {
- continue;
- } else if (version == 0) {
- version = arch_version;
- } else if (version != arch_version) {
- D(" Skipping arch set, availability for %s doesn't match %s\n",
- to_string(*it.second.begin()).c_str(), to_string(arch).c_str());
- goto skip;
- }
- }
-
- // Verify that a non-zero version is acceptable to reuse for other archs with a higher minimum
- // API, like riscv64. (e.g. It's OK to reuse an (__ANDROID_API__ >= 24) check if the arch's
- // minimum API is 35.)
- if (version != 0) {
- for (Arch arch : archs) {
- const int arch_version = avail.arch_availability[arch].introduced;
- if (arch_version == 0 && version > arch_min_api[arch]) {
- D(" Skipping arch set, availability for %s doesn't match %s\n",
- to_string(*it.second.begin()).c_str(), to_string(arch).c_str());
- goto skip;
- }
- }
- }
-
- expressions.emplace_back(generate_guard(arch_expr, version));
-
- D(" Generated expression '%s'\n", expressions.rbegin()->c_str());
-
- for (Arch arch : archs) {
- individual_archs.erase(arch);
- }
-
- skip:
- continue;
- }
-
- for (const auto& it : individual_archs) {
- const std::string& arch_expr = it.second;
- int introduced = avail.arch_availability[it.first].introduced;
- expressions.emplace_back(generate_guard(arch_expr, introduced));
- }
-
- if (expressions.size() == 0) {
- errx(1, "generated empty guard for availability %s", to_string(avail).c_str());
- } else if (expressions.size() == 1) {
- return expressions[0];
- }
-
- return "("s + Join(expressions, ") || (") + ")";
-}
-
-// Assumes that nothing weird is happening (e.g. having the semicolon be in a macro).
-static FileLocation findNextSemicolon(const std::deque<std::string>& lines, FileLocation start) {
- unsigned current_line = start.line;
- unsigned current_column = start.column;
- while (current_line <= lines.size()) {
- size_t result = lines[current_line - 1].find_first_of(';', current_column - 1);
-
- if (result != std::string::npos) {
- FileLocation loc = {
- .line = current_line,
- .column = unsigned(result) + 1,
- };
-
- return loc;
- }
-
- ++current_line;
- current_column = 0;
- }
-
- errx(1, "failed to find semicolon starting from %u:%u", start.line, start.column);
-}
-
-// Merge adjacent blocks with identical guards.
-static void mergeGuards(std::deque<std::string>& file_lines, GuardMap& guard_map) {
- if (guard_map.size() < 2) {
- return;
- }
-
- auto current = guard_map.begin();
- auto next = current;
- ++next;
-
- while (next != guard_map.end()) {
- if (current->second != next->second) {
- ++current;
- ++next;
- continue;
- }
-
- // Scan from the end of current to the beginning of next.
- bool in_block_comment = false;
- bool valid = true;
-
- FileLocation current_location = current->first.end;
- FileLocation end_location = next->first.start;
-
- auto nextLine = [¤t_location]() {
- ++current_location.line;
- current_location.column = 1;
- };
-
- auto nextCol = [&file_lines, ¤t_location, &nextLine]() {
- if (current_location.column == file_lines[current_location.line - 1].length()) {
- nextLine();
- } else {
- ++current_location.column;
- }
- };
-
- // The end location will point to the semicolon, which we don't want to read, so skip it.
- nextCol();
-
- while (current_location < end_location) {
- const std::string& line = file_lines[current_location.line - 1];
- size_t line_index = current_location.column - 1;
-
- if (in_block_comment) {
- size_t pos = line.find("*/", line_index);
- if (pos == std::string::npos) {
- D("Didn't find block comment terminator, skipping line\n");
- nextLine();
- continue;
- } else {
- D("Found block comment terminator\n");
- in_block_comment = false;
- current_location.column = pos + 2;
- nextCol();
- continue;
- }
- } else {
- size_t pos = line.find_first_not_of(" \t", line_index);
- if (pos == std::string::npos) {
- nextLine();
- continue;
- }
-
- current_location.column = pos + 1;
- if (line[pos] != '/') {
- valid = false;
- break;
- }
-
- nextCol();
- if (line.length() <= pos + 1) {
- // Trailing slash at the end of a line?
- D("Trailing slash at end of line\n");
- valid = false;
- break;
- }
-
- if (line[pos + 1] == '/') {
- // C++ style comment
- nextLine();
- } else if (line[pos + 1] == '*') {
- // Block comment
- nextCol();
- in_block_comment = true;
- D("In a block comment\n");
- } else {
- // Garbage?
- D("Unexpected output after /: %s\n", line.substr(pos).c_str());
- valid = false;
- break;
- }
- }
- }
-
- if (!valid) {
- D("Not merging blocks %s and %s\n", to_string(current->first).c_str(),
- to_string(next->first).c_str());
- ++current;
- ++next;
- continue;
- }
-
- D("Merging blocks %s and %s\n", to_string(current->first).c_str(),
- to_string(next->first).c_str());
-
- Location merged = current->first;
- merged.end = next->first.end;
-
- DeclarationAvailability avail = current->second;
-
- guard_map.erase(current);
- guard_map.erase(next);
- bool unused;
- std::tie(current, unused) = guard_map.insert(std::make_pair(merged, avail));
- next = current;
- ++next;
- }
-}
-
-static void rewriteFile(const std::string& output_path, std::deque<std::string>& file_lines,
- const GuardMap& guard_map) {
- for (auto it = guard_map.rbegin(); it != guard_map.rend(); ++it) {
- const Location& loc = it->first;
- const DeclarationAvailability& avail = it->second;
-
- std::string condition = generateGuardCondition(avail);
- if (condition.empty()) {
- continue;
- }
-
- std::string prologue = "\n#if "s + condition + "\n";
- std::string epilogue = "\n#endif /* " + condition + " */\n";
-
- file_lines[loc.end.line - 1].insert(loc.end.column, epilogue);
- file_lines[loc.start.line - 1].insert(loc.start.column - 1, prologue);
- }
-
- if (verbose) {
- printf("Preprocessing %s...\n", output_path.c_str());
- }
- writeFileLines(output_path, file_lines);
-}
-
-bool preprocessHeaders(const std::string& dst_dir, const std::string& src_dir,
- HeaderDatabase* database) {
- std::unordered_map<std::string, GuardMap> guards;
- std::unordered_map<std::string, std::deque<std::string>> file_lines;
-
- for (const auto& symbol_it : database->symbols) {
- const Symbol& symbol = symbol_it.second;
-
- for (const auto& decl_it : symbol.declarations) {
- const Location& location = decl_it.first;
- const Declaration& decl = decl_it.second;
-
- if (decl.no_guard) {
- // No guard required.
- continue;
- }
-
- DeclarationAvailability macro_guard = calculateRequiredGuard(decl);
- if (!macro_guard.empty()) {
- guards[location.filename][location] = macro_guard;
- }
- }
- }
-
- // Copy over the original headers before preprocessing.
- char* fts_paths[2] = { const_cast<char*>(src_dir.c_str()), nullptr };
- std::unique_ptr<FTS, decltype(&fts_close)> fts(fts_open(fts_paths, FTS_LOGICAL, nullptr),
- fts_close);
- if (!fts) {
- err(1, "failed to open directory %s", src_dir.c_str());
- }
-
- while (FTSENT* ent = fts_read(fts.get())) {
- llvm::StringRef path = ent->fts_path;
- if (!path.starts_with(src_dir)) {
- err(1, "path '%s' doesn't start with source dir '%s'", ent->fts_path, src_dir.c_str());
- }
-
- if (ent->fts_info != FTS_F) {
- continue;
- }
-
- std::string rel_path = path.substr(src_dir.length() + 1).str();
- std::string dst_path = dst_dir + "/" + rel_path;
- llvm::StringRef parent_path = llvm::sys::path::parent_path(dst_path);
- if (llvm::sys::fs::create_directories(parent_path)) {
- errx(1, "failed to ensure existence of directory '%s'", parent_path.str().c_str());
- }
- if (llvm::sys::fs::copy_file(path, dst_path)) {
- errx(1, "failed to copy '%s/%s' to '%s'", src_dir.c_str(), path.str().c_str(),
- dst_path.c_str());
- }
- }
-
- for (const auto& file_it : guards) {
- file_lines[file_it.first] = readFileLines(file_it.first);
- }
-
- for (auto& file_it : guards) {
- llvm::StringRef file_path = file_it.first;
- GuardMap& orig_guard_map = file_it.second;
-
- // The end positions given to us are the end of the declaration, which is some point before the
- // semicolon. Fix up the end positions by scanning for the next semicolon.
- GuardMap guard_map;
- for (const auto& it : orig_guard_map) {
- Location loc = it.first;
- loc.end = findNextSemicolon(file_lines[file_path.str()], loc.end);
- guard_map[loc] = it.second;
- }
-
- // TODO: Make sure that the Locations don't overlap.
- // TODO: Merge adjacent non-identical guards.
- mergeGuards(file_lines[file_path.str()], guard_map);
-
- if (!file_path.starts_with(src_dir)) {
- errx(1, "input file %s is not in %s\n", file_path.str().c_str(), src_dir.c_str());
- }
-
- // rel_path has a leading slash.
- llvm::StringRef rel_path = file_path.substr(src_dir.size(), file_path.size() - src_dir.size());
- std::string output_path = (llvm::Twine(dst_dir) + rel_path).str();
-
- rewriteFile(output_path, file_lines[file_path.str()], guard_map);
- }
-
- return true;
-}
diff --git a/tools/versioner/src/Preprocessor.h b/tools/versioner/src/Preprocessor.h
deleted file mode 100644
index 2a17534..0000000
--- a/tools/versioner/src/Preprocessor.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <string>
-
-class HeaderDatabase;
-
-bool preprocessHeaders(const std::string& preprocessor_output_path, const std::string& source_dir,
- HeaderDatabase* database);
diff --git a/tools/versioner/src/SymbolDatabase.cpp b/tools/versioner/src/SymbolDatabase.cpp
deleted file mode 100644
index c483c0f..0000000
--- a/tools/versioner/src/SymbolDatabase.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "SymbolDatabase.h"
-
-#include "SymbolFileParser.h"
-
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <fstream>
-#include <streambuf>
-#include <string>
-#include <unordered_set>
-
-#include <llvm/ADT/SmallVector.h>
-#include <llvm/ADT/StringRef.h>
-#include <llvm/Object/Binary.h>
-#include <llvm/Object/ELFObjectFile.h>
-
-#include "versioner.h"
-
-using namespace llvm;
-using namespace llvm::object;
-
-std::unordered_set<std::string> getSymbols(const std::string& filename) {
- std::unordered_set<std::string> result;
- auto binaryOrError = createBinary(filename);
- if (!binaryOrError) {
- errx(1, "failed to open library at %s: %s\n", filename.c_str(),
- llvm::toString(binaryOrError.takeError()).c_str());
- }
-
- ELFObjectFileBase* elf = dyn_cast_or_null<ELFObjectFileBase>(binaryOrError.get().getBinary());
- if (!elf) {
- errx(1, "failed to parse %s as ELF", filename.c_str());
- }
-
- for (const ELFSymbolRef symbol : elf->getDynamicSymbolIterators()) {
- Expected<StringRef> symbolNameOrError = symbol.getName();
-
- if (!symbolNameOrError) {
- errx(1, "failed to get symbol name for symbol in %s: %s", filename.c_str(),
- llvm::toString(symbolNameOrError.takeError()).c_str());
- }
-
- result.insert(symbolNameOrError.get().str());
- }
-
- return result;
-}
-
-static std::map<std::string, NdkSymbolType> parsePlatform(const CompilationType& type,
- const std::string& platform_dir) {
- static const std::pair<const char*, bool> wanted_files[] = {
- {"crtbegin.map.txt", false},
- {"libc.map.txt", true},
- };
-
- std::map<std::string, NdkSymbolType> result;
-
- for (auto&& [filename, required] : wanted_files) {
- std::string path = platform_dir + "/" + filename;
-
- std::optional<SymbolMap> symbols = parseSymbolFile(path, type);
- if (!symbols) {
- if (required) {
- errx(1, "error: failed to load: %s", path.c_str());
- }
- continue;
- }
-
- for (auto&& [symbol_name, symbol_type] : *symbols) {
- if (symbol_name.empty()) {
- continue;
- }
-
- if (result.count(symbol_name) != 0) {
- if (strict) {
- printf("duplicated symbol '%s' in '%s'\n", symbol_name.c_str(), path.c_str());
- }
- }
-
- result[symbol_name] = symbol_type;
- }
- }
-
- return result;
-}
-
-std::optional<NdkSymbolDatabase> parsePlatforms(const std::set<CompilationType>& types,
- const std::string& platform_dir) {
- NdkSymbolDatabase result;
- for (const CompilationType& type : types) {
- std::map<std::string, NdkSymbolType> symbols = parsePlatform(type, platform_dir);
- for (const auto& it : symbols) {
- result[it.first][type] = it.second;
- }
- }
- return std::make_optional(std::move(result));
-}
diff --git a/tools/versioner/src/SymbolDatabase.h b/tools/versioner/src/SymbolDatabase.h
deleted file mode 100644
index dbbba4f..0000000
--- a/tools/versioner/src/SymbolDatabase.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <map>
-#include <optional>
-#include <set>
-#include <string>
-#include <unordered_set>
-
-#include "DeclarationDatabase.h"
-
-using LibrarySymbolDatabase = std::unordered_set<std::string>;
-std::unordered_set<std::string> getSymbols(const std::string& filename);
-
-enum class NdkSymbolType {
- function,
- variable,
-};
-
-using NdkSymbolDatabase = std::map<std::string, std::map<CompilationType, NdkSymbolType>>;
-std::optional<NdkSymbolDatabase> parsePlatforms(const std::set<CompilationType>& types,
- const std::string& platform_dir);
diff --git a/tools/versioner/src/SymbolFileParser.cpp b/tools/versioner/src/SymbolFileParser.cpp
deleted file mode 100644
index 1b4adae..0000000
--- a/tools/versioner/src/SymbolFileParser.cpp
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "SymbolFileParser.h"
-
-#include "Arch.h"
-#include "CompilationType.h"
-
-#include <android-base/strings.h>
-
-#include <fstream>
-#include <ios>
-#include <optional>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include <err.h>
-
-namespace {
-
-using TagList = std::vector<std::string>;
-
-struct SymbolEnt {
- std::string name;
- TagList tags;
-};
-
-using SymbolList = std::vector<SymbolEnt>;
-
-struct Version {
- std::string name;
- std::string base;
- SymbolList symbols;
- TagList tags;
-};
-
-class SymbolFileParser {
- public:
- SymbolFileParser(const std::string& path, const CompilationType& type)
- : file_path(path),
- compilation_type(type),
- api_level_arch_prefix("api-level-" + to_string(type.arch) + "="),
- intro_arch_perfix("introduced-" + to_string(type.arch) + "="),
- file(path, std::ios_base::in),
- curr_line_num(0) {
- }
-
- // Parse the version script and build a symbol map.
- std::optional<SymbolMap> parse() {
- if (!file) {
- return std::nullopt;
- }
-
- SymbolMap symbol_map;
- while (hasNextLine()) {
- auto&& version = parseVersion();
- if (!version) {
- return std::nullopt;
- }
-
- if (isInArch(version->tags) && isInApi(version->tags)) {
- for (auto&& [name, tags] : version->symbols) {
- if (isInArch(tags) && isInApi(tags)) {
- symbol_map[name] = getSymbolType(tags);
- }
- }
- }
- }
- return std::make_optional(std::move(symbol_map));
- }
-
- private:
- // Read a non-empty line from the input and split at the first '#' character.
- bool hasNextLine() {
- std::string line;
- while (std::getline(file, line)) {
- ++curr_line_num;
-
- size_t hash_pos = line.find('#');
- curr_line = android::base::Trim(line.substr(0, hash_pos));
- if (!curr_line.empty()) {
- if (hash_pos != std::string::npos) {
- curr_tags = parseTags(line.substr(hash_pos + 1));
- } else {
- curr_tags.clear();
- }
- return true;
- }
- }
- return false;
- }
-
- // Tokenize the tags after the '#' character.
- static std::vector<std::string> parseTags(const std::string& tags_line) {
- std::vector<std::string> tags = android::base::Split(tags_line, " \t");
- tags.erase(std::remove(tags.begin(), tags.end(), ""), tags.end());
- return tags;
- }
-
- // Parse a version scope.
- std::optional<Version> parseVersion() {
- size_t start_line_num = curr_line_num;
-
- std::string::size_type lparen_pos = curr_line.find('{');
- if (lparen_pos == std::string::npos) {
- errx(1, "%s:%zu: error: expected '{' cannot be found in this line",
- file_path.c_str(), curr_line_num);
- }
-
- // Record the version name and version tags (before hasNextLine()).
- std::string name = android::base::Trim(curr_line.substr(0, lparen_pos));
- TagList tags = std::move(curr_tags);
-
- // Read symbol lines.
- SymbolList symbols;
- bool global_scope = true;
- bool cpp_scope = false;
- while (hasNextLine()) {
- size_t rparen_pos = curr_line.find('}');
- if (rparen_pos != std::string::npos) {
- size_t semicolon_pos = curr_line.find(';', rparen_pos + 1);
- if (semicolon_pos == std::string::npos) {
- errx(1, "%s:%zu: error: the line that ends a scope must end with ';'",
- file_path.c_str(), curr_line_num);
- }
-
- if (cpp_scope) {
- cpp_scope = false;
- continue;
- }
-
- std::string base = android::base::Trim(
- curr_line.substr(rparen_pos + 1, semicolon_pos - 1));
-
- return std::make_optional(Version{std::move(name), std::move(base),
- std::move(symbols), std::move(tags)});
- }
-
- if (android::base::StartsWith(curr_line, R"(extern "C++" {)")) {
- cpp_scope = true;
- continue;
- }
-
- if (cpp_scope) {
- continue;
- }
-
- size_t colon_pos = curr_line.find(':');
- if (colon_pos != std::string::npos) {
- std::string visibility =
- android::base::Trim(curr_line.substr(0, colon_pos));
-
- if (visibility == "global") {
- global_scope = true;
- } else if (visibility == "local") {
- global_scope = false;
- } else {
- errx(1, "%s:%zu: error: unknown version visibility: %s",
- file_path.c_str(), curr_line_num, visibility.c_str());
- }
- continue;
- }
-
- if (global_scope) {
- size_t semicolon_pos = curr_line.find(';');
- if (semicolon_pos == std::string::npos) {
- errx(1, "%s:%zu: error: symbol name line must end with ';'",
- file_path.c_str(), curr_line_num);
- }
-
- std::string symbol_name =
- android::base::Trim(curr_line.substr(0, semicolon_pos));
-
- size_t asterisk_pos = symbol_name.find('*');
- if (asterisk_pos != std::string::npos) {
- errx(1, "%s:%zu: error: global symbol name must not have wildcards",
- file_path.c_str(), curr_line_num);
- }
-
- symbols.push_back(SymbolEnt{std::move(symbol_name),
- std::move(curr_tags)});
- }
- }
-
- errx(1, "%s:%zu: error: scope started from %zu must be closed before EOF",
- file_path.c_str(), curr_line_num, start_line_num);
- }
-
- static NdkSymbolType getSymbolType(const TagList& tags) {
- for (auto&& tag : tags) {
- if (tag == "var") {
- return NdkSymbolType::variable;
- }
- }
- return NdkSymbolType::function;
- }
-
- // isInArch() returns true if there is a matching arch-specific tag or there
- // are no arch-specific tags.
- bool isInArch(const TagList& tags) const {
- bool has_arch_tags = false;
- for (auto&& tag : tags) {
- std::optional<Arch> arch = arch_from_string(tag);
- if (!arch) {
- continue;
- }
- if (*arch == compilation_type.arch) {
- return true;
- }
- has_arch_tags = true;
- }
- return !has_arch_tags;
- }
-
- // isInApi() returns true if the specified API level is equal to the
- // api-level tag, or the specified API level is greater than or equal to the
- // introduced tag, or there are no api-level or introduced tags.
- bool isInApi(const TagList& tags) const {
- bool api_level_arch = false;
- bool intro_arch = false;
- std::string api_level;
- std::string intro;
-
- for (const std::string& tag : tags) {
- // Check api-level tags.
- if (android::base::StartsWith(tag, "api-level=") && !api_level_arch) {
- api_level = tag;
- continue;
- }
- if (android::base::StartsWith(tag, api_level_arch_prefix)) {
- api_level = tag;
- api_level_arch = true;
- continue;
- }
-
- // Check introduced tags.
- if (android::base::StartsWith(tag, "introduced=") && !intro_arch) {
- intro = tag;
- continue;
- }
- if (android::base::StartsWith(tag, intro_arch_perfix)) {
- intro = tag;
- intro_arch = true;
- continue;
- }
- }
-
- if (intro.empty() && api_level.empty()) {
- return true;
- }
-
- if (!api_level.empty()) {
- // If an api-level tag is specified, it must be an exact match (mainly
- // for versioner unit tests).
- return compilation_type.api_level == parseApiLevelValue(api_level);
- }
-
- return compilation_type.api_level >= parseApiLevelValue(intro);
- }
-
- // Parse the integer API level from api-level or introduced tags.
- int parseApiLevelValue(const std::string& tag) const {
- std::string api_level = tag.substr(tag.find('=') + 1);
- auto it = api_codename_map.find(api_level);
- if (it != api_codename_map.end()) {
- return it->second;
- }
- if (api_level.find_first_not_of("0123456789") != std::string::npos) {
- errx(1, "%s:%zu: error: unknown API level codename specified: \"%s\"",
- file_path.c_str(), curr_line_num, tag.c_str());
- }
- return std::stoi(api_level);
- }
-
- private:
- const std::string& file_path;
- const CompilationType& compilation_type;
- const std::string api_level_arch_prefix;
- const std::string intro_arch_perfix;
-
- std::ifstream file;
- std::string curr_line;
- std::vector<std::string> curr_tags;
- size_t curr_line_num;
-};
-
-} // anonymous namespace
-
-
-std::optional<SymbolMap> parseSymbolFile(const std::string& file_path,
- const CompilationType& type) {
- SymbolFileParser parser(file_path, type);
- return parser.parse();
-}
diff --git a/tools/versioner/src/SymbolFileParser.h b/tools/versioner/src/SymbolFileParser.h
deleted file mode 100644
index 5cdbf2f..0000000
--- a/tools/versioner/src/SymbolFileParser.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <map>
-#include <string>
-#include <optional>
-
-#include "DeclarationDatabase.h"
-#include "SymbolDatabase.h"
-
-using SymbolMap = std::map<std::string, NdkSymbolType>;
-
-std::optional<SymbolMap> parseSymbolFile(const std::string &file,
- const CompilationType& type);
diff --git a/tools/versioner/src/Utils.cpp b/tools/versioner/src/Utils.cpp
deleted file mode 100644
index d2bb1a8..0000000
--- a/tools/versioner/src/Utils.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Utils.h"
-
-#include <err.h>
-#include <fts.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sstream>
-#include <string>
-#include <vector>
-
-#include <android-base/strings.h>
-
-#include "DeclarationDatabase.h"
-
-std::string getWorkingDir() {
- char buf[PATH_MAX];
- if (!getcwd(buf, sizeof(buf))) {
- err(1, "getcwd failed");
- }
- return buf;
-}
-
-std::vector<std::string> collectHeaders(const std::string& directory,
- const std::unordered_set<std::string>& ignored_directories) {
- std::vector<std::string> headers;
-
- char* dir_argv[2] = { const_cast<char*>(directory.c_str()), nullptr };
- std::unique_ptr<FTS, decltype(&fts_close)> fts(
- fts_open(dir_argv, FTS_LOGICAL | FTS_NOCHDIR, nullptr), fts_close);
-
- if (!fts) {
- err(1, "failed to open directory '%s'", directory.c_str());
- }
-
- FTSENT* skipping = nullptr;
- while (FTSENT* ent = fts_read(fts.get())) {
- if (ent->fts_info & FTS_DP) {
- if (ent == skipping) {
- skipping = nullptr;
- }
- continue;
- }
-
- if (skipping != nullptr) {
- continue;
- }
-
- if (ent->fts_info & FTS_D) {
- if (ignored_directories.count(ent->fts_path) != 0) {
- // fts_read guarantees that `ent` is valid and okay to hold on to until
- // after it's returned with FTS_DP set.
- skipping = ent;
- }
- continue;
- }
-
- std::string path = ent->fts_path;
- if (!android::base::EndsWith(path, ".h")) {
- continue;
- }
-
- headers.push_back(std::move(path));
- }
-
- return headers;
-}
-
-llvm::StringRef StripPrefix(llvm::StringRef string, llvm::StringRef prefix) {
- if (string.starts_with(prefix)) {
- return string.drop_front(prefix.size());
- }
- return string;
-}
diff --git a/tools/versioner/src/Utils.h b/tools/versioner/src/Utils.h
deleted file mode 100644
index 9b45dcd..0000000
--- a/tools/versioner/src/Utils.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <errno.h>
-#include <libgen.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include <llvm/ADT/StringRef.h>
-
-std::string getWorkingDir();
-std::vector<std::string> collectHeaders(const std::string& directory,
- const std::unordered_set<std::string>& ignored_directories);
-
-static inline std::string dirname(const std::string& path) {
- std::unique_ptr<char, decltype(&free)> path_copy(strdup(path.c_str()), free);
- return dirname(path_copy.get());
-}
-
-static inline bool is_directory(const std::string& path) {
- struct stat st;
- if (stat(path.c_str(), &st) == 0 && S_ISDIR(st.st_mode)) {
- return true;
- }
- return false;
-}
-
-static inline bool mkdirs(const std::string& path) {
- if (is_directory(path)) {
- return true;
- }
-
- std::string parent = dirname(path);
- if (parent == path) {
- return false;
- }
-
- if (!mkdirs(parent)) {
- return false;
- }
-
- if (mkdir(path.c_str(), 0700) != 0) {
- if (errno != EEXIST) {
- return false;
- }
- return is_directory(path);
- }
-
- return true;
-}
-
-static inline std::string to_string(const char* c) {
- return c;
-}
-
-static inline const std::string& to_string(const std::string& str) {
- return str;
-}
-
-template <typename Collection>
-static inline std::string Join(Collection c, const std::string& delimiter = ", ") {
- std::string result;
- for (const auto& item : c) {
- using namespace std;
- result.append(to_string(item));
- result.append(delimiter);
- }
- if (!result.empty()) {
- result.resize(result.length() - delimiter.length());
- }
- return result;
-}
-
-llvm::StringRef StripPrefix(llvm::StringRef string, llvm::StringRef prefix);
diff --git a/tools/versioner/src/VFS.cpp b/tools/versioner/src/VFS.cpp
deleted file mode 100644
index d797f82..0000000
--- a/tools/versioner/src/VFS.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <err.h>
-#include <fcntl.h>
-#include <fts.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-
-#include <android-base/unique_fd.h>
-#include <llvm/ADT/IntrusiveRefCntPtr.h>
-#include <llvm/Support/MemoryBuffer.h>
-#include <llvm/Support/VirtualFileSystem.h>
-
-#include "Utils.h"
-
-using android::base::unique_fd;
-using namespace llvm::vfs;
-
-static void addDirectoryToVFS(InMemoryFileSystem* vfs, const std::string& path) {
- char* paths[] = { const_cast<char*>(path.c_str()), nullptr };
- std::unique_ptr<FTS, decltype(&fts_close)> fts(
- fts_open(paths, FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOCHDIR, nullptr), fts_close);
-
- if (!fts) {
- err(1, "failed to open directory %s", path.c_str());
- }
-
- while (FTSENT* ent = fts_read(fts.get())) {
- if ((ent->fts_info & FTS_F) == 0) {
- continue;
- }
-
- const char* file_path = ent->fts_accpath;
- unique_fd fd(open(file_path, O_RDONLY | O_CLOEXEC));
- if (fd == -1) {
- err(1, "failed to open header '%s'", file_path);
- }
-
- auto buffer_opt = llvm::MemoryBuffer::getOpenFile(fd, file_path, -1, false, false);
- if (!buffer_opt) {
- errx(1, "failed to map header '%s'", file_path);
- }
-
- if (!vfs->addFile(file_path, ent->fts_statp->st_mtime, std::move(buffer_opt.get()))) {
- errx(1, "failed to add file '%s'", file_path);
- }
- }
-}
-
-llvm::IntrusiveRefCntPtr<FileSystem> createCommonVFS(const std::string& header_dir,
- const std::string& dependency_dir,
- bool add_versioning_header) {
- auto vfs = std::make_unique<InMemoryFileSystem>();
- addDirectoryToVFS(vfs.get(), header_dir);
- if (!dependency_dir.empty()) {
- addDirectoryToVFS(vfs.get(), dependency_dir);
- }
-
- if (add_versioning_header) {
- const char* top = getenv("ANDROID_BUILD_TOP");
- if (!top) {
- errx(1, "-i passed, but ANDROID_BUILD_TOP is unset");
- }
-
- std::string header_path = std::string(top) + "/bionic/libc/include/android/versioning.h";
- auto buffer_opt = llvm::MemoryBuffer::getFile(header_path);
- if (!buffer_opt) {
- err(1, "failed to open %s", header_path.c_str());
- }
- vfs->addFile("android/versioning.h", 0, std::move(buffer_opt.get()));
- }
-
- return llvm::IntrusiveRefCntPtr<FileSystem>(vfs.release());
-}
diff --git a/tools/versioner/src/VFS.h b/tools/versioner/src/VFS.h
deleted file mode 100644
index e4aac75..0000000
--- a/tools/versioner/src/VFS.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <memory>
-#include <string>
-
-#include <llvm/ADT/IntrusiveRefCntPtr.h>
-#include <llvm/Support/VirtualFileSystem.h>
-
-llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> createCommonVFS(const std::string& header_dir,
- const std::string& dependency_dir,
- bool add_versioning_header);
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
deleted file mode 100644
index 37c8bac..0000000
--- a/tools/versioner/src/versioner.cpp
+++ /dev/null
@@ -1,697 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dirent.h>
-#include <err.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#if defined(__linux__)
-#include <sched.h>
-#endif
-
-#include <atomic>
-#include <chrono>
-#include <functional>
-#include <iostream>
-#include <map>
-#include <memory>
-#include <set>
-#include <sstream>
-#include <string>
-#include <string_view>
-#include <thread>
-#include <unordered_map>
-#include <vector>
-
-#include <llvm/ADT/StringRef.h>
-
-#include <android-base/file.h>
-#include <android-base/macros.h>
-#include <android-base/parseint.h>
-#include <android-base/strings.h>
-
-#include "Arch.h"
-#include "DeclarationDatabase.h"
-#include "Driver.h"
-#include "Preprocessor.h"
-#include "SymbolDatabase.h"
-#include "Utils.h"
-#include "VFS.h"
-
-#include "versioner.h"
-
-using namespace std::chrono_literals;
-using namespace std::string_literals;
-
-bool strict;
-bool verbose;
-bool add_include;
-
-static int getCpuCount();
-static int max_thread_count = getCpuCount();
-
-static int getCpuCount() {
-#if defined(__linux__)
- cpu_set_t cpu_set;
- int rc = sched_getaffinity(getpid(), sizeof(cpu_set), &cpu_set);
- if (rc != 0) {
- err(1, "sched_getaffinity failed");
- }
- return CPU_COUNT(&cpu_set);
-#else
- return 1;
-#endif
-}
-
-namespace {
-struct HeaderLocationInformation {
- std::string header_path;
- std::string dependency_dir;
- // Absolute paths to ignore all children -- including subdirectories -- of.
- std::unordered_set<std::string> ignored_directories;
-};
-}
-
-static bool is_dir(const std::string& path) {
- struct stat st;
- return stat(path.c_str(), &st) == 0 && S_ISDIR(st.st_mode);
-}
-
-static CompilationRequirements collectRequirements(const Arch& arch,
- const HeaderLocationInformation& location) {
- std::vector<std::string> headers =
- collectHeaders(location.header_path, location.ignored_directories);
- std::vector<std::string> dependencies;
-
- if (is_dir(location.header_path)) {
- dependencies.emplace_back(location.header_path);
- }
-
- if (!location.dependency_dir.empty()) {
- auto collect_children = [&dependencies](const std::string& dir_path) {
- DIR* dir = opendir(dir_path.c_str());
- if (!dir) {
- err(1, "failed to open dependency directory '%s'", dir_path.c_str());
- }
-
- struct dirent* dent;
- while ((dent = readdir(dir))) {
- if (dent->d_name[0] == '.') {
- continue;
- }
-
- // TODO: Resolve symlinks.
- std::string dependency = dir_path + "/" + dent->d_name;
-
- struct stat st;
- if (stat(dependency.c_str(), &st) != 0) {
- err(1, "failed to stat dependency '%s'", dependency.c_str());
- }
-
- if (!S_ISDIR(st.st_mode)) {
- errx(1, "'%s' is not a directory", dependency.c_str());
- }
-
- dependencies.push_back(dependency);
- }
-
- closedir(dir);
- };
-
- collect_children(location.dependency_dir + "/common");
- collect_children(location.dependency_dir + "/" + to_string(arch));
- }
-
- auto new_end = std::remove_if(headers.begin(), headers.end(), [&arch](llvm::StringRef header) {
- for (const auto& it : ignored_headers) {
- if (!it.second.contains(arch)) {
- continue;
- }
-
- if (header.ends_with("/" + it.first)) {
- return true;
- }
- }
- return false;
- });
-
- headers.erase(new_end, headers.end());
-
- CompilationRequirements result = { .headers = headers, .dependencies = dependencies };
- return result;
-}
-
-static std::set<CompilationType> generateCompilationTypes(const std::set<Arch> selected_architectures,
- const std::set<int>& selected_levels) {
- std::set<CompilationType> result;
- for (const auto& arch : selected_architectures) {
- int min_api = arch_min_api[arch];
- for (int api_level : selected_levels) {
- if (api_level < min_api) {
- continue;
- }
-
- for (int file_offset_bits : { 32, 64 }) {
- for (bool cpp : { true, false }) {
- CompilationType type = {
- .arch = arch, .cpp = cpp, .api_level = api_level, .file_offset_bits = file_offset_bits
- };
- result.insert(type);
- }
- }
- }
- }
- return result;
-}
-
-static std::unique_ptr<HeaderDatabase> compileHeaders(const std::set<CompilationType>& types,
- const HeaderLocationInformation& location) {
- if (types.empty()) {
- errx(1, "compileHeaders received no CompilationTypes");
- }
-
- auto vfs = createCommonVFS(location.header_path, location.dependency_dir, add_include);
-
- size_t thread_count = max_thread_count;
- std::vector<std::thread> threads;
-
- std::map<CompilationType, HeaderDatabase> header_databases;
- std::unordered_map<Arch, CompilationRequirements> requirements;
-
- auto result = std::make_unique<HeaderDatabase>();
- for (const auto& type : types) {
- if (requirements.count(type.arch) == 0) {
- requirements[type.arch] = collectRequirements(type.arch, location);
- }
- }
-
- initializeTargetCC1FlagCache(vfs, types, requirements);
-
- std::vector<std::pair<CompilationType, const std::string&>> jobs;
- std::atomic<size_t> job_index(0);
- for (CompilationType type : types) {
- CompilationRequirements& req = requirements[type.arch];
- for (const std::string& header : req.headers) {
- jobs.emplace_back(type, header);
- }
- }
-
- // Dup an empty file to stdin, so that we can use `clang -include a.h -` instead of `clang a.h`,
- // since some warnings don't get generated in files that are compiled directly.
- FILE* empty_file = tmpfile();
- if (!empty_file) {
- err(1, "failed to create temporary file");
- }
-
- int empty_file_fd = fileno(empty_file);
- if (empty_file_fd == -1) {
- errx(1, "fileno failed on tmpfile");
- }
-
- dup2(empty_file_fd, STDIN_FILENO);
- fclose(empty_file);
-
- thread_count = std::min(thread_count, jobs.size());
-
- if (thread_count == 1) {
- for (const auto& job : jobs) {
- compileHeader(vfs, result.get(), job.first, job.second);
- }
- } else {
- // Spawn threads.
- for (size_t i = 0; i < thread_count; ++i) {
- threads.emplace_back([&jobs, &job_index, &result, vfs]() {
- while (true) {
- size_t idx = job_index++;
- if (idx >= jobs.size()) {
- return;
- }
-
- const auto& job = jobs[idx];
- compileHeader(vfs, result.get(), job.first, job.second);
- }
- });
- }
-
- // Reap them.
- for (auto& thread : threads) {
- thread.join();
- }
- threads.clear();
- }
-
- return result;
-}
-
-static std::set<CompilationType> getCompilationTypes(const Declaration* decl) {
- std::set<CompilationType> result;
- for (const auto& it : decl->availability) {
- result.insert(it.first);
- }
- return result;
-}
-
-template<typename T>
-static std::vector<T> Intersection(const std::set<T>& a, const std::set<T>& b) {
- std::vector<T> intersection;
- std::set_intersection(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(intersection));
- return intersection;
-}
-
-// Perform a validity check on a symbol's declarations, enforcing the following invariants:
-// 1. At most one inline definition of the function exists (overloaded inline functions for
-// _FORTIFY_SOURCE do not count because they are usually introduced to intercept the original
-// functions or usually have enable_if attributes).
-// 2. All of the availability declarations for a symbol are compatible.
-// If a function is declared as an inline before a certain version, the inline definition
-// should have no version tag.
-// 3. Each availability type must only be present globally or on a per-arch basis.
-// (e.g. __INTRODUCED_IN_32(21) __INTRODUCED_IN_64(22) __DEPRECATED_IN(23) is fine,
-// but not __INTRODUCED_IN(9) __INTRODUCED_IN_32(10))
-static bool checkSymbol(const Symbol& symbol) {
- std::string cwd = getWorkingDir() + "/";
-
- std::unordered_map<const Declaration*, std::set<CompilationType>> inline_definitions;
- for (const auto& decl_it : symbol.declarations) {
- const Declaration* decl = &decl_it.second;
- if (decl->is_definition && !decl->fortify_inline) {
- std::set<CompilationType> compilation_types = getCompilationTypes(decl);
- for (const auto& inline_def_it : inline_definitions) {
- auto intersection = Intersection(compilation_types, inline_def_it.second);
- if (!intersection.empty()) {
- fprintf(stderr, "versioner: conflicting inline definitions for symbol %s:\n",
- symbol.name.c_str());
- fprintf(stderr, " declarations visible in: %s\n", Join(intersection, ", ").c_str());
- decl->dump(cwd, stderr, 4);
- inline_def_it.first->dump(cwd, stderr, 4);
- return false;
- }
- }
-
- inline_definitions[decl] = std::move(compilation_types);
- }
-
- DeclarationAvailability availability;
- if (!decl->calculateAvailability(&availability)) {
- fprintf(stderr, "versioner: failed to calculate availability for declaration:\n");
- decl->dump(cwd, stderr, 2);
- return false;
- }
-
- if (decl->is_definition && !availability.empty()) {
- fprintf(stderr, "versioner: inline definition has non-empty versioning information:\n");
- decl->dump(cwd, stderr, 2);
- return false;
- }
- }
-
- DeclarationAvailability availability;
- if (!symbol.calculateAvailability(&availability)) {
- fprintf(stderr, "versioner: inconsistent availability for symbol '%s'\n", symbol.name.c_str());
- symbol.dump(cwd);
- return false;
- }
-
- // TODO: Check invariant #3.
- return true;
-}
-
-static bool validityCheck(const HeaderDatabase* database) {
- bool error = false;
- std::string cwd = getWorkingDir() + "/";
-
- for (const auto& symbol_it : database->symbols) {
- if (!checkSymbol(symbol_it.second)) {
- error = true;
- }
- }
- return !error;
-}
-
-// Check that our symbol availability declarations match the actual NDK
-// platform symbol availability.
-static bool checkVersions(const std::set<CompilationType>& types,
- const HeaderDatabase* header_database,
- const NdkSymbolDatabase& symbol_database) {
- std::string cwd = getWorkingDir() + "/";
- bool failed = false;
-
- std::map<Arch, std::set<CompilationType>> arch_types;
- for (const CompilationType& type : types) {
- arch_types[type.arch].insert(type);
- }
-
- std::set<std::string> completely_unavailable;
- std::map<std::string, std::set<CompilationType>> missing_availability;
- std::map<std::string, std::set<CompilationType>> extra_availability;
-
- for (const auto& symbol_it : header_database->symbols) {
- const auto& symbol_name = symbol_it.first;
- DeclarationAvailability symbol_availability;
-
- if (!symbol_it.second.calculateAvailability(&symbol_availability)) {
- errx(1, "failed to calculate symbol availability");
- }
-
- const auto platform_availability_it = symbol_database.find(symbol_name);
- if (platform_availability_it == symbol_database.end()) {
- completely_unavailable.insert(symbol_name);
- continue;
- }
-
- const auto& platform_availability = platform_availability_it->second;
-
- for (const CompilationType& type : types) {
- bool should_be_available = true;
- const auto& global_availability = symbol_availability.global_availability;
- const auto& arch_availability = symbol_availability.arch_availability[type.arch];
- if (global_availability.introduced != 0 && global_availability.introduced > type.api_level) {
- should_be_available = false;
- }
-
- if (arch_availability.introduced != 0 && arch_availability.introduced > type.api_level) {
- should_be_available = false;
- }
-
- if (global_availability.obsoleted != 0 && global_availability.obsoleted <= type.api_level) {
- should_be_available = false;
- }
-
- if (arch_availability.obsoleted != 0 && arch_availability.obsoleted <= type.api_level) {
- should_be_available = false;
- }
-
- // The function declaration might be (validly) missing for the given CompilationType.
- if (!symbol_it.second.hasDeclaration(type)) {
- should_be_available = false;
- }
-
- bool is_available = platform_availability.count(type);
-
- if (should_be_available != is_available) {
- if (is_available) {
- extra_availability[symbol_name].insert(type);
- } else {
- missing_availability[symbol_name].insert(type);
- }
- }
- }
- }
-
- for (const auto& it : symbol_database) {
- const std::string& symbol_name = it.first;
-
- bool symbol_error = false;
- if (auto missing_it = missing_availability.find(symbol_name);
- missing_it != missing_availability.end()) {
- printf("%s: declaration marked available but symbol missing in [%s]\n", symbol_name.c_str(),
- Join(missing_it->second, ", ").c_str());
- symbol_error = true;
- failed = true;
- }
-
- if (strict) {
- if (auto extra_it = extra_availability.find(symbol_name);
- extra_it != extra_availability.end()) {
- printf("%s: declaration marked unavailable but symbol available in [%s]\n",
- symbol_name.c_str(), Join(extra_it->second, ", ").c_str());
- symbol_error = true;
- failed = true;
- }
- }
-
- if (symbol_error) {
- if (auto symbol_it = header_database->symbols.find(symbol_name);
- symbol_it != header_database->symbols.end()) {
- symbol_it->second.dump(cwd);
- } else {
- errx(1, "failed to find symbol in header database");
- }
- }
- }
-
- // TODO: Verify that function/variable declarations are actually function/variable symbols.
- return !failed;
-}
-
-static void usage(bool help = false) {
- fprintf(stderr, "Usage: versioner [OPTION]... [HEADER_PATH] [DEPS_PATH]\n");
- if (!help) {
- printf("Try 'versioner -h' for more information.\n");
- exit(1);
- } else {
- fprintf(stderr, "Version headers at HEADER_PATH, with DEPS_PATH/ARCH/* on the include path\n");
- fprintf(stderr, "Autodetects paths if HEADER_PATH and DEPS_PATH are not specified\n");
- fprintf(stderr, "\n");
- fprintf(stderr, "Target specification (defaults to all):\n");
- fprintf(stderr, " -a API_LEVEL\tbuild with specified API level (can be repeated)\n");
- fprintf(stderr, " \t\tdefaults to %s\n", Join(default_levels).c_str());
- fprintf(stderr, " -r ARCH\tbuild with specified architecture (can be repeated)\n");
- fprintf(stderr, " \t\tvalid architectures are %s\n", Join(supported_archs).c_str());
- fprintf(stderr, "\n");
- fprintf(stderr, "Validation:\n");
- fprintf(stderr, " -p PATH\tcompare against NDK platform at PATH\n");
- fprintf(stderr, " -s\t\tenable strict warnings\n");
- fprintf(stderr, "\n");
- fprintf(stderr, "Preprocessing:\n");
- fprintf(stderr, " -o PATH\tpreprocess header files and emit them at PATH\n");
- fprintf(stderr, " -f\t\tpreprocess header files even if validation fails\n");
- fprintf(stderr, "\n");
- fprintf(stderr, "Miscellaneous:\n");
- fprintf(stderr, " -F\t\tdo not ignore FORTIFY headers by default\n");
- fprintf(stderr, " -d\t\tdump function availability\n");
- fprintf(stderr, " -j THREADS\tmaximum number of threads to use\n");
- fprintf(stderr, " -v\t\tenable verbose logging\n");
- fprintf(stderr, " -h\t\tdisplay this message\n");
- exit(0);
- }
-}
-
-// versioner uses a prebuilt version of clang, which is not up-to-date wrt/
-// container annotations. So disable container overflow checking. b/37775238
-extern "C" const char* __asan_default_options() {
- return "detect_container_overflow=0";
-}
-
-int main(int argc, char** argv) {
- std::string cwd = getWorkingDir() + "/";
- std::string platform_dir;
- std::set<Arch> selected_architectures;
- std::set<int> selected_levels;
- std::string preprocessor_output_path;
- bool force = false;
- bool dump = false;
- bool ignore_fortify_headers = true;
-
- int c;
- while ((c = getopt(argc, argv, "a:r:p:so:fdj:vhFi")) != -1) {
- switch (c) {
- case 'a': {
- char* end;
- int api_level = strtol(optarg, &end, 10);
- if (end == optarg || strlen(end) > 0) {
- usage();
- }
-
- selected_levels.insert(api_level);
- break;
- }
-
- case 'r': {
- std::optional<Arch> arch = arch_from_string(optarg);
- if (!arch) {
- errx(1, "unknown architecture '%s'", optarg);
- }
- selected_architectures.insert(*arch);
- break;
- }
-
- case 'p': {
- if (!platform_dir.empty()) {
- usage();
- }
-
- platform_dir = optarg;
-
- if (platform_dir.empty()) {
- usage();
- }
-
- struct stat st;
- if (stat(platform_dir.c_str(), &st) != 0) {
- err(1, "failed to stat platform directory '%s'", platform_dir.c_str());
- }
- if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) {
- errx(1, "'%s' is not a file or directory", optarg);
- }
- break;
- }
-
- case 's':
- strict = true;
- break;
-
- case 'o':
- if (!preprocessor_output_path.empty()) {
- usage();
- }
- preprocessor_output_path = optarg;
- if (preprocessor_output_path.empty()) {
- usage();
- }
- break;
-
- case 'f':
- force = true;
- break;
-
- case 'd':
- dump = true;
- break;
-
- case 'j':
- if (!android::base::ParseInt<int>(optarg, &max_thread_count, 1)) {
- usage();
- }
- break;
-
- case 'v':
- verbose = true;
- break;
-
- case 'h':
- usage(true);
- break;
-
- case 'i':
- // Secret option for tests to -include <android/versioning.h>.
- add_include = true;
- break;
-
- case 'F':
- ignore_fortify_headers = false;
- break;
-
- default:
- usage();
- break;
- }
- }
-
- if (argc - optind > 2 || optind > argc) {
- usage();
- }
-
- HeaderLocationInformation location;
-
- const char* top = getenv("ANDROID_BUILD_TOP");
- if (!top && (optind == argc || add_include)) {
- fprintf(stderr, "versioner: failed to autodetect bionic paths. Is ANDROID_BUILD_TOP set?\n");
- usage();
- }
-
- if (optind == argc) {
- // Neither HEADER_PATH nor DEPS_PATH were specified, so try to figure them out.
- std::string versioner_dir = to_string(top) + "/bionic/tools/versioner";
- location.header_path = versioner_dir + "/current";
- location.dependency_dir = versioner_dir + "/dependencies";
- if (platform_dir.empty()) {
- platform_dir = versioner_dir + "/platforms";
- }
- } else {
- if (!android::base::Realpath(argv[optind], &location.header_path)) {
- err(1, "failed to get realpath for path '%s'", argv[optind]);
- }
-
- if (argc - optind == 2) {
- location.dependency_dir = argv[optind + 1];
- }
- }
-
- // Every file that lives in bits/fortify is logically a part of a header outside of bits/fortify.
- // This makes the files there impossible to build on their own.
- if (ignore_fortify_headers) {
- std::string fortify_path = location.header_path;
- if (!android::base::EndsWith(location.header_path, "/")) {
- fortify_path += '/';
- }
- fortify_path += "bits/fortify";
- location.ignored_directories.insert(std::move(fortify_path));
- }
-
- if (selected_levels.empty()) {
- selected_levels = default_levels;
- }
-
- if (selected_architectures.empty()) {
- selected_architectures = supported_archs;
- }
-
-
- struct stat st;
- if (const char *path = location.header_path.c_str(); stat(path, &st) != 0) {
- err(1, "failed to stat '%s'", path);
- }
-
- std::set<CompilationType> compilation_types;
- std::optional<NdkSymbolDatabase> symbol_database;
-
- compilation_types = generateCompilationTypes(selected_architectures, selected_levels);
-
- // Do this before compiling so that we can early exit if the platforms don't match what we
- // expect.
- if (!platform_dir.empty()) {
- symbol_database = parsePlatforms(compilation_types, platform_dir);
- }
-
- auto start = std::chrono::high_resolution_clock::now();
- std::unique_ptr<HeaderDatabase> declaration_database =
- compileHeaders(compilation_types, location);
- auto end = std::chrono::high_resolution_clock::now();
-
- if (verbose) {
- auto diff = (end - start) / 1.0ms;
- printf("Compiled headers for %zu targets in %0.2LFms\n", compilation_types.size(), diff);
- }
-
- bool failed = false;
- if (dump) {
- declaration_database->dump(location.header_path + "/");
- } else {
- if (!validityCheck(declaration_database.get())) {
- printf("versioner: validity check failed\n");
- failed = true;
- }
-
- if (symbol_database) {
- if (!checkVersions(compilation_types, declaration_database.get(), *symbol_database)) {
- printf("versioner: version check failed\n");
- failed = true;
- }
- }
- }
-
- if (!preprocessor_output_path.empty() && (force || !failed)) {
- failed = !preprocessHeaders(preprocessor_output_path, location.header_path,
- declaration_database.get());
- }
- return failed;
-}
diff --git a/tools/versioner/src/versioner.h b/tools/versioner/src/versioner.h
deleted file mode 100644
index 225e14b..0000000
--- a/tools/versioner/src/versioner.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <map>
-#include <set>
-#include <string>
-#include <unordered_map>
-#include <unordered_set>
-
-extern bool strict;
-extern bool verbose;
-extern bool add_include;
-
-#define D(...) \
- do { \
- if (verbose) { \
- printf(__VA_ARGS__); \
- } \
- } while (0)
-
-static const std::unordered_map<std::string, std::set<Arch>> ignored_headers = {
- // Internal header.
- // TODO: we should probably just admit we're never getting rid of this.
- { "sys/_system_properties.h", supported_archs },
-
- // time64.h #errors when included on LP64 archs.
- { "time64.h", { Arch::arm64, Arch::riscv64, Arch::x86_64 } },
-};
diff --git a/tools/versioner/tests/.gitignore b/tools/versioner/tests/.gitignore
deleted file mode 100644
index 89f9ac0..0000000
--- a/tools/versioner/tests/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-out/
diff --git a/tools/versioner/tests/arch_specific/headers/foo.h b/tools/versioner/tests/arch_specific/headers/foo.h
deleted file mode 100644
index 4830a68..0000000
--- a/tools/versioner/tests/arch_specific/headers/foo.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo();
-
-#if defined(__i386__)
-int bar();
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/arch_specific/platforms/libc.map.txt b/tools/versioner/tests/arch_specific/platforms/libc.map.txt
deleted file mode 100644
index 5aa11ed..0000000
--- a/tools/versioner/tests/arch_specific/platforms/libc.map.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-LIBC {
- global:
- foo; # arm x86
- bar; # x86
-};
diff --git a/tools/versioner/tests/arch_specific/run.sh b/tools/versioner/tests/arch_specific/run.sh
deleted file mode 100644
index f0d95ae..0000000
--- a/tools/versioner/tests/arch_specific/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -r x86 -a 9 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/compilation_error/expected_fail b/tools/versioner/tests/compilation_error/expected_fail
deleted file mode 100644
index f18b625..0000000
--- a/tools/versioner/tests/compilation_error/expected_fail
+++ /dev/null
@@ -1 +0,0 @@
-versioner: compilation generated warnings or errors
diff --git a/tools/versioner/tests/compilation_error/headers/foo.h b/tools/versioner/tests/compilation_error/headers/foo.h
deleted file mode 100644
index 51c087a..0000000
--- a/tools/versioner/tests/compilation_error/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#error foo
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/compilation_error/platforms/libc.map.txt b/tools/versioner/tests/compilation_error/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/compilation_error/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/compilation_error/run.sh b/tools/versioner/tests/compilation_error/run.sh
deleted file mode 100644
index 7e8d489..0000000
--- a/tools/versioner/tests/compilation_error/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -i -j1
diff --git a/tools/versioner/tests/dependencies/dependencies/arm/archdep/archdep.h b/tools/versioner/tests/dependencies/dependencies/arm/archdep/archdep.h
deleted file mode 100644
index b2d357a..0000000
--- a/tools/versioner/tests/dependencies/dependencies/arm/archdep/archdep.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-typedef int arm_t;
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/dependencies/dependencies/common/foo/foodep.h b/tools/versioner/tests/dependencies/dependencies/common/foo/foodep.h
deleted file mode 100644
index baa5857..0000000
--- a/tools/versioner/tests/dependencies/dependencies/common/foo/foodep.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-typedef int foo_t;
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/dependencies/dependencies/x86/archdep/archdep.h b/tools/versioner/tests/dependencies/dependencies/x86/archdep/archdep.h
deleted file mode 100644
index b73f7cc..0000000
--- a/tools/versioner/tests/dependencies/dependencies/x86/archdep/archdep.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-typedef int x86_t;
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/dependencies/headers/foo.h b/tools/versioner/tests/dependencies/headers/foo.h
deleted file mode 100644
index 875de1b..0000000
--- a/tools/versioner/tests/dependencies/headers/foo.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#include <archdep.h>
-#include <foodep.h>
-
-#if defined(__i386__)
-x86_t foo(foo_t);
-#elif defined(__arm__)
-arm_t foo(foo_t);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/dependencies/platforms/libc.map.txt b/tools/versioner/tests/dependencies/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/dependencies/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/dependencies/run.sh b/tools/versioner/tests/dependencies/run.sh
deleted file mode 100644
index 0c17907..0000000
--- a/tools/versioner/tests/dependencies/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers dependencies -p platforms -r arm -r x86 -a 9
\ No newline at end of file
diff --git a/tools/versioner/tests/extern_cpp/headers/string.h b/tools/versioner/tests/extern_cpp/headers/string.h
deleted file mode 100644
index 5ac43ac..0000000
--- a/tools/versioner/tests/extern_cpp/headers/string.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#define __RENAME(x) __asm__(#x)
-
-#if defined(__cplusplus)
-extern "C++" char* basename(char*) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-extern "C++" const char* basename(const char*) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-#else
-char* basename(const char*) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-#endif
-
-char* foo() __INTRODUCED_IN(8);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/extern_cpp/platforms/libc.map.txt b/tools/versioner/tests/extern_cpp/platforms/libc.map.txt
deleted file mode 100644
index 297d1fb..0000000
--- a/tools/versioner/tests/extern_cpp/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- __gnu_basename; # introduced=23
-};
diff --git a/tools/versioner/tests/extern_cpp/run.sh b/tools/versioner/tests/extern_cpp/run.sh
deleted file mode 100644
index e320c95..0000000
--- a/tools/versioner/tests/extern_cpp/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 21 -a 23 -i
diff --git a/tools/versioner/tests/extern_cpp_mismatch/headers/string.h b/tools/versioner/tests/extern_cpp_mismatch/headers/string.h
deleted file mode 100644
index 66133d8..0000000
--- a/tools/versioner/tests/extern_cpp_mismatch/headers/string.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#define __RENAME(x) __asm__(#x)
-
-#if defined(__cplusplus)
-extern "C++" char* basename(char*) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-extern "C++" const char* basename(const char*) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-#else
-char* basename(const char*) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/extern_cpp_mismatch/platforms/libc.map.txt b/tools/versioner/tests/extern_cpp_mismatch/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/extern_cpp_mismatch/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/extern_cpp_mismatch/run.sh b/tools/versioner/tests/extern_cpp_mismatch/run.sh
deleted file mode 100644
index a34fda8..0000000
--- a/tools/versioner/tests/extern_cpp_mismatch/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/fortify_inline/headers/fcntl.h b/tools/versioner/tests/fortify_inline/headers/fcntl.h
deleted file mode 100644
index dc81ef8..0000000
--- a/tools/versioner/tests/fortify_inline/headers/fcntl.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-extern int open_real(const char* name, int flags, ...) __asm__("open");
-
-#define O_CREAT 00000100
-
-typedef unsigned int mode_t;
-
-static inline __attribute__((always_inline))
-int open(const char* name, int flags)
- __attribute__((annotate("versioner_fortify_inline")))
- __attribute__((overloadable))
- __attribute__((enable_if(!(flags & O_CREAT), ""))) {
- return open_real(name, flags);
-}
-
-static inline __attribute__((always_inline))
-int open(const char* name, int flags, mode_t mode)
- __attribute__((annotate("versioner_fortify_inline")))
- __attribute__((overloadable))
- __attribute__((enable_if(flags & O_CREAT, ""))) {
- return open_real(name, flags, mode);
-}
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/fortify_inline/platforms/libc.map.txt b/tools/versioner/tests/fortify_inline/platforms/libc.map.txt
deleted file mode 100644
index 2f09034..0000000
--- a/tools/versioner/tests/fortify_inline/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- open;
-};
diff --git a/tools/versioner/tests/fortify_inline/run.sh b/tools/versioner/tests/fortify_inline/run.sh
deleted file mode 100644
index 9bfbe6d..0000000
--- a/tools/versioner/tests/fortify_inline/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -a 12 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/inline/headers/foo.h b/tools/versioner/tests/inline/headers/foo.h
deleted file mode 100644
index a337f9c..0000000
--- a/tools/versioner/tests/inline/headers/foo.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#if __ANDROID_API__ < 12
-static int foo() {
- return 0;
-}
-#else
-int foo() __INTRODUCED_IN(12);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/inline/platforms/libc.map.txt b/tools/versioner/tests/inline/platforms/libc.map.txt
deleted file mode 100644
index 4dced92..0000000
--- a/tools/versioner/tests/inline/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo; # introduced=12
-};
diff --git a/tools/versioner/tests/inline/run.sh b/tools/versioner/tests/inline/run.sh
deleted file mode 100644
index 9bfbe6d..0000000
--- a/tools/versioner/tests/inline/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -a 12 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/missing_api/expected_fail b/tools/versioner/tests/missing_api/expected_fail
deleted file mode 100644
index 9f097f7..0000000
--- a/tools/versioner/tests/missing_api/expected_fail
+++ /dev/null
@@ -1,4 +0,0 @@
- foo: introduced = 9
- extern declaration @ headers/foo.h:5:1
- introduced = 9
-versioner: version check failed
diff --git a/tools/versioner/tests/missing_api/headers/foo.h b/tools/versioner/tests/missing_api/headers/foo.h
deleted file mode 100644
index c201dbb..0000000
--- a/tools/versioner/tests/missing_api/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __INTRODUCED_IN(9);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/missing_api/platforms/libc.map.txt b/tools/versioner/tests/missing_api/platforms/libc.map.txt
deleted file mode 100644
index 3701a9d..0000000
--- a/tools/versioner/tests/missing_api/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo; # api-level=9
-};
diff --git a/tools/versioner/tests/missing_api/run.sh b/tools/versioner/tests/missing_api/run.sh
deleted file mode 100644
index 9bfbe6d..0000000
--- a/tools/versioner/tests/missing_api/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -a 12 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/missing_arch/expected_fail b/tools/versioner/tests/missing_arch/expected_fail
deleted file mode 100644
index 7b33e19..0000000
--- a/tools/versioner/tests/missing_arch/expected_fail
+++ /dev/null
@@ -1,4 +0,0 @@
- foo: no availability
- extern declaration @ headers/foo.h:5:1
- no availability
-versioner: version check failed
diff --git a/tools/versioner/tests/missing_arch/headers/foo.h b/tools/versioner/tests/missing_arch/headers/foo.h
deleted file mode 100644
index 5ba4794..0000000
--- a/tools/versioner/tests/missing_arch/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo();
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/missing_arch/platforms/libc.map.txt b/tools/versioner/tests/missing_arch/platforms/libc.map.txt
deleted file mode 100644
index f56190e..0000000
--- a/tools/versioner/tests/missing_arch/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo; # arm
-};
diff --git a/tools/versioner/tests/missing_arch/run.sh b/tools/versioner/tests/missing_arch/run.sh
deleted file mode 100644
index f0d95ae..0000000
--- a/tools/versioner/tests/missing_arch/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -r x86 -a 9 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/multiple_decl/headers/bar.h b/tools/versioner/tests/multiple_decl/headers/bar.h
deleted file mode 100644
index b16617b..0000000
--- a/tools/versioner/tests/multiple_decl/headers/bar.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __REMOVED_IN(12);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_decl/headers/foo.h b/tools/versioner/tests/multiple_decl/headers/foo.h
deleted file mode 100644
index b16617b..0000000
--- a/tools/versioner/tests/multiple_decl/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __REMOVED_IN(12);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_decl/platforms/libc.map.txt b/tools/versioner/tests/multiple_decl/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/multiple_decl/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/multiple_decl/run.sh b/tools/versioner/tests/multiple_decl/run.sh
deleted file mode 100644
index a34fda8..0000000
--- a/tools/versioner/tests/multiple_decl/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/multiple_decl_mismatch/expected_fail b/tools/versioner/tests/multiple_decl_mismatch/expected_fail
deleted file mode 100644
index 30e7233..0000000
--- a/tools/versioner/tests/multiple_decl_mismatch/expected_fail
+++ /dev/null
@@ -1,8 +0,0 @@
-versioner: inconsistent availability for symbol 'foo'
-versioner: failed to calculate symbol availability
- foo: invalid
- extern declaration @ headers/bar.h:5:1
- obsoleted = 12
- extern declaration @ headers/foo.h:5:1
- obsoleted = 9
-versioner: validity check failed
diff --git a/tools/versioner/tests/multiple_decl_mismatch/headers/bar.h b/tools/versioner/tests/multiple_decl_mismatch/headers/bar.h
deleted file mode 100644
index b16617b..0000000
--- a/tools/versioner/tests/multiple_decl_mismatch/headers/bar.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __REMOVED_IN(12);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_decl_mismatch/headers/foo.h b/tools/versioner/tests/multiple_decl_mismatch/headers/foo.h
deleted file mode 100644
index 8e8f98c..0000000
--- a/tools/versioner/tests/multiple_decl_mismatch/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __REMOVED_IN(9);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_decl_mismatch/platforms/libc.map.txt b/tools/versioner/tests/multiple_decl_mismatch/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/multiple_decl_mismatch/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/multiple_decl_mismatch/run.sh b/tools/versioner/tests/multiple_decl_mismatch/run.sh
deleted file mode 100644
index a34fda8..0000000
--- a/tools/versioner/tests/multiple_decl_mismatch/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/multiple_definition/expected_fail b/tools/versioner/tests/multiple_definition/expected_fail
deleted file mode 100644
index 5abb833..0000000
--- a/tools/versioner/tests/multiple_definition/expected_fail
+++ /dev/null
@@ -1,7 +0,0 @@
-versioner: conflicting inline definitions for symbol foo:
- declarations visible in: arm-9 [c, fob = 32], arm-9 [c, fob = 64], arm-12 [c, fob = 32], arm-12 [c, fob = 64], arm-9 [c++, fob = 32], arm-9 [c++, fob = 64], arm-12 [c++, fob = 32], arm-12 [c++, fob = 64]
- static definition @ headers/foo.h:5:1
- no availability
- static definition @ headers/bar.h:5:1
- no availability
-versioner: validity check failed
diff --git a/tools/versioner/tests/multiple_definition/headers/bar.h b/tools/versioner/tests/multiple_definition/headers/bar.h
deleted file mode 100644
index 29592c6..0000000
--- a/tools/versioner/tests/multiple_definition/headers/bar.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-static int foo() {
- return 0;
-}
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_definition/headers/foo.h b/tools/versioner/tests/multiple_definition/headers/foo.h
deleted file mode 100644
index 29592c6..0000000
--- a/tools/versioner/tests/multiple_definition/headers/foo.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-static int foo() {
- return 0;
-}
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_definition/platforms/libc.map.txt b/tools/versioner/tests/multiple_definition/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/multiple_definition/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/multiple_definition/run.sh b/tools/versioner/tests/multiple_definition/run.sh
deleted file mode 100644
index e4abbe7..0000000
--- a/tools/versioner/tests/multiple_definition/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -a 12 -i
diff --git a/tools/versioner/tests/multiple_definition_ok/headers/bar.h b/tools/versioner/tests/multiple_definition_ok/headers/bar.h
deleted file mode 100644
index 6eced51..0000000
--- a/tools/versioner/tests/multiple_definition_ok/headers/bar.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#if __ANDROID_API__ == 12
-static int foo() {
- return 0;
-}
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_definition_ok/headers/foo.h b/tools/versioner/tests/multiple_definition_ok/headers/foo.h
deleted file mode 100644
index 773d274..0000000
--- a/tools/versioner/tests/multiple_definition_ok/headers/foo.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#if __ANDROID_API__ == 9
-static int foo() {
- return 0;
-}
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/multiple_definition_ok/platforms/libc.map.txt b/tools/versioner/tests/multiple_definition_ok/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/multiple_definition_ok/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/multiple_definition_ok/run.sh b/tools/versioner/tests/multiple_definition_ok/run.sh
deleted file mode 100644
index e4abbe7..0000000
--- a/tools/versioner/tests/multiple_definition_ok/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -a 12 -i
diff --git a/tools/versioner/tests/obsoleted/headers/foo.h b/tools/versioner/tests/obsoleted/headers/foo.h
deleted file mode 100644
index e9630e5..0000000
--- a/tools/versioner/tests/obsoleted/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __INTRODUCED_IN(9) __REMOVED_IN(11);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/obsoleted/platforms/libc.map.txt b/tools/versioner/tests/obsoleted/platforms/libc.map.txt
deleted file mode 100644
index 3701a9d..0000000
--- a/tools/versioner/tests/obsoleted/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo; # api-level=9
-};
diff --git a/tools/versioner/tests/obsoleted/run.sh b/tools/versioner/tests/obsoleted/run.sh
deleted file mode 100644
index 9bfbe6d..0000000
--- a/tools/versioner/tests/obsoleted/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -a 12 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/preprocessor/expected/foo.h b/tools/versioner/tests/preprocessor/expected/foo.h
deleted file mode 100644
index 4f74927..0000000
--- a/tools/versioner/tests/preprocessor/expected/foo.h
+++ /dev/null
@@ -1,85 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int always_available();
-
-int also_always_available() __INTRODUCED_IN(9);
-
-
-#if __ANDROID_API__ >= 13
-int needs_guard() __INTRODUCED_IN(13);
-#endif /* __ANDROID_API__ >= 13 */
-
-
-#if __ANDROID_API__ >= 12
-
-#if __ANDROID_API__ >= 13
-int needs_guard_2() __INTRODUCED_IN(13);
-#endif /* __ANDROID_API__ >= 13 */
-
-#endif
-
-#if __ANDROID_API__ >= 13
-int already_guarded() __INTRODUCED_IN(13);
-#endif
-
-#if __ANDROID_API__ > 13
-int already_guarded_2() __INTRODUCED_IN(13);
-#endif
-
-#if defined(__arm__)
-
-#if __ANDROID_API__ >= 14
-int specific_arch() __INTRODUCED_IN(14);
-#endif /* __ANDROID_API__ >= 14 */
-
-
-#if __ANDROID_API__ >= 14
-int specific_arch_already_guarded() __INTRODUCED_IN(14);
-#endif
-
-#if __ANDROID_API__ > 14
-int specific_arch_already_guarded_2() __INTRODUCED_IN(14);
-#endif
-#endif
-
-#if defined(__arm__) || defined(__i386__)
-
-#if __ANDROID_API__ >= 14
-int multiple_archs() __INTRODUCED_IN(14);
-#endif /* __ANDROID_API__ >= 14 */
-
-#endif
-
-// __INTRODUCED_IN_64(21) should be ignored.
-
-#if (!defined(__LP64__) && __ANDROID_API__ >= 24) || (defined(__LP64__))
-int multiple_introduced_1() __INTRODUCED_IN_32(24) __INTRODUCED_IN_64(21);
-#endif /* (!defined(__LP64__) && __ANDROID_API__ >= 24) || (defined(__LP64__)) */
-
-
-// This needs different guards for 32 vs 64.
-
-#if (!defined(__LP64__) && __ANDROID_API__ >= 24) || (defined(__LP64__) && __ANDROID_API__ >= 26)
-int multiple_introduced_2() __INTRODUCED_IN_32(24) __INTRODUCED_IN_64(26);
-#endif /* (!defined(__LP64__) && __ANDROID_API__ >= 24) || (defined(__LP64__) && __ANDROID_API__ >= 26) */
-
-
-// This produces both an LP64 and a not-LP64 check, but it doesn't need to check for all 64-bit
-// targets separately.
-
-#if (!defined(__LP64__) && __ANDROID_API__ >= 23) || (defined(__LP64__) && __ANDROID_API__ >= 23)
-int multiple_introduced_3() __INTRODUCED_IN_32(23) __INTRODUCED_IN_64(23);
-#endif /* (!defined(__LP64__) && __ANDROID_API__ >= 23) || (defined(__LP64__) && __ANDROID_API__ >= 23) */
-
-
-
-#if (!defined(__LP64__)) || (defined(__LP64__) && __ANDROID_API__ >= 28)
-int added_to_lp64_late() __INTRODUCED_IN_64(28);
-#endif /* (!defined(__LP64__)) || (defined(__LP64__) && __ANDROID_API__ >= 28) */
-
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor/headers/foo.h b/tools/versioner/tests/preprocessor/headers/foo.h
deleted file mode 100644
index b01d8a9..0000000
--- a/tools/versioner/tests/preprocessor/headers/foo.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int always_available();
-
-int also_always_available() __INTRODUCED_IN(9);
-
-int needs_guard() __INTRODUCED_IN(13);
-
-#if __ANDROID_API__ >= 12
-int needs_guard_2() __INTRODUCED_IN(13);
-#endif
-
-#if __ANDROID_API__ >= 13
-int already_guarded() __INTRODUCED_IN(13);
-#endif
-
-#if __ANDROID_API__ > 13
-int already_guarded_2() __INTRODUCED_IN(13);
-#endif
-
-#if defined(__arm__)
-int specific_arch() __INTRODUCED_IN(14);
-
-#if __ANDROID_API__ >= 14
-int specific_arch_already_guarded() __INTRODUCED_IN(14);
-#endif
-
-#if __ANDROID_API__ > 14
-int specific_arch_already_guarded_2() __INTRODUCED_IN(14);
-#endif
-#endif
-
-#if defined(__arm__) || defined(__i386__)
-int multiple_archs() __INTRODUCED_IN(14);
-#endif
-
-// __INTRODUCED_IN_64(21) should be ignored.
-int multiple_introduced_1() __INTRODUCED_IN_32(24) __INTRODUCED_IN_64(21);
-
-// This needs different guards for 32 vs 64.
-int multiple_introduced_2() __INTRODUCED_IN_32(24) __INTRODUCED_IN_64(26);
-
-// This produces both an LP64 and a not-LP64 check, but it doesn't need to check for all 64-bit
-// targets separately.
-int multiple_introduced_3() __INTRODUCED_IN_32(23) __INTRODUCED_IN_64(23);
-
-int added_to_lp64_late() __INTRODUCED_IN_64(28);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor/run.sh b/tools/versioner/tests/preprocessor/run.sh
deleted file mode 100644
index b039656..0000000
--- a/tools/versioner/tests/preprocessor/run.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-set -e
-
-function run_test {
- SRC=$1
- DST=$2
- rm -rf $2
- versioner -a 9 -a 12 -a 13 -a 14 -a 15 -a 21 -a 23 $1 -i -o $2
- diff -q -w -B $2 expected
-}
-
-run_test headers out
-run_test headers/ out
-run_test headers out/
-run_test headers/ out/
-
-run_test `pwd`/headers out
-run_test `pwd`/headers/ out
-run_test `pwd`/headers out/
-run_test `pwd`/headers/ out/
-
-run_test headers `pwd`/out
-run_test headers/ `pwd`/out
-run_test headers `pwd`/out/
-run_test headers/ `pwd`/out/
-
-run_test `pwd`/headers `pwd`/out
-run_test `pwd`/headers/ `pwd`/out
-run_test `pwd`/headers `pwd`/out/
-run_test `pwd`/headers/ `pwd`/out/
diff --git a/tools/versioner/tests/preprocessor_extern_cpp/expected/foo.h b/tools/versioner/tests/preprocessor_extern_cpp/expected/foo.h
deleted file mode 100644
index 9b2d122..0000000
--- a/tools/versioner/tests/preprocessor_extern_cpp/expected/foo.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#define __RENAME(x) asm(#x)
-
-#if defined(__cplusplus)
-
-#if __ANDROID_API__ >= 24
-extern "C++" const char* strchrnul(const char*, int) __RENAME(strchrnul) __INTRODUCED_IN(24);
-#endif /* __ANDROID_API__ >= 24 */
-
-#endif
-
-#if defined(__cplusplus)
-extern "C" int foo();
-#endif
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-
-#if __ANDROID_API__ >= 24
-char* strchrnul(char*, int) __INTRODUCED_IN(24);
-#endif /* __ANDROID_API__ >= 24 */
-
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_extern_cpp/headers/foo.h b/tools/versioner/tests/preprocessor_extern_cpp/headers/foo.h
deleted file mode 100644
index de26d21..0000000
--- a/tools/versioner/tests/preprocessor_extern_cpp/headers/foo.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#define __RENAME(x) asm(#x)
-
-#if defined(__cplusplus)
-extern "C++" const char* strchrnul(const char*, int) __RENAME(strchrnul) __INTRODUCED_IN(24);
-#endif
-
-#if defined(__cplusplus)
-extern "C" int foo();
-#endif
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-char* strchrnul(char*, int) __INTRODUCED_IN(24);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_extern_cpp/run.sh b/tools/versioner/tests/preprocessor_extern_cpp/run.sh
deleted file mode 100644
index 50d9b5c..0000000
--- a/tools/versioner/tests/preprocessor_extern_cpp/run.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-set -e
-
-function run_test {
- SRC=$1
- DST=$2
- rm -rf $2
- versioner -a 9 -a 12 -a 13 -a 14 -a 15 $1 -i -o $2
- diff -q -w -B $2 expected
-}
-
-run_test headers out
-run_test headers/ out
-run_test headers out/
-run_test headers/ out/
-
-run_test `pwd`/headers out
-run_test `pwd`/headers/ out
-run_test `pwd`/headers out/
-run_test `pwd`/headers/ out/
-
-run_test headers `pwd`/out
-run_test headers/ `pwd`/out
-run_test headers `pwd`/out/
-run_test headers/ `pwd`/out/
-
-run_test `pwd`/headers `pwd`/out
-run_test `pwd`/headers/ `pwd`/out
-run_test `pwd`/headers `pwd`/out/
-run_test `pwd`/headers/ `pwd`/out/
diff --git a/tools/versioner/tests/preprocessor_file_offset_bits/expected/foo.h b/tools/versioner/tests/preprocessor_file_offset_bits/expected/foo.h
deleted file mode 100644
index dcfaaee..0000000
--- a/tools/versioner/tests/preprocessor_file_offset_bits/expected/foo.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-typedef int off_t;
-typedef int ssize_t;
-typedef unsigned size_t;
-
-#if !defined(__LP64__) && defined(_FILE_OFFSET_BITS)
-#if _FILE_OFFSET_BITS == 64
-#define __USE_FILE_OFFSET64 1
-#endif
-#endif
-
-#define __RENAME(x) __asm__(#x)
-
-#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= 21
-int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
-#else
-int truncate(const char* __path, off_t __length);
-#endif
-
-#if defined(__USE_FILE_OFFSET64)
-
-#if __ANDROID_API__ >= 12
-ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) __RENAME(pread64)
- __INTRODUCED_IN(12);
-#endif /* __ANDROID_API__ >= 12 */
-
-#else
-ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset);
-#endif
-
-#if defined(__USE_FILE_OFFSET64)
-off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
-#else
-off_t lseek(int __fd, off_t __offset, int __whence);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_file_offset_bits/headers/foo.h b/tools/versioner/tests/preprocessor_file_offset_bits/headers/foo.h
deleted file mode 100644
index 5ffffa8..0000000
--- a/tools/versioner/tests/preprocessor_file_offset_bits/headers/foo.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-typedef int off_t;
-typedef int ssize_t;
-typedef unsigned size_t;
-
-#if !defined(__LP64__) && defined(_FILE_OFFSET_BITS)
-#if _FILE_OFFSET_BITS == 64
-#define __USE_FILE_OFFSET64 1
-#endif
-#endif
-
-#define __RENAME(x) __asm__(#x)
-
-#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= 21
-int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21);
-#else
-int truncate(const char* __path, off_t __length);
-#endif
-
-#if defined(__USE_FILE_OFFSET64)
-ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) __RENAME(pread64)
- __INTRODUCED_IN(12);
-#else
-ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset);
-#endif
-
-#if defined(__USE_FILE_OFFSET64)
-off_t lseek(int __fd, off_t __offset, int __whence) __RENAME(lseek64);
-#else
-off_t lseek(int __fd, off_t __offset, int __whence);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_file_offset_bits/run.sh b/tools/versioner/tests/preprocessor_file_offset_bits/run.sh
deleted file mode 100644
index d974cba..0000000
--- a/tools/versioner/tests/preprocessor_file_offset_bits/run.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-set -e
-
-rm -rf out
-versioner headers -a 9 -a 12 -a 13 -i -o out
-diff -q -w -B out expected
diff --git a/tools/versioner/tests/preprocessor_idempotence/expected/foo.h b/tools/versioner/tests/preprocessor_idempotence/expected/foo.h
deleted file mode 100644
index bc442e5..0000000
--- a/tools/versioner/tests/preprocessor_idempotence/expected/foo.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#if __ANDROID_API__ >= 10
-int foo() __INTRODUCED_IN(10);
-#endif
-
-#if __ANDROID_API__ >= 21
-int bar(int) __INTRODUCED_IN(21);
-#endif
-
-#if __ANDROID_API__ >= 10
-int multiple_1() __INTRODUCED_IN(10);
-int multiple_2() __INTRODUCED_IN(10);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_idempotence/headers/foo.h b/tools/versioner/tests/preprocessor_idempotence/headers/foo.h
deleted file mode 100644
index bc442e5..0000000
--- a/tools/versioner/tests/preprocessor_idempotence/headers/foo.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#if __ANDROID_API__ >= 10
-int foo() __INTRODUCED_IN(10);
-#endif
-
-#if __ANDROID_API__ >= 21
-int bar(int) __INTRODUCED_IN(21);
-#endif
-
-#if __ANDROID_API__ >= 10
-int multiple_1() __INTRODUCED_IN(10);
-int multiple_2() __INTRODUCED_IN(10);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_idempotence/run.sh b/tools/versioner/tests/preprocessor_idempotence/run.sh
deleted file mode 100644
index 1b0aae2..0000000
--- a/tools/versioner/tests/preprocessor_idempotence/run.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-rm -rf out
-set -e
-versioner headers -i -o out
-diff -q -w -B out expected
diff --git a/tools/versioner/tests/preprocessor_merging/expected/foo.h b/tools/versioner/tests/preprocessor_merging/expected/foo.h
deleted file mode 100644
index ecd7f71..0000000
--- a/tools/versioner/tests/preprocessor_merging/expected/foo.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-
-#if __ANDROID_API__ >= 10
-int block_merging_1() __INTRODUCED_IN(10); // foo
-int block_merging_2() __INTRODUCED_IN(10); /* bar */
-int block_merging_3() __INTRODUCED_IN(10); /* baz
-//*/
-int block_merging_4() __INTRODUCED_IN(10);
-#endif /* __ANDROID_API__ >= 10 */
-
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_merging/headers/foo.h b/tools/versioner/tests/preprocessor_merging/headers/foo.h
deleted file mode 100644
index 7aaa471..0000000
--- a/tools/versioner/tests/preprocessor_merging/headers/foo.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int block_merging_1() __INTRODUCED_IN(10); // foo
-int block_merging_2() __INTRODUCED_IN(10); /* bar */
-int block_merging_3() __INTRODUCED_IN(10); /* baz
-//*/
-int block_merging_4() __INTRODUCED_IN(10);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_merging/run.sh b/tools/versioner/tests/preprocessor_merging/run.sh
deleted file mode 100644
index 1929757..0000000
--- a/tools/versioner/tests/preprocessor_merging/run.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-rm -rf out
-set -e
-versioner headers -a 9 -a 10 -a 11 -i -o out
-diff -q -w -B out expected
diff --git a/tools/versioner/tests/preprocessor_no_guard/expected/foo.h b/tools/versioner/tests/preprocessor_no_guard/expected/foo.h
deleted file mode 100644
index 3ef0c30..0000000
--- a/tools/versioner/tests/preprocessor_no_guard/expected/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __VERSIONER_NO_GUARD __INTRODUCED_IN(14);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_no_guard/headers/foo.h b/tools/versioner/tests/preprocessor_no_guard/headers/foo.h
deleted file mode 100644
index 3ef0c30..0000000
--- a/tools/versioner/tests/preprocessor_no_guard/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __VERSIONER_NO_GUARD __INTRODUCED_IN(14);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/preprocessor_no_guard/run.sh b/tools/versioner/tests/preprocessor_no_guard/run.sh
deleted file mode 100644
index 1b0aae2..0000000
--- a/tools/versioner/tests/preprocessor_no_guard/run.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-rm -rf out
-set -e
-versioner headers -i -o out
-diff -q -w -B out expected
diff --git a/tools/versioner/tests/slow_preprocessor_idempotence/run.sh b/tools/versioner/tests/slow_preprocessor_idempotence/run.sh
deleted file mode 100644
index 6426156..0000000
--- a/tools/versioner/tests/slow_preprocessor_idempotence/run.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-rm -rf out
-set -e
-mkdir out
-versioner -o out/initial
-versioner out/initial ../../dependencies -o out/second
-diff -qrwB out/initial out/second
diff --git a/tools/versioner/tests/smoke/headers/foo.h b/tools/versioner/tests/smoke/headers/foo.h
deleted file mode 100644
index c201dbb..0000000
--- a/tools/versioner/tests/smoke/headers/foo.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-int foo() __INTRODUCED_IN(9);
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/smoke/platforms/libc.map.txt b/tools/versioner/tests/smoke/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/smoke/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/smoke/run.sh b/tools/versioner/tests/smoke/run.sh
deleted file mode 100644
index a34fda8..0000000
--- a/tools/versioner/tests/smoke/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/unnamed_bitfield/headers/foo.h b/tools/versioner/tests/unnamed_bitfield/headers/foo.h
deleted file mode 100644
index 58686c3..0000000
--- a/tools/versioner/tests/unnamed_bitfield/headers/foo.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// <sys/timex.h> was causing a segfault when compiled in C++ mode because
-// versioner was trying to mangle the name of an unnamed bitfield.
-struct foo {
- int : 32;
- int : 32;
- int : 32;
- int : 32;
-};
diff --git a/tools/versioner/tests/unnamed_bitfield/platforms/libc.map.txt b/tools/versioner/tests/unnamed_bitfield/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/unnamed_bitfield/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/unnamed_bitfield/run.sh b/tools/versioner/tests/unnamed_bitfield/run.sh
deleted file mode 100644
index a34fda8..0000000
--- a/tools/versioner/tests/unnamed_bitfield/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -i
\ No newline at end of file
diff --git a/tools/versioner/tests/version_mismatch/expected_fail b/tools/versioner/tests/version_mismatch/expected_fail
deleted file mode 100644
index 95d284b..0000000
--- a/tools/versioner/tests/version_mismatch/expected_fail
+++ /dev/null
@@ -1,8 +0,0 @@
-versioner: inconsistent availability for symbol 'foo'
-versioner: failed to calculate symbol availability
- foo: invalid
- extern declaration @ headers/foo.h:6:1
- introduced = 9
- extern declaration @ headers/foo.h:8:1
- introduced = 10
-versioner: validity check failed
diff --git a/tools/versioner/tests/version_mismatch/headers/foo.h b/tools/versioner/tests/version_mismatch/headers/foo.h
deleted file mode 100644
index ea35f36..0000000
--- a/tools/versioner/tests/version_mismatch/headers/foo.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#if __ANDROID_API__ <= 9
-int foo() __INTRODUCED_IN(9);
-#else
-int foo() __INTRODUCED_IN(10);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
diff --git a/tools/versioner/tests/version_mismatch/platforms/libc.map.txt b/tools/versioner/tests/version_mismatch/platforms/libc.map.txt
deleted file mode 100644
index 6cc4a2e..0000000
--- a/tools/versioner/tests/version_mismatch/platforms/libc.map.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-LIBC {
- global:
- foo;
-};
diff --git a/tools/versioner/tests/version_mismatch/run.sh b/tools/versioner/tests/version_mismatch/run.sh
deleted file mode 100644
index 9bfbe6d..0000000
--- a/tools/versioner/tests/version_mismatch/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-versioner headers -p platforms -r arm -a 9 -a 12 -i
\ No newline at end of file