elf: Correct DT_TEXTREL warning in PDE

Message ID 20210619232915.311613-1-hjl.tools@gmail.com
State New
Headers show
Series
  • elf: Correct DT_TEXTREL warning in PDE
Related show

Commit Message

Luis Machado via Binutils June 19, 2021, 11:29 p.m.
Change

ld: warning: creating DT_TEXTREL in a PIE

to

ld: warning: creating DT_TEXTREL in a PDE

on PDE.

bfd/

	* elflink.c (bfd_elf_final_link): Correct DT_TEXTREL warning in
	PDE.

ld/

	* testsuite/ld-x86-64/textrel-1.err: New file.
	* testsuite/ld-x86-64/textrel-1a.s: Likewise.
	* testsuite/ld-x86-64/textrel-1b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run textrel-1 tests.
---
 bfd/elflink.c                        |  3 +++
 ld/testsuite/ld-x86-64/textrel-1.err |  4 ++++
 ld/testsuite/ld-x86-64/textrel-1a.s  |  9 +++++++++
 ld/testsuite/ld-x86-64/textrel-1b.s  | 15 +++++++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp    |  5 +++++
 5 files changed, 36 insertions(+)
 create mode 100644 ld/testsuite/ld-x86-64/textrel-1.err
 create mode 100644 ld/testsuite/ld-x86-64/textrel-1a.s
 create mode 100644 ld/testsuite/ld-x86-64/textrel-1b.s

-- 
2.31.1

Patch

diff --git a/bfd/elflink.c b/bfd/elflink.c
index c9a6e78be79..9a05208253c 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13138,6 +13138,9 @@  bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 		  else if (bfd_link_dll (info))
 		    info->callbacks->einfo
 		      (_("%P: warning: creating DT_TEXTREL in a shared object\n"));
+		  else if (bfd_link_pde (info))
+		    info->callbacks->einfo
+		      (_("%P: warning: creating DT_TEXTREL in a PDE\n"));
 		  else
 		    info->callbacks->einfo
 		      (_("%P: warning: creating DT_TEXTREL in a PIE\n"));
diff --git a/ld/testsuite/ld-x86-64/textrel-1.err b/ld/testsuite/ld-x86-64/textrel-1.err
new file mode 100644
index 00000000000..222c7a37ada
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/textrel-1.err
@@ -0,0 +1,4 @@ 
+#...
+.*textrel-1b.o: warning: relocation against `foo' in read-only section `.rodata'
+.*: warning: creating DT_TEXTREL in a PDE
+#...
diff --git a/ld/testsuite/ld-x86-64/textrel-1a.s b/ld/testsuite/ld-x86-64/textrel-1a.s
new file mode 100644
index 00000000000..6b486a9a4e2
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/textrel-1a.s
@@ -0,0 +1,9 @@ 
+	.text
+	.globl	foo
+	.data
+	.align 4
+	.type	foo, @object
+	.size	foo, 4
+foo:
+	.long	4
+	.section	.note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/textrel-1b.s b/ld/testsuite/ld-x86-64/textrel-1b.s
new file mode 100644
index 00000000000..8f125e43df4
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/textrel-1b.s
@@ -0,0 +1,15 @@ 
+	.text
+	.p2align 4
+	.globl	_start
+	.type	_start, @function
+_start:
+	ret
+	.size	_start, .-_start
+	.globl	ptr
+	.section	.rodata
+	.align 8
+	.type	ptr, @object
+	.size	ptr, 8
+ptr:
+	.quad	foo
+	.section	.note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 21a4824e3d1..3bf62504cf9 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -231,6 +231,11 @@  set x86_64tests {
      "" ""
      { pr27590a.obj.bz2 pr27590b.obj.bz2 }
      {{readelf -SW pr27590.rd}} "pr27590.o"}
+    {"Build textrel-1.so" "-melf_x86_64 -shared" ""
+     "--64" { textrel-1a.s } {} "textrel-1.so"}
+    {"Build textrel-1" "-no-pie -melf_x86_64 -z nocopyreloc"
+     "tmpdir/textrel-1.so"
+     "--64" { textrel-1b.s } {{ld "textrel-1.err"}} "textrel-1"}
 }
 
 run_ld_link_tests $x86_64tests