|
| 1 | +#!/bin/bash |
| 2 | +. $(dirname $0)/common.inc |
| 3 | + |
| 4 | +cat <<EOF | $CC -o $t/a.o -fPIC -c -xc - |
| 5 | +#include <stdio.h> |
| 6 | +int main() { |
| 7 | + printf("Hello world\n"); |
| 8 | +} |
| 9 | +EOF |
| 10 | + |
| 11 | +# Probe whether the host toolchain can link a PIE; skip if not. |
| 12 | +$CC -o $t/probe $t/a.o -pie 2> /dev/null || skip |
| 13 | + |
| 14 | +# Default: standard DT_RELR tags (35/36/37) and SHT_RELR (19). |
| 15 | +$CC -B. -o $t/exe1 $t/a.o -pie -Wl,--pack-dyn-relocs=relr |
| 16 | +readelf -SW $t/exe1 | grep -F .relr.dyn | grep -Ew 'RELR' |
| 17 | +readelf --dynamic $t/exe1 > $t/log1 |
| 18 | +grep -Ew 'RELR|<unknown>: 24' $t/log1 |
| 19 | +grep -Ew 'RELRSZ|<unknown>: 23' $t/log1 |
| 20 | +grep -Ew 'RELRENT|<unknown>: 25' $t/log1 |
| 21 | + |
| 22 | +# --use-android-relr-tags: legacy DT_ANDROID_RELR* (in the OS-specific |
| 23 | +# range) and SHT_ANDROID_RELR section type, for compatibility with |
| 24 | +# pre-Android-12 loaders that don't recognize the standard tags. |
| 25 | +$CC -B. -o $t/exe2 $t/a.o -pie \ |
| 26 | + -Wl,--pack-dyn-relocs=relr -Wl,--use-android-relr-tags |
| 27 | +readelf -SW $t/exe2 | grep -F .relr.dyn | grep -Ev '\bRELR\b' |
| 28 | +readelf --dynamic $t/exe2 > $t/log2 |
| 29 | +grep -E '0x0*6fffe000\b' $t/log2 |
| 30 | +grep -E '0x0*6fffe001\b' $t/log2 |
| 31 | +grep -E '0x0*6fffe003\b' $t/log2 |
| 32 | +# Make sure the standard tags are NOT emitted in this mode. |
| 33 | +not grep -Ew 'RELR|<unknown>: 24' $t/log2 |
| 34 | +not grep -Ew 'RELRSZ|<unknown>: 23' $t/log2 |
| 35 | +not grep -Ew 'RELRENT|<unknown>: 25' $t/log2 |
| 36 | + |
| 37 | +# --no-use-android-relr-tags reverts to the standard tags. |
| 38 | +$CC -B. -o $t/exe3 $t/a.o -pie \ |
| 39 | + -Wl,--pack-dyn-relocs=relr \ |
| 40 | + -Wl,--use-android-relr-tags -Wl,--no-use-android-relr-tags |
| 41 | +readelf --dynamic $t/exe3 > $t/log3 |
| 42 | +grep -Ew 'RELR|<unknown>: 24' $t/log3 |
0 commit comments