diff --git a/install_base.sh b/install_base.sh index dfc2254b6d9842a6167237fed355a9c5dff83b19..bd1b4baedd01dbc5dc7e452a3d19569c1ce0fe3d 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 550b8698fbf812b8a9fcc7e4d0fd26b42be4fa33..d5a9369020a08d36bc54bda55fc9e86b8ff521cc 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 0000000000000000000000000000000000000000..5672526166b04f8f4ad262ad685631d5c9a9ba4b --- /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 b2a7f0f240e319607f57534be2ace5e5abff0357..1e70d301577fc0b7cf27d586133a86f0be3e9431 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):