Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symgen_helper script #36

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
scripts/ffigen_helper.sh <version>
```

4. Update callbacks data.
4. Run `symgen_helper.sh` to find out what to add to `symgen.yaml`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts with step 2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I updated it.


```sh
scripts/symgen_helper.sh <version>
```

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`.
Expand Down
87 changes: 87 additions & 0 deletions scripts/symgen_helper.sh
Original file line number Diff line number Diff line change
@@ -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) <version>"
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
Loading