From 6b586e770909fdd3de14c9e60f0a766a90df6598 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 15 Apr 2021 13:39:08 -0700 Subject: [PATCH] Force everything to use python3 for consistency. Rather than "whatever people have installed as 'python' on their machine". I've removed check-symbols.py because that's been broken for years and we never even noticed, and I'm not sure it's worth fixing. Test: treehugger, manual Change-Id: Ieb996bbdf790a18d4b1fb46a409cc240ba2a2a49 --- libc/kernel/tools/clean_header.py | 2 +- libc/kernel/tools/cpp.py | 2 +- libc/kernel/tools/update_all.py | 2 +- libc/tools/check-symbols-glibc.py | 30 +++++------ libc/tools/check-symbols.py | 87 ------------------------------- libc/tools/generate_notice.py | 2 +- libc/tools/genfunctosyscallnrs.py | 2 +- libc/tools/genseccomp.py | 2 +- libc/tools/genserv.py | 2 +- libc/tools/gensyscalls.py | 2 +- libc/tools/ndk_missing_symbols.py | 2 +- libc/tools/symbols.py | 7 ++- libc/tools/test_genseccomp.py | 2 +- tools/generate-version-script.py | 2 +- tools/versioner/run_tests.py | 2 +- 15 files changed, 33 insertions(+), 115 deletions(-) delete mode 100755 libc/tools/check-symbols.py diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py index 2c2d001a2..f86d36e4e 100755 --- a/libc/kernel/tools/clean_header.py +++ b/libc/kernel/tools/clean_header.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 #------------------------------------------------------------------------------ # Description of the header clean process diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py index 8538eb006..9f5345350 100755 --- a/libc/kernel/tools/cpp.py +++ b/libc/kernel/tools/cpp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """A glorified C pre-processor parser.""" import ctypes diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py index cef24dd4c..d878ec630 100755 --- a/libc/kernel/tools/update_all.py +++ b/libc/kernel/tools/update_all.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # import sys, cpp, kernel, glob, os, re, getopt, clean_header, subprocess, shutil from defaults import * diff --git a/libc/tools/check-symbols-glibc.py b/libc/tools/check-symbols-glibc.py index d8d198262..613aa88ee 100755 --- a/libc/tools/check-symbols-glibc.py +++ b/libc/tools/check-symbols-glibc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # Copyright (C) 2015 The Android Open Source Project # @@ -231,33 +231,33 @@ posix = posix - in_posix_and_glibc_but_dead_or_useless glibc = glibc - in_posix_and_glibc_but_dead_or_useless if not only_unwanted: - #print 'glibc:' + #print('glibc:') #for symbol in sorted(glibc): - # print symbol - #print + # print(symbol) + #print() - #print 'bionic:' + #print('bionic:') #for symbol in sorted(bionic): - # print symbol - #print + # print(symbol) + #print() - print 'in glibc (but not posix) but not bionic:' + print('in glibc (but not posix) but not bionic:') for symbol in sorted((glibc - posix).difference(bionic)): - print symbol - print + print(symbol) + print() - print 'in posix (and implemented in glibc) but not bionic:' + print('in posix (and implemented in glibc) but not bionic:') for symbol in sorted((posix.intersection(glibc)).difference(bionic)): - print symbol - print + print(symbol) + print() - print 'in bionic but not glibc:' + print('in bionic but not glibc:') allowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff | std_stuff | weird_stuff | libresolv_stuff | known) for symbol in sorted((bionic - allowed_stuff).difference(glibc)): if symbol in ndk_ignored: symbol += '*' - print symbol + print(symbol) sys.exit(0) diff --git a/libc/tools/check-symbols.py b/libc/tools/check-symbols.py deleted file mode 100755 index 656891790..000000000 --- a/libc/tools/check-symbols.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python - -import glob -import os -import re -import string -import subprocess -import sys - -toolchain = os.environ['ANDROID_TOOLCHAIN'] -arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain) - -sys.stderr.write('Checking symbols for arch "%s"...\n' % arch) - -def GetSymbols(library, functions_or_variables): - global api - global arch - - api = '9' - if library == 'libm' and arch == 'arm': - api = '3' - - # There were no 64-bit ABIs before API level 21. - if '64' in arch: - api = '21' - - # What GCC calls aarch64, Android calls arm64. - if arch == 'aarch64': - arch = 'arm64' - - path = '%s/development/ndk/platforms/android-%s/arch-%s/symbols/%s.so.%s.txt' % (os.environ['ANDROID_BUILD_TOP'], api, arch, library, functions_or_variables) - symbols = set() - for line in open(path, 'r'): - symbols.add(line.rstrip()) - #sys.stdout.write('%d %s in %s for %s\n' % (len(symbols), functions_or_variables, library, arch)) - return symbols - -def CheckSymbols(library, functions_or_variables): - expected_symbols = GetSymbols(library, functions_or_variables) - - lib_dir = 'lib' - if '64' in arch: - lib_dir = 'lib64' - - so_file = '%s/system/%s/%s.so' % (os.environ['ANDROID_PRODUCT_OUT'], lib_dir, library) - - # Example readelf output: - # 264: 0001623c 4 FUNC GLOBAL DEFAULT 8 cabsf - # 266: 00016244 4 FUNC GLOBAL DEFAULT 8 dremf - # 267: 00019018 4 OBJECT GLOBAL DEFAULT 11 __fe_dfl_env - # 268: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_dcmplt - - - r = re.compile(r' +\d+: [0-9a-f]+ +\d+ (FUNC|OBJECT) +\S+ +\S+ +\d+ (\S+)') - - actual_symbols = set() - for line in subprocess.check_output(['readelf', '-W', '--dyn-syms', so_file]).split('\n'): - m = r.match(line) - if m: - symbol = string.split(m.group(2), '@')[0] - if m.group(1) == 'FUNC' and functions_or_variables == 'functions': - actual_symbols.add(symbol) - elif m.group(1) == 'OBJECT' and functions_or_variables == 'variables': - actual_symbols.add(symbol) - #else: - #print 'ignoring: ' % line - - missing = expected_symbols - actual_symbols - if len(missing) > 0: - sys.stderr.write('%d missing %s in %s for %s:\n' % (len(missing), functions_or_variables, library, arch)) - for miss in sorted(missing): - sys.stderr.write(' %s\n' % miss) - - extra = actual_symbols - expected_symbols - if len(extra) > 0: - sys.stderr.write('%d extra %s in %s for %s:\n' % (len(extra), functions_or_variables, library, arch)) - for s in sorted(extra): - sys.stderr.write(' %s\n' % s) - - return len(missing) == 0 - -CheckSymbols("libc", "functions") -CheckSymbols("libc", "variables") -CheckSymbols("libm", "functions") -CheckSymbols("libm", "variables") - -sys.exit(0) diff --git a/libc/tools/generate_notice.py b/libc/tools/generate_notice.py index e0e6b3215..e4318b2b5 100755 --- a/libc/tools/generate_notice.py +++ b/libc/tools/generate_notice.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Run with directory arguments from any directory, with no special setup # required. diff --git a/libc/tools/genfunctosyscallnrs.py b/libc/tools/genfunctosyscallnrs.py index 26642f9ae..fa488447a 100755 --- a/libc/tools/genfunctosyscallnrs.py +++ b/libc/tools/genfunctosyscallnrs.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import argparse import logging diff --git a/libc/tools/genseccomp.py b/libc/tools/genseccomp.py index a78f6c140..33bf47074 100755 --- a/libc/tools/genseccomp.py +++ b/libc/tools/genseccomp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import argparse import logging diff --git a/libc/tools/genserv.py b/libc/tools/genserv.py index 84a139d25..acbfea2f0 100755 --- a/libc/tools/genserv.py +++ b/libc/tools/genserv.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # import sys, os, string, re diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py index b4e093ccc..baaa52d25 100755 --- a/libc/tools/gensyscalls.py +++ b/libc/tools/gensyscalls.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This tool is used to generate the assembler system call stubs, # the header files listing all available system calls, and the diff --git a/libc/tools/ndk_missing_symbols.py b/libc/tools/ndk_missing_symbols.py index a9f92b183..eff697219 100755 --- a/libc/tools/ndk_missing_symbols.py +++ b/libc/tools/ndk_missing_symbols.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # Copyright (C) 2015 The Android Open Source Project # diff --git a/libc/tools/symbols.py b/libc/tools/symbols.py index 3f40aad99..145753421 100644 --- a/libc/tools/symbols.py +++ b/libc/tools/symbols.py @@ -41,7 +41,8 @@ def GetFromElf(elf_file, sym_type='--dyn-syms'): symbols = set() - output = subprocess.check_output(['readelf', sym_type, '-W', elf_file]) + output = subprocess.check_output(['readelf', sym_type, '-W', elf_file], + text=True) for line in output.split('\n'): if ' HIDDEN ' in line or ' UND ' in line: continue @@ -76,6 +77,10 @@ def GetFromAndroidSo(files): if not os.path.isdir(lib_dir): lib_dir = os.path.join(out_dir, 'system/lib') + lib_dir = os.path.join(out_dir, 'apex/com.android.runtime/lib64/bionic/') + if not os.path.isdir(lib_dir): + lib_dir = os.path.join(out_dir, 'apex/com.android.runtime/lib/bionic/') + results = set() for f in files: results |= GetFromElf(os.path.join(lib_dir, f)) diff --git a/libc/tools/test_genseccomp.py b/libc/tools/test_genseccomp.py index 8bd351732..b833c2709 100755 --- a/libc/tools/test_genseccomp.py +++ b/libc/tools/test_genseccomp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Unit tests for genseccomp.py import textwrap diff --git a/tools/generate-version-script.py b/tools/generate-version-script.py index acfe21859..def621e1f 100755 --- a/tools/generate-version-script.py +++ b/tools/generate-version-script.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This tool is used to generate the version scripts for libc, libm, libdl, # and libstdc++ for every architecture. diff --git a/tools/versioner/run_tests.py b/tools/versioner/run_tests.py index f3bb6db89..396f895f1 100755 --- a/tools/versioner/run_tests.py +++ b/tools/versioner/run_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import os import subprocess