^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh -eu
^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) tmp_file=$(mktemp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) trap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) cat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) void *p = &p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) $LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) --use-android-relr-tags -o $tmp_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) # Despite printing an error message, GNU nm still exits with exit code 0 if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # sees a relr section. So we need to check that nothing is printed to stderr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) test -z "$($NM $tmp_file 2>&1 >/dev/null)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) $OBJCOPY -O binary $tmp_file $tmp_file.bin