From 87d246e64e5bbdba8a3dd4ae7a07caf243dc860e Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Fri, 10 Jan 2025 11:09:20 +0900 Subject: [PATCH 1/2] Add symgen_helper script Find the so file that uses the header file declared in entrypoint.h. ./scripts/symgen_helper.sh --- scripts/README.md | 8 +++- scripts/symgen_helper.sh | 87 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100755 scripts/symgen_helper.sh diff --git a/scripts/README.md b/scripts/README.md index 8339186..d27f999 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -23,7 +23,13 @@ scripts/ffigen_helper.sh ``` -4. Update callbacks data. +4. Run `symgen_helper.sh` to find out what to add to `symgen.yaml`. + + ```sh + scripts/symgen_helper.sh + ``` + +5. Update callbacks data. * Run `./generate_callbacks.sh verify` to check type substitution. Build errors will have to be addressed by editing `gen_callbacks.py`. diff --git a/scripts/symgen_helper.sh b/scripts/symgen_helper.sh new file mode 100755 index 0000000..f249a28 --- /dev/null +++ b/scripts/symgen_helper.sh @@ -0,0 +1,87 @@ +#!/bin/bash +SCRIPT_DIR=$(dirname $(readlink -f $0)) +ROOT_DIR=$(readlink -f $SCRIPT_DIR/..) + +version=$1 +if [ -z "$version" ]; then + echo "$(basename $0) " + exit 1 +fi + +entrypoints=$ROOT_DIR/configs/$version/entrypoints.h +rootstraps=$ROOT_DIR/rootstraps/$version + +show_loading() { + while :; do + for s in '|' '/' '-' '\' '|'; do + printf "\rCollecting symbol information... $s" + sleep 0.2 + done + done +} + +show_loading & +LOADING_PID=$! + +declare -A symbols + +while IFS= read -r so_file; do + if file "$so_file" | grep -q 'ELF'; then + while IFS= read -r symbol; do + if [[ -n "$symbol" ]]; then + symbols["$symbol"]+="$so_file " + fi + done < <(nm -gD "$so_file" | awk '{print $3}') + else + echo "Warning: $so_file is not a valid ELF file." + fi +done < <(find "$rootstraps" -type f -name "*.so") + +kill $LOADING_PID +wait $LOADING_PID 2>/dev/null + +echo -e "\n\n" + +declare -a unique_so_file_list + +add_symbol_file() { + local value=$1 + local exists=0 + + for item in "${unique_so_file_list[@]}"; do + if [[ "$item" == "$value" ]]; then + exists=1 + break + fi + done + + if [[ $exists -eq 0 ]]; then + unique_so_file_list+=("$value") + fi +} + +file_from_entrypoints=$(grep -oP '#include\s*<\K[^>]*' "$entrypoints") + +for header in $file_from_entrypoints; do + header_file=$(find "$rootstraps" -type f -name "$(basename $header)") + if [ ! -f "$header_file" ]; then + continue + fi + + functions=$(grep -oP '^\w+\s+\w+\s*\([^)]*\)\s*;' "$header_file" | awk '{print $2}' | sed 's/(.*//') + + for symbol in $functions; do + if [[ -n "${symbols[$symbol]}" ]]; then + found_symbol_file=$(basename ${symbols[$symbol]}) + echo "$(basename $header_file) / $found_symbol_file" + add_symbol_file $found_symbol_file + break; + fi + done +done + +echo "------------------------------------------" + +for x in "${unique_so_file_list[@]}"; do + echo "- $x" +done From ea26eb8d5ba96a549253195cb1c77e58ef897733 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Fri, 10 Jan 2025 17:41:53 +0900 Subject: [PATCH 2/2] Fix readme --- scripts/README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index d27f999..ffb9141 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -15,7 +15,7 @@ 1. Create a copy of any existing config in the `configs` directory with the new version number as the directory name. -2. Manually update `entrypoints.h` and `symgen.yaml` by referring to the official [API docs](https://docs.tizen.org/application/native/api/iot-headed/latest) and the rootstrap. +2. Manually update `entrypoints.h` and `symgen.yaml` by referring to the official [API docs](https://docs.tizen.org/application/native/api/iot-headed/latest) and the rootstrap. (Run `symgen_helper.sh` to find out what to add to `symgen.yaml`. (`scripts/symgen_helper.sh `)) 3. Run `ffigen_helper.sh` to generate the contents of the `ffigen.yaml` file. @@ -23,13 +23,7 @@ scripts/ffigen_helper.sh ``` -4. Run `symgen_helper.sh` to find out what to add to `symgen.yaml`. - - ```sh - scripts/symgen_helper.sh - ``` - -5. Update callbacks data. +4. Update callbacks data. * Run `./generate_callbacks.sh verify` to check type substitution. Build errors will have to be addressed by editing `gen_callbacks.py`.