diff options
| author | Tobias Hieta <tobias@hieta.se> | 2023-05-17 16:59:41 +0200 |
|---|---|---|
| committer | Tobias Hieta <tobias@hieta.se> | 2023-05-25 11:17:05 +0200 |
| commit | f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c (patch) | |
| tree | 98a310ca2d529f568804993c98d6a301f9f2886e /llvm-libgcc | |
| parent | 35ea4e2dbf32b338c14a2facfc603812e78c8239 (diff) | |
[NFC][Py Reformat] Reformat python files in the rest of the dirs
This is an ongoing series of commits that are reformatting our
Python code. This catches the last of the python files to
reformat. Since they where so few I bunched them together.
Reformatting is done with `black`.
If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.
If you run into any problems, post to discourse about it and
we will try to help.
RFC Thread below:
https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style
Reviewed By: jhenderson, #libc, Mordante, sivachandra
Differential Revision: https://reviews.llvm.org/D150784
Diffstat (limited to 'llvm-libgcc')
| -rwxr-xr-x | llvm-libgcc/generate_version_script.py | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/llvm-libgcc/generate_version_script.py b/llvm-libgcc/generate_version_script.py index 98850d4f4a2d..5332869494a3 100755 --- a/llvm-libgcc/generate_version_script.py +++ b/llvm-libgcc/generate_version_script.py @@ -18,13 +18,12 @@ def split_suffix(symbol): its priortiy. A symbol that has a '@@' instead of '@' has been designated by the linker as the default symbol, and is awarded a priority of -1. """ - if '@' not in symbol: + if "@" not in symbol: return None - data = [i for i in filter(lambda s: s, symbol.split('@'))] - _, version = data[-1].split('_') - version = version.replace('.', '') - priority = -1 if '@@' in symbol else int(version + '0' * - (3 - len(version))) + data = [i for i in filter(lambda s: s, symbol.split("@"))] + _, version = data[-1].split("_") + version = version.replace(".", "") + priority = -1 if "@@" in symbol else int(version + "0" * (3 - len(version))) return data[0], data[1], priority @@ -43,9 +42,9 @@ def invert_mapping(symbol_map): def intersection(llvm, gcc): """ - Finds the intersection between the symbols extracted from compiler-rt.a/libunwind.a - and libgcc_s.so.1. - """ + Finds the intersection between the symbols extracted from compiler-rt.a/libunwind.a + and libgcc_s.so.1. + """ common_symbols = {} for i in gcc: suffix_triple = split_suffix(i) @@ -67,59 +66,58 @@ def find_function_names(path): Runs readelf on a binary and reduces to only defined functions. Equivalent to `llvm-readelf --wide ${path} | grep 'FUNC' | grep -v 'UND' | awk '{print $8}'`. """ - result = subprocess.run(args=['llvm-readelf', '-su', path], - capture_output=True) + result = subprocess.run(args=["llvm-readelf", "-su", path], capture_output=True) if result.returncode != 0: - print(result.stderr.decode('utf-8'), file=sys.stderr) + print(result.stderr.decode("utf-8"), file=sys.stderr) sys.exit(1) - stdout = result.stdout.decode('utf-8') - stdout = filter(lambda x: 'FUNC' in x and 'UND' not in x, - stdout.split('\n')) - stdout = chain( - map(lambda x: filter(None, x), (i.split(' ') for i in stdout))) + stdout = result.stdout.decode("utf-8") + stdout = filter(lambda x: "FUNC" in x and "UND" not in x, stdout.split("\n")) + stdout = chain(map(lambda x: filter(None, x), (i.split(" ") for i in stdout))) return [list(i)[7] for i in stdout] def to_file(versioned_symbols): - path = f'{os.path.dirname(os.path.realpath(__file__))}/new-gcc_s-symbols' - with open(path, 'w') as f: - f.write('Do not check this version script in: you should instead work ' - 'out which symbols are missing in `lib/gcc_s.ver` and then ' - 'integrate them into `lib/gcc_s.ver`. For more information, ' - 'please see `doc/LLVMLibgcc.rst`.\n') + path = f"{os.path.dirname(os.path.realpath(__file__))}/new-gcc_s-symbols" + with open(path, "w") as f: + f.write( + "Do not check this version script in: you should instead work " + "out which symbols are missing in `lib/gcc_s.ver` and then " + "integrate them into `lib/gcc_s.ver`. For more information, " + "please see `doc/LLVMLibgcc.rst`.\n" + ) for version, symbols in versioned_symbols: - f.write(f'{version} {{\n') + f.write(f"{version} {{\n") for i in symbols: - f.write(f' {i};\n') - f.write('};\n\n') + f.write(f" {i};\n") + f.write("};\n\n") def read_args(): parser = argparse.ArgumentParser() - parser.add_argument('--compiler_rt', - type=str, - help='Path to `libclang_rt.builtins-${ARCH}.a`.', - required=True) - parser.add_argument('--libunwind', - type=str, - help='Path to `libunwind.a`.', - required=True) parser.add_argument( - '--libgcc_s', + "--compiler_rt", + type=str, + help="Path to `libclang_rt.builtins-${ARCH}.a`.", + required=True, + ) + parser.add_argument( + "--libunwind", type=str, help="Path to `libunwind.a`.", required=True + ) + parser.add_argument( + "--libgcc_s", type=str, - help= - 'Path to `libgcc_s.so.1`. Note that unlike the other two arguments, this is a dynamic library.', - required=True) + help="Path to `libgcc_s.so.1`. Note that unlike the other two arguments, this is a dynamic library.", + required=True, + ) return parser.parse_args() def main(): args = read_args() - llvm = find_function_names(args.compiler_rt) + find_function_names( - args.libunwind) + llvm = find_function_names(args.compiler_rt) + find_function_names(args.libunwind) gcc = find_function_names(args.libgcc_s) versioned_symbols = intersection(llvm, gcc) # TODO(cjdb): work out a way to integrate new symbols in with the existing @@ -127,5 +125,5 @@ def main(): to_file(versioned_symbols) -if __name__ == '__main__': +if __name__ == "__main__": main() |
