| # Copyright 2021 The Fuchsia 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/components.gni") |
| import("//build/cpp/cpp_fuzzer.gni") |
| import("//build/test.gni") |
| import("//build/testing/zbi_test.gni") |
| import("//build/zircon/migrated_targets.gni") |
| |
| is_elf = current_os != "mac" && current_os != "win" |
| |
| zx_library("elfldltl") { |
| sdk = "source" |
| sdk_headers = [ |
| "lib/elfldltl/compat-hash.h", |
| "lib/elfldltl/constants.h", |
| "lib/elfldltl/diagnostics.h", |
| "lib/elfldltl/dynamic.h", |
| "lib/elfldltl/field.h", |
| "lib/elfldltl/fuzzer.h", |
| "lib/elfldltl/gnu-hash.h", |
| "lib/elfldltl/init-fini.h", |
| "lib/elfldltl/internal/const-string.h", |
| "lib/elfldltl/internal/dynamic-tag-error.h", |
| "lib/elfldltl/internal/phdr-error.h", |
| "lib/elfldltl/layout.h", |
| "lib/elfldltl/link.h", |
| "lib/elfldltl/machine.h", |
| "lib/elfldltl/memory.h", |
| "lib/elfldltl/note.h", |
| "lib/elfldltl/phdr.h", |
| "lib/elfldltl/relocation.h", |
| "lib/elfldltl/relro.h", |
| "lib/elfldltl/self.h", |
| "lib/elfldltl/static-pie.h", |
| "lib/elfldltl/static-pie-with-vdso.h", |
| "lib/elfldltl/symbol.h", |
| ] |
| |
| sources = [] |
| if (is_elf) { |
| sources += [ "self.cc" ] |
| configs += [ "//build/config/sanitizers:no_sanitizers" ] |
| libs = [ "./self-base.ld" ] |
| } |
| |
| public_deps = [ "//sdk/lib/stdcompat" ] |
| |
| if (is_kernel) { |
| deps = [ |
| "//zircon/kernel/lib/ktl", |
| "//zircon/kernel/lib/libc", |
| ] |
| } |
| |
| if (current_os == "linux") { |
| configs -= [ "//build/config/linux:implicit-host-libs" ] |
| } |
| } |
| |
| test("elfldltl-unittests") { |
| deps = [ ":unittests" ] |
| } |
| |
| # These pure unit tests can be included in a standalone ZBI test binary too. |
| source_set("unittests") { |
| sources = [ |
| "diagnostics-tests.cc", |
| "dynamic-tests.cc", |
| "field-tests.cc", |
| "initfini-tests.cc", |
| "internal-tests.cc", |
| "layout-tests.cc", |
| "memory-tests.cc", |
| "note-tests.cc", |
| "phdr-tests.cc", |
| "relocation-tests.cc", |
| "symbol-tests.cc", |
| "symbol-tests.h", |
| "tests.h", |
| ] |
| deps = [ |
| ".", |
| "//sdk/lib/stdcompat", |
| "//zircon/system/ulib/zxtest", |
| ] |
| if (is_elf) { |
| sources += [ "self-tests.cc" ] |
| } |
| } |
| |
| if (current_os == "linux") { |
| config("linux-static-pie.config") { |
| # Avoid libc references from assert() in libc++ header code. |
| defines = [ "NDEBUG=1" ] |
| include_dirs = [ "//third_party/linux-syscall-support" ] |
| } |
| |
| static_library("linux-static-pie") { |
| sources = [ "linux-static-pie.cc" ] |
| configs -= [ "//build/config/linux:implicit-host-libs" ] |
| configs += [ ":linux-static-pie.config" ] |
| deps = [ "." ] |
| } |
| |
| if (current_toolchain == host_toolchain) { |
| host_test("linux-static-pie-test") { |
| deps = [ ":linux-static-pie-test(//build/toolchain:linux_$host_cpu)" ] |
| binary_path = get_label_info(deps[0], "root_out_dir") + "/" + |
| get_label_info(deps[0], "name") |
| } |
| } else { |
| test("linux-static-pie-test") { |
| disable_syslog_backend = true |
| sources = [ "linux-static-pie-test.cc" ] |
| configs -= [ |
| "//build/config/linux:default-pie", |
| "//build/config/linux:implicit-host-libs", |
| ] |
| configs += [ ":linux-static-pie.config" ] |
| cflags = [ "-fPIE" ] |
| ldflags = [ |
| "-nostartfiles", |
| "-nostdlib++", |
| "-static-pie", |
| "-nolibc", |
| ] |
| deps = [ ":linux-static-pie" ] |
| |
| exclude_toolchain_tags = [ "instrumented" ] |
| } |
| } |
| } |
| |
| if (is_fuchsia) { |
| static_library("static-pie") { |
| sources = [ "fuchsia-static-pie.cc" ] |
| configs += [ "//build/config/fuchsia:static-pie-config" ] |
| deps = [ "." ] |
| |
| # Avoid libc references from assert() in libc++ header code. |
| defines = [ "NDEBUG=1" ] |
| } |
| |
| test("fuchsia-static-pie-test") { |
| sources = [ "fuchsia-static-pie-test.cc" ] |
| |
| # Avoid libc references from assert() in libc++ header code. |
| defines = [ "NDEBUG=1" ] |
| |
| configs += [ "//build/config/fuchsia:static-pie-config" ] |
| if (zircon_toolchain == false) { |
| configs -= [ "//build/config/fuchsia:fdio_config" ] |
| } |
| disable_syslog_backend = true |
| |
| ldflags = [ |
| # The build system makes it impossible to avoid the libc dep. But this |
| # can avoid it creating a spurious DT_NEEDED, though that's harmless |
| # enough since nothing looks at those without a dynamic linker. |
| "-Wl,--as-needed", |
| |
| # A standalone binary should indicate its stack requirements. |
| # They should be minimal for this test. |
| "-Wl,-z,stack-size=0x1000", |
| ] |
| |
| deps = [ |
| ":static-pie", |
| "//src/zircon/lib/zircon", |
| "//zircon/third_party/ulib/musl/src/exit:abort", |
| "//zircon/third_party/ulib/musl/src/string:stdmem", |
| ] |
| |
| exclude_toolchain_tags = [ "instrumented" ] |
| } |
| } |
| |
| fuchsia_unittest_package("elfldltl-static-pie-test") { |
| deps = [ |
| ":fuchsia-static-pie-test", |
| "//src/sys/testing/elftest", |
| ] |
| } |
| |
| # Make that into a bootable ZBI with just the kernel. |
| zbi_test("zbi-static-pie-test") { |
| args = [ |
| "userboot=test/fuchsia-static-pie-test", |
| "kernel.enable-serial-syscalls=true", |
| ] |
| |
| deps = [ |
| ":fuchsia-static-pie-test", |
| "//zircon/kernel", |
| ] |
| assert_no_deps = [ |
| "//zircon/system/core/*", |
| "//zircon/system/dev/*", |
| ] |
| } |
| |
| fuchsia_unittest_package("elfldltl-tests") { |
| deps = [ ":elfldltl-unittests" ] |
| } |
| |
| cpp_fuzzer("dynamic-fuzzer") { |
| sources = [ "dynamic-fuzzer.cc" ] |
| deps = [ "." ] |
| } |
| |
| cpp_fuzzer("note-fuzzer") { |
| sources = [ "note-fuzzer.cc" ] |
| deps = [ "." ] |
| } |
| |
| cpp_fuzzer("relocation-fuzzer") { |
| sources = [ "relocation-fuzzer.cc" ] |
| deps = [ "." ] |
| } |
| |
| cpp_fuzzer("symbol-fuzzer") { |
| sources = [ "symbol-fuzzer.cc" ] |
| deps = [ "." ] |
| } |
| |
| fuzzer_package("elfldltl-fuzzers") { |
| fuzz_host = true |
| cpp_fuzzers = [ |
| ":dynamic-fuzzer", |
| ":note-fuzzer", |
| ":relocation-fuzzer", |
| ":symbol-fuzzer", |
| ] |
| } |
| |
| group("tests") { |
| testonly = true |
| |
| deps = [ |
| ":elfldltl-fuzzers", |
| ":elfldltl-static-pie-test", |
| ":elfldltl-tests", |
| ":elfldltl-unittests($host_toolchain)", |
| ":zbi-static-pie-test", |
| ] |
| |
| if (host_os == "linux") { |
| deps += [ ":linux-static-pie-test($host_toolchain)" ] |
| } |
| } |