xref: /openbmc/linux/scripts/tools-support-relr.sh (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
15cf896fbSPeter Collingbourne#!/bin/sh -eu
25cf896fbSPeter Collingbourne# SPDX-License-Identifier: GPL-2.0
35cf896fbSPeter Collingbourne
45cf896fbSPeter Collingbournetmp_file=$(mktemp)
55cf896fbSPeter Collingbournetrap "rm -f $tmp_file.o $tmp_file $tmp_file.bin" EXIT
65cf896fbSPeter Collingbourne
765e1f38dSIlie Halipcat << "END" | $CC -c -x c - -o $tmp_file.o >/dev/null 2>&1
85cf896fbSPeter Collingbournevoid *p = &p;
95cf896fbSPeter CollingbourneEND
10*ccb2d173SFangrui Song
11*ccb2d173SFangrui Song# ld.lld before 15 did not support -z pack-relative-relocs.
12*ccb2d173SFangrui Songif ! $LD $tmp_file.o -shared -Bsymbolic --pack-dyn-relocs=relr -o $tmp_file 2>/dev/null; then
13*ccb2d173SFangrui Song	$LD $tmp_file.o -shared -Bsymbolic -z pack-relative-relocs -o $tmp_file 2>&1 |
14*ccb2d173SFangrui Song		grep -q pack-relative-relocs && exit 1
15*ccb2d173SFangrui Songfi
165cf896fbSPeter Collingbourne
175cf896fbSPeter Collingbourne# Despite printing an error message, GNU nm still exits with exit code 0 if it
185cf896fbSPeter Collingbourne# sees a relr section. So we need to check that nothing is printed to stderr.
1965e1f38dSIlie Haliptest -z "$($NM $tmp_file 2>&1 >/dev/null)"
205cf896fbSPeter Collingbourne
2165e1f38dSIlie Halip$OBJCOPY -O binary $tmp_file $tmp_file.bin
22