blob: e0da6023634421bd654c5b6d9e0f9b0030e27a47 [file] [log] [blame]
sophiez6bde0b52021-01-09 01:03:42 +00001#!/bin/bash -e
2
3# Copyright 2020 Google Inc. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Generates NDK API txt file used by Mainline modules. NDK APIs would have value
18# "UND" in Ndx column and have suffix "@LIB_NAME" in Name column.
19# For example, current line llvm-readelf output is:
20# 1: 00000000 0 FUNC GLOBAL DEFAULT UND dlopen@LIBC
21# After the parse function below "dlopen" would be write to the output file.
22printHelp() {
23 echo "**************************** Usage Instructions ****************************"
24 echo "This script is used to generate the Mainline modules backed-by NDK symbols."
25 echo ""
26 echo "To run this script use: ./ndk_backedby_module.sh \$BINARY_IMAGE_DIRECTORY \$OUTPUT_FILE_PATH \$NDK_LIB_NAME_LIST"
27 echo "For example: If all the module image files that you would like to run is under directory '/myModule' and output write to /backedby.txt then the command would be:"
28 echo "./ndk_usedby_module.sh /myModule /backedby.txt /ndkLibList.txt"
29 echo "If the module1 is backing lib1 then the backedby.txt would contains: "
30 echo "lib1"
31}
32
33genBackedByList() {
34 dir="$1"
35 [[ ! -e "$2" ]] && echo "" >> "$2"
36 while IFS= read -r line
37 do
38 soFileName=$(echo "$line" | sed 's/\(.*so\).*/\1/')
39 if [[ ! -z "$soFileName" && "$soFileName" != *"#"* ]]
40 then
41 find "$dir" -type f -name "$soFileName" -exec echo "$soFileName" >> "$2" \;
42 fi
43 done < "$3"
44}
45
46if [[ "$1" == "help" ]]
47then
48 printHelp
49elif [[ "$#" -ne 3 ]]
50then
51 echo "Wrong argument length. Expecting 3 argument representing image file directory, output path, path to ndk library list."
52else
53 [[ -e "$2" ]] && rm "$2"
54 genBackedByList "$1" "$2" "$3"
55fi