genwrappers.sh 1.02 KB
Newer Older
1
#!/bin/sh
John Tsichritzis's avatar
John Tsichritzis committed
2
# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#
# SPDX-License-Identifier: BSD-3-Clause

set -e

build=.
out=output.a

for i
do
	case $i in
	-o)
		out=$2
		shift 2
		;;
	-b)
		build=$2
		shift 2
		;;
22
23
24
25
26
27
28
29
	--bti=*)
		enable_bti=$(echo $1 | sed 's/--bti=\(.*\)/\1/')
		shift 1
		;;
	--asflags=*)
		asflags=$(echo $1 | sed 's/--asflags=\(.*\)/\1/')
		shift 1
		;;
30
31
32
33
34
35
36
37
38
39
40
	--)
		shift
		break
		;;
	-*)
		echo usage: genwrappers.sh [-o output] [-b dir] file ... >&2
		exit 1
		;;
	esac
done

41
42
43
44
45
46
47
awk -v BTI=$enable_bti '
{sub(/[:blank:]*#.*/,"")}
!/^$/ && $NF != "patch" && $NF != "reserved" {
		if (BTI == 1)
			print $1*8, $2, $3
		else
			print $1*4, $2, $3}' "$@" |
48
49
50
51
52
53
54
while read idx lib sym
do
	file=$build/${lib}_$sym

	cat <<EOF > $file.s
	.globl	$sym
$sym:
55
56
57
58
59
60
EOF
if [ $enable_bti = 1 ]
then
	echo "\tbti\tjc" >> $file.s
fi
	cat <<EOF >> $file.s
61
	ldr	x17, =jmptbl
John Tsichritzis's avatar
John Tsichritzis committed
62
	mov	x16, #$idx
63
	ldr	x17, [x17]
64
65
66
67
	add	x16, x16, x17
	br	x16
EOF

68
	${CROSS_COMPILE}as ${asflags} -o $file.o $file.s
69
70
71
done

${CROSS_COMPILE}ar -rc $out $build/*.o