public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] x86: Don't check R_386_NONE nor R_X86_64_NONE
@ 2024-01-09 14:42 H.J. Lu
  0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2024-01-09 14:42 UTC (permalink / raw)
  To: binutils

This is what I am checking in.


H.J.
---
Update x86 ELF linker to skip R_386_NONE/R_X86_64_NONE when scanning
relocations.

bfd/

	* PR ld/31047
	* elf32-i386.c (elf_i386_scan_relocs): Don't check R_386_NONE.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Don't check
	R_X86_64_NONE.

ld/

	* PR ld/31047
	* testsuite/ld-i386/i386.exp: Run PR ld/31047 test.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr31047.d: New file.
	* testsuite/ld-x86-64/pr31047-x32.d: Likewise.
	* testsuite/ld-x86-64/pr31047.d: Likewise.
	* testsuite/ld-x86-64/pr31047a.s: Likewise.
	* testsuite/ld-x86-64/pr31047b.s: Likewise.
---
 bfd/elf32-i386.c                     |  4 ++++
 bfd/elf64-x86-64.c                   |  4 ++++
 ld/testsuite/ld-i386/i386.exp        |  1 +
 ld/testsuite/ld-i386/pr31047.d       | 13 +++++++++++++
 ld/testsuite/ld-x86-64/pr31047-x32.d | 13 +++++++++++++
 ld/testsuite/ld-x86-64/pr31047.d     | 13 +++++++++++++
 ld/testsuite/ld-x86-64/pr31047a.s    |  3 +++
 ld/testsuite/ld-x86-64/pr31047b.s    |  6 ++++++
 ld/testsuite/ld-x86-64/x86-64.exp    |  2 ++
 9 files changed, 59 insertions(+)
 create mode 100644 ld/testsuite/ld-i386/pr31047.d
 create mode 100644 ld/testsuite/ld-x86-64/pr31047-x32.d
 create mode 100644 ld/testsuite/ld-x86-64/pr31047.d
 create mode 100644 ld/testsuite/ld-x86-64/pr31047a.s
 create mode 100644 ld/testsuite/ld-x86-64/pr31047b.s

diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 5fc68551e95..e2f88a11487 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1525,6 +1525,10 @@ elf_i386_scan_relocs (bfd *abfd,
       r_symndx = ELF32_R_SYM (rel->r_info);
       r_type = ELF32_R_TYPE (rel->r_info);
 
+      /* Don't check R_386_NONE.  */
+      if (r_type == R_386_NONE)
+	continue;
+
       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
 	{
 	  /* xgettext:c-format */
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index ec001599cc1..f8905fbd4d4 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2040,6 +2040,10 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
       r_symndx = htab->r_sym (rel->r_info);
       r_type = ELF32_R_TYPE (rel->r_info);
 
+      /* Don't check R_X86_64_NONE.  */
+      if (r_type == R_X86_64_NONE)
+	continue;
+
       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
 	{
 	  /* xgettext:c-format */
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index c7df7731ac4..18d1c9198ca 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -512,6 +512,7 @@ run_dump_test "dt-relr-1b"
 run_dump_test "pr28870"
 run_dump_test "pr28894"
 run_dump_test "pr30787"
+run_dump_test "pr31047"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr31047.d b/ld/testsuite/ld-i386/pr31047.d
new file mode 100644
index 00000000000..9c96d825cc7
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr31047.d
@@ -0,0 +1,13 @@
+#source: ../ld-x86-64/pr31047a.s
+#source: ../ld-x86-64/pr31047b.s
+#as: --32
+#ld: -pie -melf_i386
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+:	90                   	nop
diff --git a/ld/testsuite/ld-x86-64/pr31047-x32.d b/ld/testsuite/ld-x86-64/pr31047-x32.d
new file mode 100644
index 00000000000..87bb92cbb44
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr31047-x32.d
@@ -0,0 +1,13 @@
+#source: pr31047a.s
+#source: pr31047b.s
+#as: --x32
+#ld: -pie -melf32_x86_64
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+:	90                   	nop
diff --git a/ld/testsuite/ld-x86-64/pr31047.d b/ld/testsuite/ld-x86-64/pr31047.d
new file mode 100644
index 00000000000..5c3047cce34
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr31047.d
@@ -0,0 +1,13 @@
+#source: pr31047a.s
+#source: pr31047b.s
+#as: --64
+#ld: -pie -melf_x86_64
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+:	90                   	nop
diff --git a/ld/testsuite/ld-x86-64/pr31047a.s b/ld/testsuite/ld-x86-64/pr31047a.s
new file mode 100644
index 00000000000..9d4777eba80
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr31047a.s
@@ -0,0 +1,3 @@
+	.globl foo
+	foo = 0x1000
+	.section .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/pr31047b.s b/ld/testsuite/ld-x86-64/pr31047b.s
new file mode 100644
index 00000000000..1f0169abf40
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr31047b.s
@@ -0,0 +1,6 @@
+	.text
+	.globl _start
+_start:
+	.nop
+	.reloc 0, BFD_RELOC_NONE, 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 0af9f047600..03266cba7e0 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -511,6 +511,8 @@ run_dump_test "dt-relr-1a-x32"
 run_dump_test "dt-relr-1b"
 run_dump_test "dt-relr-1b-x32"
 run_dump_test "pr30787"
+run_dump_test "pr31047"
+run_dump_test "pr31047-x32"
 
 if { ![skip_sframe_tests] } {
     run_dump_test "sframe-simple-1"
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-09 14:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 14:42 [PATCH v2] x86: Don't check R_386_NONE nor R_X86_64_NONE H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).