aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-09-09 05:05:16 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-09-09 05:05:29 -0700
commit0a27fed72d4190cc70025c671b5133e6c58d9c09 (patch)
tree3d9d0bc8ad47eba702a00a23ebd00c8e64da165c /ld
parent90d499086b5d35ac5b58c925f23513f6af2c3639 (diff)
downloadgdb-0a27fed72d4190cc70025c671b5133e6c58d9c09.zip
gdb-0a27fed72d4190cc70025c671b5133e6c58d9c09.tar.gz
gdb-0a27fed72d4190cc70025c671b5133e6c58d9c09.tar.bz2
x86: Properly handle __ehdr_start
After _bfd_i386_elf_convert_load and _bfd_x86_64_elf_convert_load are removed, elf_i386_convert_load_reloc and elf_x86_64_convert_load_reloc see __ehdr_start as an undefined symbol when they are called from check_relocs to convert GOT relocations against local symbols. But __ehdr_start will be defined as a hidden symbol by linker at the later stage if it is referenced. This patch marks __ehdr_start as a defined local symbol at the start of check_relocs if it is referenced and not defined. bfd/ PR ld/22115 * elf32-i386.c (elf_i386_convert_load_reloc): Check linker_def. Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO. * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Check linker_def. Don't use UNDEFINED_WEAK_RESOLVED_TO_ZERO. * elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set local_ref and linker_def on __ehdr_start if it is referenced and not defined. (_bfd_x86_elf_link_symbol_references_local): Also set local_ref and return TRUE when building executable, if a symbol has non-GOT/non-PLT relocations in text section or there is no dynamic linker. * elfxx-x86.h (elf_x86_link_hash_entry): Add linker_def. ld/ PR ld/22115 * ld-i386/i386.exp: Run PR ld/22115 tests, * ld/testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr22115-1.s: New file. * testsuite/ld-i386/pr22115-1a.d: Likewise. * testsuite/ld-i386/pr22115-1b.d: Likewise. * testsuite/ld-i386/pr22115-1c.d: Likewise. * testsuite/ld-i386/pr22115-1d.d: Likewise. * testsuite/ld-x86-64/pr22115-1.s: Likewise. * testsuite/ld-x86-64/pr22115-1a-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1a.d: Likewise. * testsuite/ld-x86-64/pr22115-1b-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1b.d: Likewise. * testsuite/ld-x86-64/pr22115-1c-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1c.d: Likewise. * testsuite/ld-x86-64/pr22115-1d-x32.d: Likewise. * testsuite/ld-x86-64/pr22115-1d.d: Likewise.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog20
-rw-r--r--ld/testsuite/ld-i386/i386.exp4
-rw-r--r--ld/testsuite/ld-i386/pr22115-1.s7
-rw-r--r--ld/testsuite/ld-i386/pr22115-1a.d13
-rw-r--r--ld/testsuite/ld-i386/pr22115-1b.d6
-rw-r--r--ld/testsuite/ld-i386/pr22115-1c.d13
-rw-r--r--ld/testsuite/ld-i386/pr22115-1d.d6
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1.s7
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1a-x32.d13
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1a.d13
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1b-x32.d6
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1b.d6
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1c-x32.d13
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1c.d13
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1d-x32.d6
-rw-r--r--ld/testsuite/ld-x86-64/pr22115-1d.d6
-rw-r--r--ld/testsuite/ld-x86-64/x86-64.exp8
17 files changed, 160 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 98318e9..7c17868 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,23 @@
+2017-09-09 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/22115
+ * ld-i386/i386.exp: Run PR ld/22115 tests,
+ * ld/testsuite/ld-x86-64/x86-64.exp: Likewise.
+ * testsuite/ld-i386/pr22115-1.s: New file.
+ * testsuite/ld-i386/pr22115-1a.d: Likewise.
+ * testsuite/ld-i386/pr22115-1b.d: Likewise.
+ * testsuite/ld-i386/pr22115-1c.d: Likewise.
+ * testsuite/ld-i386/pr22115-1d.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1.s: Likewise.
+ * testsuite/ld-x86-64/pr22115-1a-x32.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1a.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1b-x32.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1b.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1c-x32.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1c.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1d-x32.d: Likewise.
+ * testsuite/ld-x86-64/pr22115-1d.d: Likewise.
+
2017-09-06 H.J. Lu <hongjiu.lu@intel.com>
* testsuite/ld-x86-64/pr19609-2a.d: Updated.
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index bd15610..f691c32 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -440,6 +440,10 @@ run_dump_test "pie1"
run_dump_test "pie1-nacl"
run_dump_test "pr21884"
run_dump_test "pr21884-nacl"
+run_dump_test "pr22115-1a"
+run_dump_test "pr22115-1b"
+run_dump_test "pr22115-1c"
+run_dump_test "pr22115-1d"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr22115-1.s b/ld/testsuite/ld-i386/pr22115-1.s
new file mode 100644
index 0000000..341eede
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr22115-1.s
@@ -0,0 +1,7 @@
+ .text
+ .globl _start
+ .type _start, @function
+_start:
+ movl __ehdr_start@GOT(%eax), %eax
+ .size _start, .-_start
+ .weak __ehdr_start
diff --git a/ld/testsuite/ld-i386/pr22115-1a.d b/ld/testsuite/ld-i386/pr22115-1a.d
new file mode 100644
index 0000000..4857952
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr22115-1a.d
@@ -0,0 +1,13 @@
+#source: pr22115-1.s
+#as: --32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_i386
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+: 8d 80 ([0-9a-f]{2} ){4} * lea -?0x[a-f0-9]+\(%eax\),%eax
+#pass
diff --git a/ld/testsuite/ld-i386/pr22115-1b.d b/ld/testsuite/ld-i386/pr22115-1b.d
new file mode 100644
index 0000000..bb05851
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr22115-1b.d
@@ -0,0 +1,6 @@
+#source: pr22115-1.s
+#as: --32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_i386
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-i386/pr22115-1c.d b/ld/testsuite/ld-i386/pr22115-1c.d
new file mode 100644
index 0000000..ce70539
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr22115-1c.d
@@ -0,0 +1,13 @@
+#source: pr22115-1.s
+#as: --32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_i386 --no-dynamic-linker
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+: 8d 80 ([0-9a-f]{2} ){4} * lea -?0x[a-f0-9]+\(%eax\),%eax
+#pass
diff --git a/ld/testsuite/ld-i386/pr22115-1d.d b/ld/testsuite/ld-i386/pr22115-1d.d
new file mode 100644
index 0000000..3a0b8e3
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr22115-1d.d
@@ -0,0 +1,6 @@
+#source: pr22115-1.s
+#as: --32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_i386 --no-dynamic-linker
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr22115-1.s b/ld/testsuite/ld-x86-64/pr22115-1.s
new file mode 100644
index 0000000..8c01e50
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1.s
@@ -0,0 +1,7 @@
+ .text
+ .globl _start
+ .type _start, @function
+_start:
+ movq __ehdr_start@GOTPCREL(%rip), %rax
+ .size _start, .-_start
+ .weak __ehdr_start
diff --git a/ld/testsuite/ld-x86-64/pr22115-1a-x32.d b/ld/testsuite/ld-x86-64/pr22115-1a-x32.d
new file mode 100644
index 0000000..8232589
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1a-x32.d
@@ -0,0 +1,13 @@
+#source: pr22115-1.s
+#as: --x32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf32_x86_64
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -?0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <__ehdr_start>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr22115-1a.d b/ld/testsuite/ld-x86-64/pr22115-1a.d
new file mode 100644
index 0000000..43dc787
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1a.d
@@ -0,0 +1,13 @@
+#source: pr22115-1.s
+#as: --64 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_x86_64
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -?0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <__ehdr_start>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr22115-1b-x32.d b/ld/testsuite/ld-x86-64/pr22115-1b-x32.d
new file mode 100644
index 0000000..949dc5f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1b-x32.d
@@ -0,0 +1,6 @@
+#source: pr22115-1.s
+#as: --x32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf32_x86_64
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr22115-1b.d b/ld/testsuite/ld-x86-64/pr22115-1b.d
new file mode 100644
index 0000000..f1aaf72
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1b.d
@@ -0,0 +1,6 @@
+#source: pr22115-1.s
+#as: --64 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_x86_64
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr22115-1c-x32.d b/ld/testsuite/ld-x86-64/pr22115-1c-x32.d
new file mode 100644
index 0000000..384f8f4
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1c-x32.d
@@ -0,0 +1,13 @@
+#source: pr22115-1.s
+#as: --x32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf32_x86_64 --no-dynamic-linker
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -?0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <__ehdr_start>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr22115-1c.d b/ld/testsuite/ld-x86-64/pr22115-1c.d
new file mode 100644
index 0000000..ac147f8
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1c.d
@@ -0,0 +1,13 @@
+#source: pr22115-1.s
+#as: --64 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_x86_64 --no-dynamic-linker
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+ +[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea -?0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ <__ehdr_start>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr22115-1d-x32.d b/ld/testsuite/ld-x86-64/pr22115-1d-x32.d
new file mode 100644
index 0000000..755c827
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1d-x32.d
@@ -0,0 +1,6 @@
+#source: pr22115-1.s
+#as: --x32 -mrelax-relocations=yes
+#ld: -pie -z text -m elf32_x86_64 --no-dynamic-linker
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr22115-1d.d b/ld/testsuite/ld-x86-64/pr22115-1d.d
new file mode 100644
index 0000000..2cb1c65
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22115-1d.d
@@ -0,0 +1,6 @@
+#source: pr22115-1.s
+#as: --64 -mrelax-relocations=yes
+#ld: -pie -z text -m elf_x86_64 --no-dynamic-linker
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 46b3ec7..edf8896 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -369,6 +369,14 @@ run_dump_test "property-x86-shstk5-x32"
run_dump_test "pr21884"
run_dump_test "pr21884-nacl"
run_dump_test "pr22071"
+run_dump_test "pr22115-1a"
+run_dump_test "pr22115-1a-x32"
+run_dump_test "pr22115-1b"
+run_dump_test "pr22115-1b-x32"
+run_dump_test "pr22115-1c"
+run_dump_test "pr22115-1c-x32"
+run_dump_test "pr22115-1d"
+run_dump_test "pr22115-1d-x32"
if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
return