^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # Check whether linker can handle cross-segment @segrel():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) CPPFLAGS=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) CC=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) OBJDUMP=$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) READELF=$3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) dir=$(dirname $0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) tmp=${TMPDIR:-/tmp}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) out=$tmp/out$$
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # Check whether cross-segment segment-relative relocs work fine. We need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # that for building the gate DSO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) $CC -nostdlib -static -Wl,-T$dir/check-segrel.lds $dir/check-segrel.S -o $out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) res=$($OBJDUMP --full --section .rodata $out | fgrep 000 | cut -f3 -d' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) rm -f $out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) if [ $res != 00000a00 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) CPPFLAGS="$CPPFLAGS -DHAVE_BUGGY_SEGREL"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) cat >&2 <<EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) warning: your linker cannot handle cross-segment segment-relative relocations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) please upgrade to a newer version (it is safe to use this linker, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) the kernel will be bigger than strictly necessary).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) # Check whether .align inside a function works as expected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) $CC -c $dir/check-text-align.S -o $out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) $READELF -u $out | fgrep -q 'prologue(rlen=12)'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) res=$?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) rm -f $out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if [ $res -eq 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) CPPFLAGS="$CPPFLAGS -DHAVE_WORKING_TEXT_ALIGN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if ! $CC -c $dir/check-model.c -o $out 2>&1 | grep __model__ | grep -q attrib
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) CPPFLAGS="$CPPFLAGS -DHAVE_MODEL_SMALL_ATTRIBUTE"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) rm -f $out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) # Check whether assembler supports .serialize.{data,instruction} directive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) $CC -c $dir/check-serialize.S -o $out 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) res=$?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) rm -f $out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if [ $res -eq 0 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) CPPFLAGS="$CPPFLAGS -DHAVE_SERIALIZE_DIRECTIVE"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) echo $CPPFLAGS