blob: 981369c327c46f758cb9104b243b09e307e1acfb [file] [log] [blame]
# Copyright 2014 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.
import("//build/config/android/config.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
# NOTE: This file is included in Linux builds to build the
# crazy_linker_zip_fuzzer target (see below). However, the rest of the
# crazy linker doesn't build or work on Linux yet.
config("crazy_config") {
include_dirs = [ "src/include" ]
if (is_android) {
libs = [
"log",
"dl",
]
}
}
if (is_android) {
group("android_crazy_linker_tests") {
deps = [
":android_crazy_linker_unittests",
":crazy_linker_bench_load_library",
":crazy_linker_test_constructors_destructors",
":crazy_linker_test_dl_wrappers",
":crazy_linker_test_dl_wrappers_recursive",
":crazy_linker_test_dl_wrappers_valid_handles",
":crazy_linker_test_dl_wrappers_with_system_handle",
":crazy_linker_test_jni_hooks",
":crazy_linker_test_load_library",
":crazy_linker_test_load_library_depends",
":crazy_linker_test_load_library_with_gnu_hash_table",
":crazy_linker_test_load_library_with_relr_relocations",
":crazy_linker_test_relocated_shared_relro",
":crazy_linker_test_search_path_list",
":crazy_linker_test_shared_relro",
":crazy_linker_test_two_shared_relros",
":run_android_crazy_linker_tests",
]
testonly = true
}
# Template to define a source set for the crazy linker.
# This takes a single boolean parameter:
#
# unit_tests: if true, build a version with unit-testing support.
#
template("crazy_linker_library") {
source_set(target_name) {
forward_variables_from(invoker, "*")
sources = [
"src/include/crazy_linker.h",
"src/src/crazy_linker_api.cpp",
"src/src/crazy_linker_ashmem.cpp",
"src/src/crazy_linker_ashmem.h",
"src/src/crazy_linker_debug.cpp",
"src/src/crazy_linker_debug.h",
"src/src/crazy_linker_defines.h",
"src/src/crazy_linker_elf_hash_table.cpp",
"src/src/crazy_linker_elf_hash_table.h",
"src/src/crazy_linker_elf_loader.cpp",
"src/src/crazy_linker_elf_loader.h",
"src/src/crazy_linker_elf_relocations.cpp",
"src/src/crazy_linker_elf_relocations.h",
"src/src/crazy_linker_elf_relro.cpp",
"src/src/crazy_linker_elf_relro.h",
"src/src/crazy_linker_elf_symbols.cpp",
"src/src/crazy_linker_elf_symbols.h",
"src/src/crazy_linker_elf_view.cpp",
"src/src/crazy_linker_elf_view.h",
"src/src/crazy_linker_error.cpp",
"src/src/crazy_linker_error.h",
"src/src/crazy_linker_globals.cpp",
"src/src/crazy_linker_globals.h",
"src/src/crazy_linker_gnu_hash_table.cpp",
"src/src/crazy_linker_gnu_hash_table.h",
"src/src/crazy_linker_library_list.cpp",
"src/src/crazy_linker_library_list.h",
"src/src/crazy_linker_library_view.cpp",
"src/src/crazy_linker_library_view.h",
"src/src/crazy_linker_line_reader.cpp",
"src/src/crazy_linker_line_reader.h",
"src/src/crazy_linker_memory_mapping.cpp",
"src/src/crazy_linker_memory_mapping.h",
"src/src/crazy_linker_pointer_set.cpp",
"src/src/crazy_linker_pointer_set.h",
"src/src/crazy_linker_proc_maps.cpp",
"src/src/crazy_linker_proc_maps.h",
"src/src/crazy_linker_rdebug.cpp",
"src/src/crazy_linker_rdebug.h",
"src/src/crazy_linker_relr_relocations.cpp",
"src/src/crazy_linker_relr_relocations.h",
"src/src/crazy_linker_search_path_list.cpp",
"src/src/crazy_linker_search_path_list.h",
"src/src/crazy_linker_shared_library.cpp",
"src/src/crazy_linker_shared_library.h",
"src/src/crazy_linker_system.cpp",
"src/src/crazy_linker_system.h",
"src/src/crazy_linker_system_android.cpp",
"src/src/crazy_linker_system_android.h",
"src/src/crazy_linker_system_linker.cpp",
"src/src/crazy_linker_system_linker.h",
"src/src/crazy_linker_thread_data.cpp",
"src/src/crazy_linker_thread_data.h",
"src/src/crazy_linker_util.cpp",
"src/src/crazy_linker_util.h",
"src/src/crazy_linker_wrappers.cpp",
"src/src/crazy_linker_wrappers.h",
"src/src/crazy_linker_zip.cpp",
"src/src/crazy_linker_zip.h",
"src/src/elf_traits.h",
"src/src/linker_phdr.cpp",
"src/src/linker_phdr.h",
"src/src/linker_reloc_iterators.h",
"src/src/linker_sleb128.h",
]
include_dirs = [ "src/src" ]
if (defined(unit_tests) && unit_tests) {
sources += [
"src/src/crazy_linker_system_mock.cpp",
"src/src/crazy_linker_system_mock.h",
]
defines = [
"UNIT_TEST",
"CRAZY_DEBUG=1",
]
} else {
# Disable r_brk() calls for release builds. This is a work-around for
# unexplained runtime crashes that happen on Intel-based Android
# devices that run ARM binaries through Houdini. For more details
# see https://crbug.com/796938
if (!is_debug) {
defines = [ "CRAZY_DISABLE_R_BRK" ]
}
}
public_configs = [ ":crazy_config" ]
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}
}
crazy_linker_library("android_crazy_linker") {
}
crazy_linker_library("android_crazy_linker_for_unittests") {
unit_tests = true
}
test("android_crazy_linker_unittests") {
sources = [
"src/src/crazy_linker_ashmem_unittest.cpp",
"src/src/crazy_linker_elf_hash_table_unittest.cpp",
"src/src/crazy_linker_elf_symbols_unittest.cpp",
"src/src/crazy_linker_error_unittest.cpp",
"src/src/crazy_linker_globals_unittest.cpp",
"src/src/crazy_linker_gnu_hash_table_unittest.cpp",
"src/src/crazy_linker_line_reader_unittest.cpp",
"src/src/crazy_linker_pointer_set_unittest.cpp",
"src/src/crazy_linker_proc_maps_unittest.cpp",
"src/src/crazy_linker_relr_relocations_unittest.cpp",
"src/src/crazy_linker_search_path_list_unittest.cpp",
"src/src/crazy_linker_system_unittest.cpp",
"src/src/crazy_linker_thread_data_unittest.cpp",
"src/src/crazy_linker_util_threads_unittest.cpp",
"src/src/crazy_linker_util_unittest.cpp",
"src/src/crazy_linker_zip_test_data.cpp",
"src/src/crazy_linker_zip_test_data.h",
"src/src/crazy_linker_zip_unittest.cpp",
]
include_dirs = [ "src/src" ]
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
deps = [
":android_crazy_linker_for_unittests",
"//testing/gtest",
"//testing/gtest:gtest_main",
]
if (is_android) {
use_raw_android_executable = true
}
}
# The following are shared libraries used by the integration tests.
template("crazy_linker_test_library") {
shared_library(target_name) {
forward_variables_from(invoker,
[
"deps",
"data_deps",
"defines",
"ldflags",
])
sources = invoker.sources
libs = [ "log" ]
if (defined(invoker.libs)) {
libs += invoker.libs
}
# This is not Chromium code.
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
# All libraries expects their symbols to be visible.
if (is_android) {
configs -= [ "//build/config/android:hide_all_but_jni_onload" ]
}
configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
configs += [ "//build/config/gcc:symbol_visibility_default" ]
}
}
crazy_linker_test_library("crazy_linker_tests_libfoo") {
sources = [
"src/tests/foo.cpp",
]
}
crazy_linker_test_library("crazy_linker_tests_libfoo_with_gnu_hash_table") {
sources = [
"src/tests/foo.cpp",
]
ldflags = [ "-Wl,--hash-style=gnu" ]
}
crazy_linker_test_library("crazy_linker_tests_libfoo2") {
sources = [
"src/tests/foo2.cpp",
]
}
crazy_linker_test_library("crazy_linker_tests_libfoo_with_relro") {
sources = [
"src/tests/foo_with_relro.cpp",
]
}
crazy_linker_test_library("crazy_linker_tests_libfoo_with_relro_and_relr") {
sources = [
"src/tests/foo_with_relro.cpp",
]
ldflags = [ "-Wl,--pack-dyn-relocs=relr,--use-android-relr-tags" ]
}
crazy_linker_test_library(
"crazy_linker_tests_libfoo_with_static_constructor") {
sources = [
"src/tests/foo_with_static_constructor.cpp",
]
}
crazy_linker_test_library("crazy_linker_tests_libbar") {
sources = [
"src/tests/bar.cpp",
]
deps = [
":crazy_linker_tests_libfoo",
]
}
crazy_linker_test_library("crazy_linker_tests_libbar_with_relro") {
sources = [
"src/tests/bar_with_relro.cpp",
]
deps = [
":crazy_linker_tests_libfoo_with_relro",
]
}
crazy_linker_test_library("crazy_linker_tests_libbar_with_two_dlopens") {
sources = [
"src/tests/bar_with_two_dlopens.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo",
":crazy_linker_tests_libfoo2",
]
libs = [ "dl" ]
}
crazy_linker_test_library("crazy_linker_tests_libzoo") {
sources = [
"src/tests/zoo.cpp",
]
data_deps = [
":crazy_linker_tests_libbar",
]
}
crazy_linker_test_library("crazy_linker_tests_libzoo_with_dlopen_handle") {
sources = [
"src/tests/zoo_with_dlopen_handle.cpp",
]
libs = [ "dl" ]
}
crazy_linker_test_library("crazy_linker_tests_libzoo_dlopen_in_initializer") {
sources = [
"src/tests/zoo_with_dlopen_in_elf_initializer.cpp",
]
defines = [
"THIS_LIB_NAME=\"libzoo_dlopen_in_initializer\"",
"LIB_NAME=\"libcrazy_linker_tests_libzoo_dlopen_in_initializer_inner.so\"",
]
data_deps = [
":crazy_linker_tests_libzoo_dlopen_in_initializer_inner",
]
libs = [ "dl" ]
}
crazy_linker_test_library(
"crazy_linker_tests_libzoo_dlopen_in_initializer_inner") {
sources = [
"src/tests/zoo_with_dlopen_in_elf_initializer.cpp",
]
defines = [
"THIS_LIB_NAME=\"libzoo_dlopen_in_initializer_inner\"",
"LIB_NAME=\"libcrazy_linker_tests_libzoo.so\"",
]
data_deps = [
":crazy_linker_tests_libzoo",
]
libs = [ "dl" ]
}
crazy_linker_test_library("crazy_linker_tests_libjni_lib") {
sources = [
"src/tests/jni_lib.cpp",
]
}
# Integration tests are provided as standalone executables for now.
executable("crazy_linker_bench_load_library") {
sources = [
"src/tests/bench_load_library.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_jni_hooks") {
sources = [
"src/tests/test_jni_hooks.cpp",
]
data_deps = [
":crazy_linker_tests_libjni_lib",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_load_library") {
sources = [
"src/tests/test_load_library.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_load_library_with_relr_relocations") {
sources = [
"src/tests/test_load_library.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo_with_relro_and_relr",
]
defines =
[ "LIB_NAME=\"libcrazy_linker_tests_libfoo_with_relro_and_relr.so\"" ]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_load_library_depends") {
sources = [
"src/tests/test_load_library_depends.cpp",
]
data_deps = [
":crazy_linker_tests_libbar",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_constructors_destructors") {
sources = [
"src/tests/test_constructors_destructors.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo_with_static_constructor",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_load_library_with_gnu_hash_table") {
sources = [
"src/tests/test_load_library.cpp",
]
defines =
[ "LIB_NAME=\"libcrazy_linker_tests_libfoo_with_gnu_hash_table.so\"" ]
data_deps = [
":crazy_linker_tests_libfoo_with_gnu_hash_table",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_dl_wrappers") {
sources = [
"src/tests/test_dl_wrappers.cpp",
]
data_deps = [
":crazy_linker_tests_libzoo",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_dl_wrappers_recursive") {
sources = [
"src/tests/test_dl_wrappers_recursive.cpp",
]
data_deps = [
":crazy_linker_tests_libzoo_dlopen_in_initializer",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_dl_wrappers_with_system_handle") {
sources = [
"src/tests/test_dl_wrappers_with_system_handle.cpp",
]
data_deps = [
":crazy_linker_tests_libzoo_with_dlopen_handle",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_dl_wrappers_valid_handles") {
sources = [
"src/tests/test_dl_wrappers_valid_handles.cpp",
]
data_deps = [
":crazy_linker_tests_libbar_with_two_dlopens",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_search_path_list") {
sources = [
"src/tests/test_search_path_list.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo",
":crazy_linker_tests_libfoo2",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_relocated_shared_relro") {
sources = [
"src/tests/test_relocated_shared_relro.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo_with_relro",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_shared_relro") {
sources = [
"src/tests/test_shared_relro.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo_with_relro",
]
deps = [
":android_crazy_linker",
]
}
executable("crazy_linker_test_two_shared_relros") {
sources = [
"src/tests/test_two_shared_relros.cpp",
]
data_deps = [
":crazy_linker_tests_libfoo_with_relro",
":crazy_linker_tests_libbar_with_relro",
]
deps = [
":android_crazy_linker",
]
}
# Copy the script that runs all integration tests to the right directory.
copy("run_android_crazy_linker_tests") {
sources = [
"src/run_tests.sh",
]
outputs = [
"$root_out_dir/bin/run_android_crazy_linker_tests",
]
}
} # is_android
# NOTE: To build and run this on Linux, use the following commands after
# performing a Release build for Android:
#
# cd $CHROMIUM_SRC_DIR
# mkdir out/Fuzz
# gn gen out/Fuzz '--args=use_libfuzzer=true is_asan=true is_debug=false'
# ninja -C out/Fuzz android_crazy_linker_zip_fuzzer
# out/Fuzz/android_crazy_linker_zip_fuzzer out/Release/apks
#
fuzzer_test("android_crazy_linker_zip_fuzzer") {
sources = [
"src/src/crazy_linker_system.cpp",
"src/src/crazy_linker_system.h",
"src/src/crazy_linker_util.cpp",
"src/src/crazy_linker_util.h",
"src/src/crazy_linker_zip.cpp",
"src/src/crazy_linker_zip.h",
]
defines = [ "CRAZY_LINKER_ENABLE_FUZZING" ]
}