diff options
author | Kelvin Zhang <zhangkelvin@google.com> | 2021-07-29 14:50:32 -0400 |
---|---|---|
committer | Kelvin Zhang <zhangkelvin@google.com> | 2021-08-17 17:18:51 -0700 |
commit | 011d854311a08d777daba6cf81fd41d62921827a (patch) | |
tree | b785bdf9ce143363c8154f92ff8f163902eb32a1 | |
parent | ae55a30d74dec9fd3590d2b016420a2d3b28c236 (diff) | |
download | zucchini-011d854311a08d777daba6cf81fd41d62921827a.tar.gz |
Get zucchini to compile on AOSP
Test: mm
Change-Id: Ia030273fcc71d0920f2c62327a08903e5e27a544
-rw-r--r-- | Android.bp | 146 | ||||
-rw-r--r-- | aosp/include/absl/types/optional.h | 28 | ||||
-rw-r--r-- | aosp/include/base/check.h | 22 | ||||
-rw-r--r-- | aosp/include/base/check_op.h | 22 | ||||
-rw-r--r-- | aosp/include/base/containers/cxx20_erase.h | 22 | ||||
-rw-r--r-- | aosp/include/base/notreached.h | 22 | ||||
-rw-r--r-- | aosp/include/build/buildflag.h | 47 | ||||
-rw-r--r-- | aosp/include/buildflags.h | 14 | ||||
-rwxr-xr-x | aosp/preprocess.py | 31 |
9 files changed, 354 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..df2ba83 --- /dev/null +++ b/Android.bp @@ -0,0 +1,146 @@ + +filegroup { + name: "libzucchini_srcs", + + srcs: [ + "abs32_utils.cc", + "address_translator.cc", + "arm_utils.cc", + "binary_data_histogram.cc", + "buffer_sink.cc", + "buffer_source.cc", + "crc32.cc", + "disassembler.cc", + "disassembler_dex.cc", + "disassembler_elf.cc", + "disassembler_no_op.cc", + "disassembler_win32.cc", + "disassembler_ztf.cc", + "element_detection.cc", + "encoded_view.cc", + "ensemble_matcher.cc", + "equivalence_map.cc", + "heuristic_ensemble_matcher.cc", + "image_index.cc", + "imposed_ensemble_matcher.cc", + "io_utils.cc", + "patch_reader.cc", + "patch_writer.cc", + "reference_bytes_mixer.cc", + "reference_set.cc", + "rel32_finder.cc", + "rel32_utils.cc", + "reloc_elf.cc", + "reloc_win32.cc", + "target_pool.cc", + "targets_affinity.cc", + "zucchini_apply.cc", + "zucchini_gen.cc", + "zucchini_tools.cc", + ], +} + +filegroup { + name: "libzucchini_headers", + srcs: [ + "abs32_utils.h", + "address_translator.h", + "algorithm.h", + "arm_utils.h", + "binary_data_histogram.h", + "buffer_sink.h", + "buffer_source.h", + "buffer_view.h", + "crc32.h", + "disassembler.h", + "disassembler_dex.h", + "disassembler_elf.h", + "disassembler_no_op.h", + "disassembler_win32.h", + "disassembler_ztf.h", + "element_detection.h", + "encoded_view.h", + "ensemble_matcher.h", + "equivalence_map.h", + "heuristic_ensemble_matcher.h", + "image_index.h", + "image_utils.h", + "imposed_ensemble_matcher.h", + "io_utils.h", + "main_utils.h", + "mapped_file.h", + "patch_reader.h", + "patch_utils.h", + "patch_writer.h", + "reference_bytes_mixer.h", + "reference_set.h", + "rel32_finder.h", + "rel32_utils.h", + "reloc_elf.h", + "reloc_win32.h", + "suffix_array.h", + "target_pool.h", + "targets_affinity.h", + "test_disassembler.h", + "test_reference_reader.h", + "test_utils.h", + "type_dex.h", + "type_elf.h", + "type_win_pe.h", + "type_ztf.h", + "typed_value.h", + "zucchini.h", + "zucchini_apply.h", + "zucchini_commands.h", + "zucchini_gen.h", + "zucchini_integration.h", + "zucchini_tools.h", + ], +} + +// The aosp versions of sources are preprocesseed with include +// re-written in an AOSP compatible way. Some headers, such as +// absl, are simply redirected to STL equivalent. +gensrcs { + name: "libzucchini_aosp_srcs", + cmd: "$(location aosp/preprocess.py) $(in) $(out)", + tool_files: ["aosp/preprocess.py"], + srcs: [":libzucchini_srcs"], + output_extension: "cc", +} + +gensrcs { + name: "libzucchini_aosp_headers", + cmd: "$(location aosp/preprocess.py) $(in) $(out)", + tool_files: ["aosp/preprocess.py"], + srcs: [":libzucchini_headers"], + export_include_dirs: ["."], + output_extension: "h", +} + + +cc_library { + name: "libzucchini", + host_supported: true, + // Need this to ensure that the generated headers are used, + // instead of loacl ones. As the generated headers contain + // incorrect include paths + include_build_directory: false, + srcs: [":libzucchini_aosp_srcs"], + generated_headers: ["libzucchini_aosp_headers"], + local_include_dirs: ["aosp/include"], + export_generated_headers: ["libzucchini_aosp_headers"], + export_include_dirs: ["aosp/include"], + static_libs: [ + "libchrome", + "libcutils", + ], + shared_libs: [ + "liblog", + "libbase", + ], + cflags: [ + "-Wno-unused-parameter", + ], + visibility: ["//system/update_engine:__subpackages__"], +} diff --git a/aosp/include/absl/types/optional.h b/aosp/include/absl/types/optional.h new file mode 100644 index 0000000..3321c72 --- /dev/null +++ b/aosp/include/absl/types/optional.h @@ -0,0 +1,28 @@ +// +// Copyright (C) 2021 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. +// + +#ifndef __ZUCCHINI_AOSP_ABSL_OPTIONAL_H +#define __ZUCCHINI_AOSP_ABSL_OPTIONAL_H + +#include <optional> + +namespace absl { + template <typename T> using optional = std::optional<T>; + inline constexpr auto nullopt = std::nullopt; +} + +#endif + diff --git a/aosp/include/base/check.h b/aosp/include/base/check.h new file mode 100644 index 0000000..3ed2e04 --- /dev/null +++ b/aosp/include/base/check.h @@ -0,0 +1,22 @@ +// +// Copyright (C) 2021 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. +// + +#ifndef __ZUCCHINI_AOSP_BASE_CHECK_H +#define __ZUCCHINI_AOSP_BASE_CHECK_H + +#include <base/logging.h> + +#endif /* __ZUCCHINI_AOSP_BASE_CHECK_H */ diff --git a/aosp/include/base/check_op.h b/aosp/include/base/check_op.h new file mode 100644 index 0000000..d72e4a4 --- /dev/null +++ b/aosp/include/base/check_op.h @@ -0,0 +1,22 @@ +// +// Copyright (C) 2021 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. +// + +#ifndef __ZUCCHINI_AOSP_BASE_CHECK_OP_H +#define __ZUCCHINI_AOSP_BASE_CHECK_OP_H + +#include <base/logging.h> + +#endif /* __ZUCCHINI_AOSP_BASE_CHECK_OP_H */ diff --git a/aosp/include/base/containers/cxx20_erase.h b/aosp/include/base/containers/cxx20_erase.h new file mode 100644 index 0000000..2fac314 --- /dev/null +++ b/aosp/include/base/containers/cxx20_erase.h @@ -0,0 +1,22 @@ +// +// Copyright (C) 2021 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. +// + +#ifndef __ZUCCHINI_AOSP_BASE_CONTAINERS_CXX20_ERASE_H +#define __ZUCCHINI_AOSP_BASE_CONTAINERS_CXX20_ERASE_H + +#include <base/stl_util.h> + +#endif diff --git a/aosp/include/base/notreached.h b/aosp/include/base/notreached.h new file mode 100644 index 0000000..631285c --- /dev/null +++ b/aosp/include/base/notreached.h @@ -0,0 +1,22 @@ +// +// Copyright (C) 2021 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. +// + +#ifndef __ZUCCHINI_AOSP_BASE_NOTREACHED_H +#define __ZUCCHINI_AOSP_BASE_NOTREACHED_H + +#include <base/logging.h> + +#endif /* __ZUCCHINI_AOSP_BASE_NOTREACHED_H */ diff --git a/aosp/include/build/buildflag.h b/aosp/include/build/buildflag.h new file mode 100644 index 0000000..8d7c0e0 --- /dev/null +++ b/aosp/include/build/buildflag.h @@ -0,0 +1,47 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BUILD_BUILDFLAG_H_ +#define BUILD_BUILDFLAG_H_ + +// These macros un-mangle the names of the build flags in a way that looks +// natural, and gives errors if the flag is not defined. Normally in the +// preprocessor it's easy to make mistakes that interpret "you haven't done +// the setup to know what the flag is" as "flag is off". Normally you would +// include the generated header rather than include this file directly. +// +// This is for use with generated headers. See build/buildflag_header.gni. + +// This dance of two macros does a concatenation of two preprocessor args using +// ## doubly indirectly because using ## directly prevents macros in that +// parameter from being expanded. +#define BUILDFLAG_CAT_INDIRECT(a, b) a##b +#define BUILDFLAG_CAT(a, b) BUILDFLAG_CAT_INDIRECT(a, b) + +// Accessor for build flags. +// +// To test for a value, if the build file specifies: +// +// ENABLE_FOO=true +// +// Then you would check at build-time in source code with: +// +// #include "foo_flags.h" // The header the build file specified. +// +// #if BUILDFLAG(ENABLE_FOO) +// ... +// #endif +// +// There will no #define called ENABLE_FOO so if you accidentally test for +// whether that is defined, it will always be negative. You can also use +// the value in expressions: +// +// const char kSpamServerName[] = BUILDFLAG(SPAM_SERVER_NAME); +// +// Because the flag is accessed as a preprocessor macro with (), an error +// will be thrown if the proper header defining the internal flag value has +// not been included. +#define BUILDFLAG(flag) (BUILDFLAG_CAT(BUILDFLAG_INTERNAL_, flag)()) + +#endif // BUILD_BUILDFLAG_H_ diff --git a/aosp/include/buildflags.h b/aosp/include/buildflags.h new file mode 100644 index 0000000..2b63e59 --- /dev/null +++ b/aosp/include/buildflags.h @@ -0,0 +1,14 @@ +// Generated by build/write_buildflag_header.py +// From "//components/zucchini:buildflags" + +#ifndef COMPONENTS_ZUCCHINI_BUILDFLAGS_H_ +#define COMPONENTS_ZUCCHINI_BUILDFLAGS_H_ + +#include "build/buildflag.h" + +#define BUILDFLAG_INTERNAL_ENABLE_DEX() (1) +#define BUILDFLAG_INTERNAL_ENABLE_ELF() (1) +#define BUILDFLAG_INTERNAL_ENABLE_WIN() (0) +#define BUILDFLAG_INTERNAL_ENABLE_ZTF() (0) + +#endif // COMPONENTS_ZUCCHINI_BUILDFLAGS_H_ diff --git a/aosp/preprocess.py b/aosp/preprocess.py new file mode 100755 index 0000000..7a31ffc --- /dev/null +++ b/aosp/preprocess.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +# ChromeOs version of zucchini expects to find its headers +# in a specifc path. In android the include paths are slightly +# different. Since we can't change upstream source code, we +# use this script to preprocess all files(.cc and ,h) and +# re-write all include paths + + +def main(argv): + if len(argv) != 3: + print("Usage:", argv[0], "<input path> <output path>") + return 1 + input_path = argv[1] + output_path = argv[2] + with open(input_path, "r") as infp, open(output_path, "w") as outfp: + for line in infp.readlines(): + line = line.replace('#include "components/zucchini/', + '#include "') + line = line.replace('#include <components/zucchini/', + '#include <') + line = line.replace('#include "third_party/abseil-cpp/', + '#include "') + line = line.replace('#include <third_party/abseil-cpp/', + '#include <') + outfp.write(line) + + +if __name__ == '__main__': + import sys + sys.exit(main(sys.argv)) |