aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelvin Zhang <zhangkelvin@google.com>2021-08-18 17:59:45 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-08-18 17:59:45 +0000
commitf236f926d504e63de23fbb5693c42672485f3852 (patch)
treeb785bdf9ce143363c8154f92ff8f163902eb32a1
parent26118fbabd48d66e44b15399dd3011c5b722c1c5 (diff)
parent01480cf7fb9f1bfdd1d637a512fe50f810e452ae (diff)
downloadzucchini-f236f926d504e63de23fbb5693c42672485f3852.tar.gz
Get zucchini to compile on AOSP am: 011d854311 am: b5f9632072 am: 496408893a am: e2c5010bc9 am: 01480cf7fb
Original change: https://android-review.googlesource.com/c/platform/external/zucchini/+/1799408 Change-Id: I5b38343de40eed3fb60f9857f6202cc97dce7c10
-rw-r--r--Android.bp146
-rw-r--r--aosp/include/absl/types/optional.h28
-rw-r--r--aosp/include/base/check.h22
-rw-r--r--aosp/include/base/check_op.h22
-rw-r--r--aosp/include/base/containers/cxx20_erase.h22
-rw-r--r--aosp/include/base/notreached.h22
-rw-r--r--aosp/include/build/buildflag.h47
-rw-r--r--aosp/include/buildflags.h14
-rwxr-xr-xaosp/preprocess.py31
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))