summaryrefslogtreecommitdiffstats
path: root/tools/relocation_packer/BUILD.gn
blob: d841277ef123cde36f510a109f5cd877ec542f6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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("config.gni")

assert(relocation_packing_supported)

if (target_arch == "arm") {
  target_define = "TARGET_ARM"
} else if (target_arch == "arm64") {
  target_define = "TARGET_ARM64"
}

if (current_toolchain == host_toolchain) {
  # GYP: //tools/relocation_packer/relocation_packer.gyp:lib_relocation_packer
  source_set("lib_relocation_packer") {
    defines = [ target_define ]
    deps = [ "//third_party/elfutils:libelf" ]
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]
    sources = [
      "src/debug.cc",
      "src/delta_encoder.cc",
      "src/elf_file.cc",
      "src/leb128.cc",
      "src/packer.cc",
      "src/sleb128.cc",
      "src/run_length_encoder.cc",
    ]
  }

  # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer
  executable("relocation_packer") {
    defines = [ target_define ]
    deps = [
      ":lib_relocation_packer",
      "//third_party/elfutils:libelf",
    ]
    sources = [ "src/main.cc" ]
  }

  # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer_unittests
  test("relocation_packer_unittests") {
    sources = [
      "src/debug_unittest.cc",
      "src/delta_encoder_unittest.cc",
      "src/elf_file_unittest.cc",
      "src/leb128_unittest.cc",
      "src/packer_unittest.cc",
      "src/sleb128_unittest.cc",
      "src/run_length_encoder_unittest.cc",
      "src/run_all_unittests.cc",
    ]
    rebased_test_data = rebase_path("test_data", root_build_dir)
    data = [
      "test_data/elf_file_unittest_relocs_arm32.so",
      "test_data/elf_file_unittest_relocs_arm32_packed.so",
      "test_data/elf_file_unittest_relocs_arm64.so",
      "test_data/elf_file_unittest_relocs_arm64_packed.so",
    ]
    defines = [
      target_define,
      "INTERMEDIATE_DIR=\"$rebased_test_data\""
    ]
    include_dirs = [ "//" ]
    deps = [
      ":lib_relocation_packer",
      ":relocation_packer_test_data",
      "//testing:gtest",
    ]
  }
}

if (current_toolchain == default_toolchain &&
    (target_arch == "arm" || target_arch == "arm64")) {
  # Targets to build test data.  These participate only in building test
  # data for use with elf_file_unittest.cc, and are not part of the main
  # relocation packer build.  Unit test data files are checked in to the
  # source tree as 'golden' data, and are not generated 'on the fly' by
  # the build.
  #
  # See test_data/generate_elf_file_unittest_relocs.sh for instructions.

  # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer_test_data
  shared_library("relocation_packer_test_data") {
    cflags = [ "-O0", "-g0" ]
    sources = [
      "test_data/elf_file_unittest_relocs.cc"
    ]
  }

  # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer_unittests_test_data
  action("relocation_packer_unittests_test_data") {
    script = "test_data/generate_elf_file_unittest_relocs.py"
    test_file = "$root_build_dir/librelocation_packer_test_data.so"
    if (target_arch == "arm") {
      added_section = ".android.rel.dyn"
      packed_output = "elf_file_unittest_relocs_arm32_packed.so"
      unpacked_output = "elf_file_unittest_relocs_arm32.so"
    } else if (target_arch == "arm64") {
      added_section = ".android.rela.dyn"
      packed_output = "elf_file_unittest_relocs_arm64_packed.so"
      unpacked_output = "elf_file_unittest_relocs_arm64.so"
    } else {
      assert(false, "Unsupported target arch for relocation packer")
    }

    packed_output = "$root_build_dir/$packed_output"
    unpacked_output = "$root_build_dir/$unpacked_output"

    inputs = [
      test_file,
    ]

    deps = [
      ":relocation_packer_test_data",
      ":relocation_packer($host_toolchain)",
    ]

    outputs = [
      packed_output,
      unpacked_output,
    ]

    args = [
      "--android-pack-relocations", rebase_path(relocation_packer_exe, root_build_dir),
      "--android-objcopy", rebase_path(android_objcopy, root_build_dir),
      "--added-section=$added_section",
      "--test-file", rebase_path(test_file, root_build_dir),
      "--packed-output", rebase_path(packed_output, root_build_dir),
      "--unpacked-output", rebase_path(unpacked_output, root_build_dir),
    ]
  }
}