aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-05-01 10:08:31 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-05-01 10:08:48 -0700
commit6d520e36de0229eefe2f1671438cc8333a90b5e6 (patch)
tree715843d140e793d17d2f3ef1728987bcf30704cc /gold
parente10cfd063328872efa721b4a08b9d52486fb5878 (diff)
downloadgdb-6d520e36de0229eefe2f1671438cc8333a90b5e6.zip
gdb-6d520e36de0229eefe2f1671438cc8333a90b5e6.tar.gz
gdb-6d520e36de0229eefe2f1671438cc8333a90b5e6.tar.bz2
gold: x86-64: Fix TLSDESC -> LE relaxation
X86-64 TLSDESC sequences can be: 4c 8d 0d 00 00 00 00 leaq foo@TLSDESC(%rip), %r9 4c 89 c8 movq %r9, %rax ff 10 call *foo@TLSCALL(%rax) TLSDESC -> LE relaxation can turn them into: 49 c7 c1 fc ff ff ff mov $0xfffffffffffffffc,%r9 4c 89 c8 mov %r9,%rax 66 90 xchg %ax,%ax We need to check and update the REX byte in this case. PR gold/25473 * x86_64.cc (Target_x86_64<size>::Relocate::tls_desc_gd_to_ie): Properly check r8 - r15 in "lea foo@TLSDESC(%rip), %reg". (Target_x86_64<size>::Relocate::tls_desc_gd_to_le): Properly relax r8 - r15 in "lea foo@TLSDESC(%rip), %reg". * testsuite/Makefile.am (check_SCRIPTS): Add x86_64_gd_to_le.sh. (check_DATA): Add x86_64_gd_to_le.stdout. (MOSTLYCLEANFILES): Add x86_64_gd_to_le. (x86_64_gd_to_le.o): New target. (x86_64_gd_to_le): Likewise. (x86_64_gd_to_le.stdout): Likewise. * testsuite/Makefile.in: Regenerated. * testsuite/x86_64_gd_to_le.s: New file. * testsuite/x86_64_gd_to_le.sh: Likewise.
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog17
-rw-r--r--gold/testsuite/Makefile.am11
-rw-r--r--gold/testsuite/Makefile.in17
-rw-r--r--gold/testsuite/x86_64_gd_to_le.s24
-rwxr-xr-xgold/testsuite/x86_64_gd_to_le.sh26
-rw-r--r--gold/x86_64.cc11
6 files changed, 103 insertions, 3 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 97044b6..0b7cb07 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,5 +1,22 @@
2020-05-01 H.J. Lu <hongjiu.lu@intel.com>
+ PR gold/25473
+ * x86_64.cc (Target_x86_64<size>::Relocate::tls_desc_gd_to_ie):
+ Properly check r8 - r15 in "lea foo@TLSDESC(%rip), %reg".
+ (Target_x86_64<size>::Relocate::tls_desc_gd_to_le): Properly
+ relax r8 - r15 in "lea foo@TLSDESC(%rip), %reg".
+ * testsuite/Makefile.am (check_SCRIPTS): Add x86_64_gd_to_le.sh.
+ (check_DATA): Add x86_64_gd_to_le.stdout.
+ (MOSTLYCLEANFILES): Add x86_64_gd_to_le.
+ (x86_64_gd_to_le.o): New target.
+ (x86_64_gd_to_le): Likewise.
+ (x86_64_gd_to_le.stdout): Likewise.
+ * testsuite/Makefile.in: Regenerated.
+ * testsuite/x86_64_gd_to_le.s: New file.
+ * testsuite/x86_64_gd_to_le.sh: Likewise.
+
+2020-05-01 H.J. Lu <hongjiu.lu@intel.com>
+
* testsuite/odr_violation2.cc (Ordering::operator()): Make
expression even more complex.
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 4c26f33..6187554 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -1202,6 +1202,17 @@ x86_64_indirect_jump_to_direct1: x86_64_indirect_jump_to_direct1.o gcctestdir/ld
x86_64_indirect_jump_to_direct1.stdout: x86_64_indirect_jump_to_direct1
$(TEST_OBJDUMP) -dw $< > $@
+check_SCRIPTS += x86_64_gd_to_le.sh
+check_DATA += x86_64_gd_to_le.stdout
+MOSTLYCLEANFILES += x86_64_gd_to_le
+
+x86_64_gd_to_le.o: x86_64_gd_to_le.s
+ $(TEST_AS) --64 -o $@ $<
+x86_64_gd_to_le: x86_64_gd_to_le.o gcctestdir/ld
+ gcctestdir/ld -o $@ $<
+x86_64_gd_to_le.stdout: x86_64_gd_to_le
+ $(TEST_OBJDUMP) -dw $< > $@
+
check_SCRIPTS += x86_64_overflow_pc32.sh
check_DATA += x86_64_overflow_pc32.err
MOSTLYCLEANFILES += x86_64_overflow_pc32.err
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 9f29dc6..8d2f142 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -291,6 +291,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_28 = tls_shared_nonpic_test
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_29 = x86_64_mov_to_lea.sh \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_call_to_direct.sh \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_gd_to_le.sh \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_overflow_pc32.sh \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_overflow_pc32.sh \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1.sh \
@@ -311,6 +312,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea14.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_call_to_direct1.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_jump_to_direct1.stdout \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_gd_to_le.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_overflow_pc32.err \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_overflow_pc32.err \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1.stdout \
@@ -332,6 +334,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea14 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_call_to_direct1 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_jump_to_direct1 \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_gd_to_le \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_overflow_pc32.err \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_overflow_pc32.err
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_32 = pr17704a_test
@@ -5667,6 +5670,13 @@ x86_64_indirect_call_to_direct.sh.log: x86_64_indirect_call_to_direct.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+x86_64_gd_to_le.sh.log: x86_64_gd_to_le.sh
+ @p='x86_64_gd_to_le.sh'; \
+ b='x86_64_gd_to_le.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
x86_64_overflow_pc32.sh.log: x86_64_overflow_pc32.sh
@p='x86_64_overflow_pc32.sh'; \
b='x86_64_overflow_pc32.sh'; \
@@ -8364,6 +8374,13 @@ uninstall-am:
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -o $@ $<
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_indirect_jump_to_direct1.stdout: x86_64_indirect_jump_to_direct1
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -dw $< > $@
+
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_gd_to_le.o: x86_64_gd_to_le.s
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) --64 -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_gd_to_le: x86_64_gd_to_le.o gcctestdir/ld
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_gd_to_le.stdout: x86_64_gd_to_le
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -dw $< > $@
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_overflow_pc32.o: x86_64_overflow_pc32.s
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) -o $@ $<
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_overflow_pc32.err: x86_64_overflow_pc32.o gcctestdir/ld
diff --git a/gold/testsuite/x86_64_gd_to_le.s b/gold/testsuite/x86_64_gd_to_le.s
new file mode 100644
index 0000000..dcdd303
--- /dev/null
+++ b/gold/testsuite/x86_64_gd_to_le.s
@@ -0,0 +1,24 @@
+ .text
+ .p2align 4
+ .globl _start
+ .type _start, @function
+_start:
+ .cfi_startproc
+ subq $8, %rsp
+ .cfi_def_cfa_offset 16
+ leaq foo@TLSDESC(%rip), %r9
+ movq %r9, %rax
+ call *foo@TLSCALL(%rax)
+ addq %fs:0, %rax
+ addq $8, %rsp
+ .cfi_def_cfa_offset 8
+ ret
+ .cfi_endproc
+ .size _start, .-_start
+ .section .tdata,"awT",@progbits
+ .align 4
+ .type foo, @object
+ .size foo, 4
+foo:
+ .long 30
+ .section .note.GNU-stack,"",@progbits
diff --git a/gold/testsuite/x86_64_gd_to_le.sh b/gold/testsuite/x86_64_gd_to_le.sh
new file mode 100755
index 0000000..7ecc6ea
--- /dev/null
+++ b/gold/testsuite/x86_64_gd_to_le.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# x86_64_gd_to_ie.sh -- a test for GDesc -> IE conversion.
+
+# Copyright (C) 2020 Free Software Foundation, Inc.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+set -e
+
+grep -q "mov[ \t]\+\$0x[a-f0-9]\+,%r9" x86_64_gd_to_le.stdout
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 114ebb0..d4f1d6b 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -5477,7 +5477,9 @@ Target_x86_64<size>::Relocate::tls_desc_gd_to_ie(
tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3);
tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
tls::check_tls(relinfo, relnum, rela.get_r_offset(),
- view[-3] == 0x48 && view[-2] == 0x8d && view[-1] == 0x05);
+ ((view[-3] & 0xfb) == 0x48
+ && view[-2] == 0x8d
+ && (view[-1] & 0xc7) == 0x05));
view[-2] = 0x8b;
const elfcpp::Elf_Xword addend = rela.get_r_addend();
Relocate_functions<size, false>::pcrela32(view, value, addend, address);
@@ -5516,9 +5518,12 @@ Target_x86_64<size>::Relocate::tls_desc_gd_to_le(
tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3);
tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
tls::check_tls(relinfo, relnum, rela.get_r_offset(),
- view[-3] == 0x48 && view[-2] == 0x8d && view[-1] == 0x05);
+ ((view[-3] & 0xfb) == 0x48
+ && view[-2] == 0x8d
+ && (view[-1] & 0xc7) == 0x05));
+ view[-3] = 0x48 | ((view[-3] >> 2) & 1);
view[-2] = 0xc7;
- view[-1] = 0xc0;
+ view[-1] = 0xc0 | ((view[-1] >> 3) & 7);
value -= tls_segment->memsz();
Relocate_functions<size, false>::rela32(view, value, 0);
}