forked from NVIDIA/TensorRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stubify.sh
executable file
·61 lines (50 loc) · 1.98 KB
/
stubify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#
# SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This short shell script will extract all the strong "text" symbols from the
# shared library and create a new "stub" shared library with the same symbols.
# The body of these functions will be empty and therefore have no dependencies.
# This scripts uses whatever CC is defined in the user's environment.
#
set -o pipefail
# check arguments
if [ $# -ne 2 ] ; then
echo "Usage: $(basename $0) IN_LIBFILE OUT_LIBFILE"
exit 1
fi
IN_LIBFILE="$1"
OUT_LIBFILE="$2"
# check compiler
if [ -z "${CC}" ] ; then
echo "Error: Environment variable 'CC' has not been defined"
exit 1
fi
SONAME=$(readelf -d "${IN_LIBFILE}" | grep '(SONAME)' | cut -d [ -f 2 | cut -d ] -f 1)
OS=$(lsb_release -si)-$(lsb_release -sr | cut -d '.' -f 1-2)
if [ "$OS" = "Ubuntu-22.04" ] ; then
EXTRA_NM_FLAG="--without-symbol-versions"
fi
# make stub library
if [ -z "${CC_ARGS}" ] ; then
nm -D "${IN_LIBFILE}" ${EXTRA_NM_FLAG} | \
awk '{if ($2 == "T") { print "void",$3,"() {}" }}' | \
"${CC}" -x c -Og -fPIC -shared -Wl,-soname=${SONAME} -Wl,--strip-all -o "${OUT_LIBFILE}" -
else
nm -D "${IN_LIBFILE}" ${EXTRA_NM_FLAG} | \
awk '{if ($2 == "T") { print "void",$3,"() {}" }}' | \
"${CC}" -x c -Og -fPIC -shared -Wl,-soname=${SONAME} -Wl,--strip-all -o "${OUT_LIBFILE}" "${CC_ARGS}" -
fi
exit $?