summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2023-07-19 14:45:36 +0100
committer David Srbecky <dsrbecky@google.com> 2023-08-09 17:23:45 +0000
commitaca0ea41b7c377fc940854834b18325b9d118d7c (patch)
tree6ba4e4457a37084f502400d7e612a6dc8e0ed8a6
parent0819677b7206026205e6be76e9743b78dd5eb846 (diff)
Add build rule to check CFI
Add build rule that will check ART CFI. This will execute in post-submit to avoid regressions. Test: m check_cfi Change-Id: I26acaa40d76f81d6753eb01f24b1aa388213eed1
-rw-r--r--runtime/Android.bp18
-rw-r--r--tools/Android.bp21
-rwxr-xr-xtools/check_cfi.py20
3 files changed, 54 insertions, 5 deletions
diff --git a/runtime/Android.bp b/runtime/Android.bp
index fb3d1e442e..9b67dd931b 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -706,6 +706,24 @@ art_cc_library {
},
}
+art_cc_library {
+ name: "libart-unstripped",
+ defaults: ["libart_common_defaults"],
+ apex_available: [
+ "com.android.art",
+ "com.android.art.debug",
+ // libart doesn't go into test_broken_com.android.art, but the libart-broken
+ // needs to have the same apex_available list as its dependencies in order
+ // to compile against their sources. Then that change comes back up to affect
+ // libart as well, because it also needs to have the same apex_available as its
+ // dependencies.
+ "test_broken_com.android.art",
+ ],
+ strip: {
+ none: true,
+ },
+}
+
// "Broken" version of the ART runtime library, used only for testing.
art_cc_test_library {
name: "libart-broken",
diff --git a/tools/Android.bp b/tools/Android.bp
index 207a121848..ef0cadf2f0 100644
--- a/tools/Android.bp
+++ b/tools/Android.bp
@@ -108,3 +108,24 @@ sh_binary {
},
},
}
+
+cc_genrule {
+ name: "check_cfi",
+ tool_files: [
+ "check_cfi.py",
+ ],
+ tools: [
+ "llvm-dwarfdump",
+ "llvm-objdump",
+ ],
+ srcs: [
+ ":libart-unstripped",
+ ],
+ out: [
+ "check_cfi.txt",
+ ],
+ cmd: "$(location check_cfi.py) " +
+ "--dwarfdump $(location llvm-dwarfdump) " +
+ "--objdump $(location llvm-objdump) " +
+ "--out $(out) $(in)",
+}
diff --git a/tools/check_cfi.py b/tools/check_cfi.py
index 274e377e4f..60d6c1b296 100755
--- a/tools/check_cfi.py
+++ b/tools/check_cfi.py
@@ -21,6 +21,7 @@ Fully inferring CFI from disassembly is not possible in general.
"""
import os, re, subprocess, collections, pathlib, bisect, collections, sys
+from argparse import ArgumentParser
from dataclasses import dataclass
from functools import cache
from pathlib import Path
@@ -87,7 +88,7 @@ class Error(Exception):
def get_arch(lib: pathlib.Path) -> str:
""" Get architecture of the given library based on the ELF header. """
- proc = subprocess.run(["llvm-objdump", "--file-headers", lib],
+ proc = subprocess.run([args.objdump, "--file-headers", lib],
encoding='utf-8',
capture_output=True,
check=True)
@@ -102,7 +103,7 @@ Source = collections.namedtuple("Source", ["pc", "file", "line", "flag"])
def get_src(lib: pathlib.Path) -> List[Source]:
""" Get source-file and line-number for all hand-written assembly code. """
- proc = subprocess.run(["llvm-dwarfdump", "--debug-line", lib],
+ proc = subprocess.run([args.dwarfdump, "--debug-line", lib],
encoding='utf-8',
capture_output=True,
check=True)
@@ -126,7 +127,7 @@ Fde = collections.namedtuple("Fde", ["pc", "end", "data"])
def get_fde(lib: pathlib.Path) -> List[Fde]:
""" Get all FDE blocks (in dumped text-based format) """
- proc = subprocess.run(["llvm-dwarfdump", "--debug-frame", lib],
+ proc = subprocess.run([args.dwarfdump, "--debug-frame", lib],
encoding='utf-8',
capture_output=True,
check=True)
@@ -148,7 +149,7 @@ Asm = collections.namedtuple("Asm", ["pc", "name", "data"])
def get_asm(lib: pathlib.Path) -> List[Asm]:
""" Get all ASM blocks (in dumped text-based format) """
- proc = subprocess.run(["llvm-objdump", "--disassemble", "--no-show-raw-insn", lib],
+ proc = subprocess.run([args.objdump, "--disassemble", "--no-show-raw-insn", lib],
encoding='utf-8',
capture_output=True,
check=True)
@@ -286,7 +287,7 @@ def check_lib(lib: pathlib.Path) -> int:
def main(argv):
""" Check libraries provided on the command line, or use the default build output """
- libs = argv[1:]
+ libs = args.srcs
if not libs:
apex = Path(os.environ["OUT"]) / "symbols/apex/"
libs = list(apex.glob("**/libart.so"))
@@ -296,6 +297,15 @@ def main(argv):
if fail > 0:
print(fail, "ERROR(s) in", str(lib))
sys.exit(1)
+ if args.out:
+ args.out.write_bytes(b"")
if __name__ == "__main__":
+ parser = ArgumentParser(description=__doc__)
+ parser.add_argument("--out", type=Path, help="Output (will just generate empty file)")
+ parser.add_argument("--dwarfdump", type=Path, default="llvm-dwarfdump")
+ parser.add_argument("--objdump", type=Path, default="llvm-objdump")
+ parser.add_argument("srcs", nargs="*", type=Path)
+ args = parser.parse_args()
+
main(sys.argv)