From caa1a0114cf9ecd6f24f556a337af7e374374b13 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Mon, 7 Oct 2024 00:46:48 +0100 Subject: [PATCH] lisa._kmod: Replace jq by a Python script Avoid adding a dependency over jq and use a Python script instead. This also provides more flexibility in post-processing. --- install_base.sh | 3 - lisa/_assets/kmodules/lisa/Makefile | 3 +- lisa/_assets/kmodules/lisa/rustdoc_symbols.py | 64 +++++++++++++++++++ lisa/_kmod.py | 3 - 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100755 lisa/_assets/kmodules/lisa/rustdoc_symbols.py diff --git a/install_base.sh b/install_base.sh index dfc2254b6..bd1b4baed 100755 --- a/install_base.sh +++ b/install_base.sh @@ -256,9 +256,6 @@ for arg in "${args[@]}"; do "--install-kernel-build-dependencies" | "--install-all") apt_packages+=(build-essential gcc bc bison flex libssl-dev libncurses5-dev libelf-dev pahole) - # For the LISA kernel module - apt_packages+=(jq) - handled=1 ;;& diff --git a/lisa/_assets/kmodules/lisa/Makefile b/lisa/_assets/kmodules/lisa/Makefile index 550b8698f..d5a936902 100644 --- a/lisa/_assets/kmodules/lisa/Makefile +++ b/lisa/_assets/kmodules/lisa/Makefile @@ -111,11 +111,10 @@ $(RUST_OBJECT): $(RUST_TARGET_DIR) cd $(RUST_SRC) && $(call cargo_cmd,rustdoc --target-dir $(RUST_TARGET_DIR) -- -Zunstable-options --output-format json) # Get the list of exported symbols (pub with #[no_mangle] attribute) from the rustdoc JSON - cat $(RUST_TARGET_DIR)/doc/lisakmod.json | jq '.index[] | select(.attrs[] | contains("#[no_mangle]")) | .name' -r > $(RUST_SYMBOLS) + python3 "$(MODULE_SRC)/rustdoc_symbols.py" --rustdoc-json $(RUST_TARGET_DIR)/doc/lisakmod.json --out-symbols-plain $(RUST_SYMBOLS) --out-symbols-lds $(RUST_SYMBOLS_LDS) cat $(RUST_SYMBOLS) # Prelink the archive into a single object file. - sed -ne 's/\(.*\)/EXTERN(\1)/p' $(RUST_SYMBOLS) > $(RUST_SYMBOLS_LDS) $(LD) $(KBUILD_LDFLAGS) --gc-sections -T $(RUST_SYMBOLS_LDS) -nostdlib -r -o $(RUST_OBJECT) --whole-archive $(RUST_TARGET_DIR)/target/release/liblisakmod.a # Only keep as GLOBAL symbols the ones that are to be exported (and the diff --git a/lisa/_assets/kmodules/lisa/rustdoc_symbols.py b/lisa/_assets/kmodules/lisa/rustdoc_symbols.py new file mode 100755 index 000000000..567252616 --- /dev/null +++ b/lisa/_assets/kmodules/lisa/rustdoc_symbols.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2023, Arm Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import json +from pathlib import Path +import sys + + +def main(): + parser = argparse.ArgumentParser(""" + Parse the JSON output of rustdoc --output-format=json and extract the + exported C symbols. + """) + + parser.add_argument('--rustdoc-json', help='JSON file to parse', required=True) + parser.add_argument('--out-symbols-plain', help='File to write the symbol list, one per line') + parser.add_argument('--out-symbols-lds', help='File to write the symbol list as a linker script, one symbol per line in an EXTERN(symbol) command') + + args = parser.parse_args() + path = Path(args.rustdoc_json) + + with open(path, 'r') as f: + data = json.load(f) + + items = [ + item + for item in data['index'].values() + if '#[no_mangle]' in item['attrs'] + ] + symbols = sorted( + item['name'] + for item in items + ) + + if (path := args.out_symbols_plain): + content = '\n'.join(symbols) + '\n' + Path(path).write_text(content) + + if (path := args.out_symbols_lds): + content = '\n'.join(( + f'EXTERN({sym})' + for sym in symbols + )) + '\n' + Path(path).write_text(content) + +if __name__ == '__main__': + main() diff --git a/lisa/_kmod.py b/lisa/_kmod.py index b2a7f0f24..1e70d3015 100644 --- a/lisa/_kmod.py +++ b/lisa/_kmod.py @@ -435,9 +435,6 @@ def _make_build_chroot(cc, cross_compile, abi, bind_paths=None, version=None, ov 'perl', 'pahole', 'git', - - # This is needed by the LISA kernel module - 'jq', ] if is_clang(cc): -- GitLab