ANDROID: GKI: Header generation fix and improvements

Remove dependency on kleaf intermediate abi_symbollist.raw
and use vendor symbol lists as dependencies for header
generation targets. This prevents the feature to break in
case kleaf path and/or sandboxes changes and rebuilds the
header files if any vendor symbol list changes.

Update the header generation script to process the symbol lists
before generating headers to make sure symbols are in byte order,
any symbol list marker, whitespaces and emptylines are removed
for kernel binary search API.

Bug: 232430739
Test: TH
Change-Id: Ib5783fb21543844dac7faf1fb0fcf3e7bd2bf608
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
(cherry picked from commit 1da1154eda5c026858a1e651c9aecb883d1305b3)
This commit is contained in:
Ramji Jiyani 2023-01-20 02:35:02 +00:00 committed by Treehugger Robot
parent 849ee75c5c
commit 7b49f3dd1f
2 changed files with 24 additions and 10 deletions

View File

@ -22,18 +22,26 @@ obj-$(CONFIG_MODVERSIONS) += version.o
obj-$(CONFIG_MODULE_UNLOAD_TAINT_TRACKING) += tracking.o
#
# ANDROID: GKI: Generate headerfile required for gki_module.o
# ANDROID: GKI: Generate headerfiles required for gki_module.o
#
# Dependencies on generated files need to be listed explicitly
$(obj)/gki_module.o: $(obj)/gki_module_protected_exports.h \
$(obj)/gki_module_unprotected.h
$(obj)/gki_module_unprotected.h: $(srctree)/scripts/gen_gki_modules_headers.sh \
$(if $(wildcard ${OUT_DIR}/abi_symbollist.raw), ${OUT_DIR}/abi_symbollist.raw)
ALL_KMI_SYMBOLS := all_kmi_symbols
$(obj)/gki_module_unprotected.h: $(ALL_KMI_SYMBOLS) \
$(srctree)/scripts/gen_gki_modules_headers.sh
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/gen_gki_modules_headers.sh $@ \
"$(srctree)"
"$(srctree)" \
$(ALL_KMI_SYMBOLS)
# Generate symbol list with union of all symbol list for arm64; empty for others
$(ALL_KMI_SYMBOLS): $(if $(filter arm64,$(ARCH)),$(wildcard $(srctree)/android/abi_gki_aarch64*),)
$(if $(strip $^),cat $^ > $(ALL_KMI_SYMBOLS), echo "" > $(ALL_KMI_SYMBOLS))
$(obj)/gki_module_protected_exports.h: $(srctree)/android/abi_gki_protected_exports \
$(srctree)/scripts/gen_gki_modules_headers.sh
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/gen_gki_modules_headers.sh $@ \
"$(srctree)"
"$(srctree)" \
$<

View File

@ -19,6 +19,7 @@
# Collect arguments from Makefile
TARGET=$1
SRCTREE=$2
SYMBOL_LIST=$3
set -e
@ -47,8 +48,14 @@ generate_header() {
rm -f -- "${header_file}"
fi
# Find Maximum symbol name length if valid symbol_file exist
# If symbol_file exist preprocess it and find maximum name length
if [ -s "${symbol_file}" ]; then
# Remove White Spaces, empty lines and symbol list markers if any
sed -i '/^[[:space:]]*$/d; /^#/d; /\[abi_symbol_list\]/d' "${symbol_file}"
# Sort in byte order for kernel binary search at runtime
LC_ALL=C sort -o "${symbol_file}" "${symbol_file}"
# Trim white spaces & +1 for null termination
local max_name_len=$(awk '
{
@ -88,13 +95,12 @@ generate_header() {
}
if [ "$(basename "${TARGET}")" = "gki_module_unprotected.h" ]; then
# Sorted list of vendor symbols
GKI_VENDOR_SYMBOLS="${OUT_DIR}/abi_symbollist.raw"
# Union of vendor symbol lists
GKI_VENDOR_SYMBOLS="${SYMBOL_LIST}"
generate_header "${TARGET}" "${GKI_VENDOR_SYMBOLS}" "unprotected"
else
# Sorted list of exported symbols
GKI_EXPORTED_SYMBOLS="${SRCTREE}/android/abi_gki_protected_exports"
GKI_EXPORTED_SYMBOLS="${SYMBOL_LIST}"
generate_header "${TARGET}" "${GKI_EXPORTED_SYMBOLS}" "protected_exports"
fi