new file mode 100644
@@ -0,0 +1,13 @@
+ .text
+ .p2align 3
+ .globl _start
+_start:
+ .byte 0
+
+ .data
+ .p2align 3
+ .globl data
+data:
+ .byte 0
+ // Offset is not a multiple of 2. Don't use DT_RELR.
+ .dc.a __ehdr_start + 10
new file mode 100644
@@ -0,0 +1,10 @@
+#source: dt-relr-1.s
+#ld: -e _start $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#...
+There is no dynamic section in this file.
+#...
+There are no relocations in this file.
+#pass
new file mode 100644
@@ -0,0 +1,9 @@
+#source: dt-relr-1.s
+#ld: -e _start -pie $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#failif
+#...
+Relocation section '\.relr\.dyn' at offset .*
+#pass
new file mode 100644
@@ -0,0 +1,9 @@
+#source: dt-relr-1.s
+#ld: -shared $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#failif
+#...
+Relocation section '\.relr\.dyn' at offset .*
+#pass
new file mode 100644
@@ -0,0 +1,20 @@
+ .text
+ .p2align 3
+ .globl _start
+_start:
+ .byte 0
+
+ .data
+ .p2align 3
+ .globl data
+data:
+
+ .dc.a .data
+ .dc.a 0
+ .dc.a data + 2
+ .dc.a __ehdr_start + 4
+ .dc.a __ehdr_start + 9
+
+ .byte 0
+ // Offset is not a multiple of 2. Don't use DT_RELR.
+ .dc.a __ehdr_start + 10
new file mode 100644
@@ -0,0 +1,10 @@
+#source: dt-relr-2.s
+#ld: -e _start $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#...
+There is no dynamic section in this file.
+#...
+There are no relocations in this file.
+#pass
new file mode 100644
@@ -0,0 +1,17 @@
+#source: dt-relr-2.s
+#ld: -e _start -pie $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#...
+ 0x[0-9a-f]+ \(RELR\) +0x[0-9a-f]+
+ 0x[0-9a-f]+ \(RELRSZ\) +(8|16) \(bytes\)
+ 0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\)
+#...
+Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
+#...
+[0-9a-f]+ +[0-9a-f]+ +R_.*_RELATIVE .*
+#...
+Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
+ 4 offsets
+#pass
new file mode 100644
@@ -0,0 +1,17 @@
+#source: dt-relr-2.s
+#ld: -shared $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#...
+ 0x[0-9a-f]+ \(RELR\) +0x[0-9a-f]+
+ 0x[0-9a-f]+ \(RELRSZ\) +(8|16) \(bytes\)
+ 0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\)
+#...
+Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
+#...
+[0-9a-f]+ +[0-9a-f]+ +R_.*_RELATIVE .*
+#...
+Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
+ 3 offsets
+#pass
new file mode 100644
@@ -0,0 +1,17 @@
+#source: dt-relr-2.s
+#ld: -e _start -pie $DT_RELR_LDFLAGS --no-relax
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#...
+ 0x[0-9a-f]+ \(RELR\) +0x[0-9a-f]+
+ 0x[0-9a-f]+ \(RELRSZ\) +(8|16) \(bytes\)
+ 0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\)
+#...
+Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
+#...
+[0-9a-f]+ +[0-9a-f]+ +R_.*_RELATIVE .*
+#...
+Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
+ 4 offsets
+#pass
new file mode 100644
@@ -0,0 +1,9 @@
+#source: dt-relr-2.s
+#ld: -e _start -pie $DT_RELR_LDFLAGS -z nocombreloc
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#failif
+#...
+Relocation section '\.relr\.dyn' at offset .*
+#pass
new file mode 100644
@@ -0,0 +1,8 @@
+#source: dt-relr-2.s
+#ld: -r $DT_RELR_LDFLAGS
+#readelf: -rW
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#...
+Relocation section '\.rel(a|)\.data' at offset 0x[0-9a-f]+ contains 5 entries:
+#pass
new file mode 100644
@@ -0,0 +1,9 @@
+#source: dt-relr-2.s
+#ld: -e _start -pie $NO_DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#failif
+#...
+Relocation section '\.relr\.dyn' at offset .*
+#pass
new file mode 100644
@@ -0,0 +1,9 @@
+#source: dt-relr-2.s
+#ld: -e _start -shared $NO_DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#failif
+#...
+Relocation section '\.relr\.dyn' at offset .*
+#pass
new file mode 100644
@@ -0,0 +1,12 @@
+ .text
+ .p2align 3
+ .globl _start
+_start:
+ .byte 0
+
+ // Section alignment is not a multiple of 2. Don't use DT_RELR.
+ .data
+ .p2align 0
+ .globl data
+data:
+ .dc.a data
new file mode 100644
@@ -0,0 +1,9 @@
+#source: dt-relr-3.s
+#ld: -e _start -pie $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#failif
+#...
+Relocation section '\.relr\.dyn' at offset .*
+#pass
new file mode 100644
@@ -0,0 +1,9 @@
+#source: dt-relr-3.s
+#ld: -shared $DT_RELR_LDFLAGS
+#readelf: -rW -d
+#target: x86_64-*-linux* i?86-*-linux-gnu i?86-*-gnu*
+
+#failif
+#...
+Relocation section '\.relr\.dyn' at offset .*
+#pass
new file mode 100644
@@ -0,0 +1,14 @@
+#as: --32
+#ld: -shared -melf_i386 $DT_RELR_LDFLAGS
+#readelf: -r -s --wide
+
+Relocation section '.relr.dyn' at offset 0x[a-f0-9]+ contains 1 entry:
+ +1 offset
+[a-f0-9]+
+
+#...
+Symbol table '.symtab' contains [0-9]+ entries:
+ Num: Value Size Type Bind Vis Ndx Name
+#...
+ +[a-f0-9]+: 00000000 0 NOTYPE LOCAL DEFAULT 1 __ehdr_start
+#pass
new file mode 100644
@@ -0,0 +1,3 @@
+ .text
+foo:
+ pushl __ehdr_start@GOT(%ebx)
@@ -507,6 +507,7 @@ run_dump_test "pr27491-1c"
run_dump_test "pr27491-2"
run_dump_test "pr27491-3"
run_dump_test "pr27491-4"
+run_dump_test "dt-relr-1"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
new file mode 100644
@@ -0,0 +1,15 @@
+#source: dt-relr-1.s
+#as: --x32
+#ld: -shared -melf32_x86_64 $DT_RELR_LDFLAGS
+#readelf: -r -s --wide
+
+Relocation section '.relr.dyn' at offset 0x[a-f0-9]+ contains 1 entry:
+ +1 offset
+[a-f0-9]+
+
+#...
+Symbol table '.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +LOCAL +DEFAULT +[0-9]+ +__ehdr_start
+#pass
new file mode 100644
@@ -0,0 +1,14 @@
+#as: --64
+#ld: -shared -melf_x86_64 $DT_RELR_LDFLAGS
+#readelf: -r -s --wide
+
+Relocation section '.relr.dyn' at offset 0x[a-f0-9]+ contains 1 entry:
+ +1 offset
+[a-f0-9]+
+
+#...
+Symbol table '.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +LOCAL +DEFAULT +[0-9]+ +__ehdr_start
+#pass
new file mode 100644
@@ -0,0 +1,3 @@
+ .text
+foo:
+ add __ehdr_start@GOTPCREL(%rip), %rax
@@ -507,6 +507,8 @@ run_dump_test "pr27491-1c"
run_dump_test "pr27491-2"
run_dump_test "pr27491-3"
run_dump_test "pr27491-4"
+run_dump_test "dt-relr-1"
+run_dump_test "dt-relr-1-x32"
if ![istarget "x86_64-*-linux*"] {
return