162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Check whether linker can handle cross-segment @segrel():
562306a36Sopenharmony_ci#
662306a36Sopenharmony_ciCPPFLAGS=""
762306a36Sopenharmony_ciCC=$1
862306a36Sopenharmony_ciOBJDUMP=$2
962306a36Sopenharmony_ciREADELF=$3
1062306a36Sopenharmony_cidir=$(dirname $0)
1162306a36Sopenharmony_citmp=${TMPDIR:-/tmp}
1262306a36Sopenharmony_ciout=$tmp/out$$
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci# Check whether cross-segment segment-relative relocs work fine.  We need
1562306a36Sopenharmony_ci# that for building the gate DSO:
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci$CC -nostdlib -static -Wl,-T$dir/check-segrel.lds $dir/check-segrel.S -o $out
1862306a36Sopenharmony_cires=$($OBJDUMP --full --section .rodata $out | fgrep 000 | cut -f3 -d' ')
1962306a36Sopenharmony_cirm -f $out
2062306a36Sopenharmony_ciif [ $res != 00000a00 ]; then
2162306a36Sopenharmony_ci    CPPFLAGS="$CPPFLAGS -DHAVE_BUGGY_SEGREL"
2262306a36Sopenharmony_ci    cat >&2 <<EOF
2362306a36Sopenharmony_ciwarning: your linker cannot handle cross-segment segment-relative relocations.
2462306a36Sopenharmony_ci         please upgrade to a newer version (it is safe to use this linker, but
2562306a36Sopenharmony_ci         the kernel will be bigger than strictly necessary).
2662306a36Sopenharmony_ciEOF
2762306a36Sopenharmony_cifi
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci# Check whether .align inside a function works as expected.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci$CC -c $dir/check-text-align.S -o $out
3262306a36Sopenharmony_ci$READELF -u $out | fgrep -q 'prologue(rlen=12)'
3362306a36Sopenharmony_cires=$?
3462306a36Sopenharmony_cirm -f $out
3562306a36Sopenharmony_ciif [ $res -eq 0 ]; then
3662306a36Sopenharmony_ci    CPPFLAGS="$CPPFLAGS -DHAVE_WORKING_TEXT_ALIGN"
3762306a36Sopenharmony_cifi
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciif ! $CC -c $dir/check-model.c -o $out 2>&1 | grep  __model__ | grep -q attrib
4062306a36Sopenharmony_cithen
4162306a36Sopenharmony_ci    CPPFLAGS="$CPPFLAGS -DHAVE_MODEL_SMALL_ATTRIBUTE"
4262306a36Sopenharmony_cifi
4362306a36Sopenharmony_cirm -f $out
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci# Check whether assembler supports .serialize.{data,instruction} directive.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci$CC -c $dir/check-serialize.S -o $out 2>/dev/null
4862306a36Sopenharmony_cires=$?
4962306a36Sopenharmony_cirm -f $out
5062306a36Sopenharmony_ciif [ $res -eq 0 ]; then
5162306a36Sopenharmony_ci    CPPFLAGS="$CPPFLAGS -DHAVE_SERIALIZE_DIRECTIVE"
5262306a36Sopenharmony_cifi
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciecho $CPPFLAGS
55