| # Copyright 2019 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/test.gni") |
| |
| import("//build/zircon/c_utils.gni") |
| |
| fuchsia_unittest_package("fdio-constructor-unittest-package") { |
| deps = [ ":fdio-constructor" ] |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ ":fdio-constructor-unittest-package" ] |
| } |
| |
| # This bogus test is necessary to have the verification run in the variant |
| # toolchain. |
| test("fdio-constructor") { |
| output_name = "fdio-constructor-test" |
| |
| sources = [ "bogus-test.cc" ] |
| |
| # fdio must not have any static constructors, because its code must work |
| # before static constructors have run. Some compiler instrumentation |
| # modes generate static constructors that are harmless and superfluous, so |
| # don't check those builds. Note that it's important that this be in deps |
| # here rather than in the group() above, because this will be evaluated |
| # after variant selection has chosen which build to actually test. |
| if (!toolchain_variant.instrumented) { |
| deps = [ |
| ":no-static-ctor", |
| "//src/sys/testing/elftest", |
| ] |
| } else { |
| deps = [ "//src/sys/testing/elftest" ] |
| } |
| } |
| |
| fdio_rspfile = "$target_gen_dir/fdio.rsp" |
| link_output_rspfile("fdio-rspfile") { |
| visibility = [ ":*" ] |
| deps = [ "//sdk/lib/fdio" ] |
| outputs = [ fdio_rspfile ] |
| } |
| |
| toolchain_utils_action("no-static-ctor") { |
| max_ctors = 0 |
| if (current_cpu == "arm64") { |
| # Known constructor on arm `init_have_lse_atomics` from libclang_rt.builtins |
| max_ctors += 1 |
| } |
| |
| testonly = true |
| script = "no-static-ctor.sh" |
| utils = [ "readelf" ] |
| outputs = [ "$target_out_dir/$target_name" ] |
| depfile = "${outputs[0]}.d" |
| deps = [ ":fdio-rspfile" ] |
| inputs = [ fdio_rspfile ] |
| args = [ |
| "@" + rebase_path(fdio_rspfile, root_build_dir), |
| rebase_path(outputs[0], root_build_dir), |
| rebase_path(depfile, root_build_dir), |
| "$max_ctors", |
| ] |
| } |