18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci# Create an autoksyms.h header file from the list of all module's needed symbols 58c2ecf20Sopenharmony_ci# as recorded on the second line of *.mod files and the user-provided symbol 68c2ecf20Sopenharmony_ci# whitelist. 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciset -e 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cioutput_file="$1" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci# Use "make V=1" to debug this script. 138c2ecf20Sopenharmony_cicase "$KBUILD_VERBOSE" in 148c2ecf20Sopenharmony_ci*1*) 158c2ecf20Sopenharmony_ci set -x 168c2ecf20Sopenharmony_ci ;; 178c2ecf20Sopenharmony_ciesac 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci# We need access to CONFIG_ symbols 208c2ecf20Sopenharmony_ci. include/config/auto.conf 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cineeded_symbols= 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci# Special case for modversions (see modpost.c) 258c2ecf20Sopenharmony_ciif [ -n "$CONFIG_MODVERSIONS" ]; then 268c2ecf20Sopenharmony_ci needed_symbols="$needed_symbols module_layout" 278c2ecf20Sopenharmony_cifi 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci# With CONFIG_LTO_CLANG, LLVM bitcode has not yet been compiled into a binary 308c2ecf20Sopenharmony_ci# when the .mod files are generated, which means they don't yet contain 318c2ecf20Sopenharmony_ci# references to certain symbols that will be present in the final binaries. 328c2ecf20Sopenharmony_ciif [ -n "$CONFIG_LTO_CLANG" ]; then 338c2ecf20Sopenharmony_ci # intrinsic functions 348c2ecf20Sopenharmony_ci needed_symbols="$needed_symbols memcpy memmove memset" 358c2ecf20Sopenharmony_ci # ftrace 368c2ecf20Sopenharmony_ci needed_symbols="$needed_symbols _mcount" 378c2ecf20Sopenharmony_ci # stack protector symbols 388c2ecf20Sopenharmony_ci needed_symbols="$needed_symbols __stack_chk_fail __stack_chk_guard" 398c2ecf20Sopenharmony_cifi 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciksym_wl= 428c2ecf20Sopenharmony_ciif [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then 438c2ecf20Sopenharmony_ci # Use 'eval' to expand the whitelist path and check if it is relative 448c2ecf20Sopenharmony_ci eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST" 458c2ecf20Sopenharmony_ci [ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl" 468c2ecf20Sopenharmony_ci if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then 478c2ecf20Sopenharmony_ci echo "ERROR: '$ksym_wl' whitelist file not found" >&2 488c2ecf20Sopenharmony_ci exit 1 498c2ecf20Sopenharmony_ci fi 508c2ecf20Sopenharmony_cifi 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci# Generate a new ksym list file with symbols needed by the current 538c2ecf20Sopenharmony_ci# set of modules. 548c2ecf20Sopenharmony_cicat > "$output_file" << EOT 558c2ecf20Sopenharmony_ci/* 568c2ecf20Sopenharmony_ci * Automatically generated file; DO NOT EDIT. 578c2ecf20Sopenharmony_ci */ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciEOT 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci[ -f modules.order ] && modlist=modules.order || modlist=/dev/null 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci sed 's/ko$/mod/' $modlist | xargs -n1 sed -n -e '2p' 658c2ecf20Sopenharmony_ci echo "$needed_symbols" 668c2ecf20Sopenharmony_ci [ -n "$ksym_wl" ] && cat "$ksym_wl" 678c2ecf20Sopenharmony_ci} | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' | 688c2ecf20Sopenharmony_ci# Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry 698c2ecf20Sopenharmony_ci# point addresses. 708c2ecf20Sopenharmony_cised -e 's/^\.//' | 718c2ecf20Sopenharmony_cisort -u | 728c2ecf20Sopenharmony_cised -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file" 73