aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/tools/toolcheck
blob: 04fc44b750d2fa28ca3a61b25580409d74760b54 (plain) (blame)
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
#!/bin/bash
#
# Copyright 2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
#

set -e

cleanup() {
	[[ ! -d $temp ]] || rm -rf "$temp"
	exit
}
trap cleanup INT TERM EXIT
temp="$(mktemp -d)"

check_thumb2_address() {
	local disassembly

	$CC $KBUILD_AFLAGS -o "$temp/a.out" -c -xassembler - <<-_EOF
		.syntax unified
		.thumb
		.macro	badr, reg, sym
		adr	\reg, \sym + 1
		.endm

		.type test, %function
		.thumb_func
		test:
		mov	r0, #0
		badr	lr, test
	_EOF
	disassembly="$($OBJDUMP -d "$temp/a.out")"

	[[ $disassembly =~ 4:[[:space:]]*f2af\ 0e07 ]] && return 0

	echo "Error: your assembler version produces buggy kernels:" >&2
	read < <($AS --version) && echo "$REPLY" >&2
	[[ $disassembly =~ 4:[[:space:]].*$ ]] && echo "${BASH_REMATCH[0]}" >&2 || echo "$disassembly" >&2
	return 1
}

config="$(< .config)"
[[ $config == *CONFIG_THUMB2_KERNEL=y* ]] && check_thumb2_address

exit 0