[PATCH] gold: Add -z noreloc-overflow option
H.J. Lu
hjl.tools@gmail.com
Mon Nov 2 14:53:13 GMT 2020
Add -z noreloc-overflow command-line option to the x86-64 ELF gold linker,
like bfd linker, to disable relocation overflow check. This can be used
to avoid relocation overflow check if there will be no dynamic relocation
overflow at run-time.
* NEWS: Mention -z noreloc-overflow.
* options.h (-z,noreloc_overflow): New option.
* x86_64.cc (Target_x86_64<size>::Scan::check_non_pic): Disable
overflow check for R_X86_64_32 and R_X86_64_32S with -z
noreloc-overflow.
* testsuite/Makefile.am (x86_64_no_overflow_32s.sh): New test.
(x86_64_no_overflow_32.sh): Likewise.
(x32_no_overflow_32s.sh): Likewise.
(x32_no_overflow_32.sh): Likewise.
* testsuite/Makefile.in: Regenerated.
* testsuite/x32_no_overflow_32.sh: New file.
* testsuite/x32_no_overflow_32s.sh: Likewise.
* testsuite/x86_64_no_overflow_32.s: Likewise.
* testsuite/x86_64_no_overflow_32.sh: Likewise.
* testsuite/x86_64_no_overflow_32s.s: Likewise.
* testsuite/x86_64_no_overflow_32s.sh: Likewise.
---
gold/NEWS | 2 +
gold/options.h | 4 +-
gold/testsuite/Makefile.am | 44 +++++++++++++++
gold/testsuite/Makefile.in | 70 +++++++++++++++++++++++-
gold/testsuite/x32_no_overflow_32.sh | 27 +++++++++
gold/testsuite/x32_no_overflow_32s.sh | 27 +++++++++
gold/testsuite/x86_64_no_overflow_32.s | 8 +++
gold/testsuite/x86_64_no_overflow_32.sh | 27 +++++++++
gold/testsuite/x86_64_no_overflow_32s.s | 8 +++
gold/testsuite/x86_64_no_overflow_32s.sh | 27 +++++++++
gold/x86_64.cc | 11 +++-
11 files changed, 251 insertions(+), 4 deletions(-)
create mode 100755 gold/testsuite/x32_no_overflow_32.sh
create mode 100755 gold/testsuite/x32_no_overflow_32s.sh
create mode 100644 gold/testsuite/x86_64_no_overflow_32.s
create mode 100755 gold/testsuite/x86_64_no_overflow_32.sh
create mode 100644 gold/testsuite/x86_64_no_overflow_32s.s
create mode 100755 gold/testsuite/x86_64_no_overflow_32s.sh
diff --git a/gold/NEWS b/gold/NEWS
index 1880ea61d9..e29a67e280 100644
--- a/gold/NEWS
+++ b/gold/NEWS
@@ -1,3 +1,5 @@
+* Add -z noreloc-overflow option (x86-64 only).
+
Changes in 1.16:
* Improve warning messages for relocations that refer to discarded sections.
diff --git a/gold/options.h b/gold/options.h
index 51d3614e6b..e0ab73602d 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -1529,7 +1529,9 @@ class General_options
N_("Keep .text.hot, .text.startup, .text.exit and .text.unlikely "
"as separate sections in the final binary."),
N_("Merge all .text.* prefix sections."));
-
+ DEFINE_bool(noreloc_overflow, options::DASH_Z, '\0', false,
+ N_("(x86-64 only) Disable relocation overflow check."),
+ NULL);
public:
typedef options::Dir_list Dir_list;
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 768caad276..60899db102 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -1257,6 +1257,50 @@ x32_overflow_pc32.err: x32_overflow_pc32.o gcctestdir/ld
exit 1; \
fi
+check_SCRIPTS += x86_64_no_overflow_32s.sh
+check_DATA += x86_64_no_overflow_32s.stdout
+MOSTLYCLEANFILES += x86_64_no_overflow_32s
+
+x86_64_no_overflow_32s.o: x86_64_no_overflow_32s.s
+ $(TEST_AS) -o $@ $<
+x86_64_no_overflow_32s: x86_64_no_overflow_32s.o gcctestdir/ld
+ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+x86_64_no_overflow_32s.stdout: x86_64_no_overflow_32s
+ $(TEST_OBJDUMP) -dw $< > $@
+
+check_SCRIPTS += x86_64_no_overflow_32.sh
+check_DATA += x86_64_no_overflow_32.stdout
+MOSTLYCLEANFILES += x86_64_no_overflow_32
+
+x86_64_no_overflow_32.o: x86_64_no_overflow_32.s
+ $(TEST_AS) -o $@ $<
+x86_64_no_overflow_32: x86_64_no_overflow_32.o gcctestdir/ld
+ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+x86_64_no_overflow_32.stdout: x86_64_no_overflow_32
+ $(TEST_OBJDUMP) -dw $< > $@
+
+check_SCRIPTS += x32_no_overflow_32s.sh
+check_DATA += x32_no_overflow_32s.stdout
+MOSTLYCLEANFILES += x32_no_overflow_32s
+
+x32_no_overflow_32s.o: x86_64_no_overflow_32s.s
+ $(TEST_AS) --x32 -o $@ $<
+x32_no_overflow_32s: x32_no_overflow_32s.o gcctestdir/ld
+ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+x32_no_overflow_32s.stdout: x32_no_overflow_32s
+ $(TEST_OBJDUMP) -dw $< > $@
+
+check_SCRIPTS += x32_no_overflow_32.sh
+check_DATA += x32_no_overflow_32.stdout
+MOSTLYCLEANFILES += x32_no_overflow_32
+
+x32_no_overflow_32.o: x86_64_no_overflow_32.s
+ $(TEST_AS) --x32 -o $@ $<
+x32_no_overflow_32: x32_no_overflow_32.o gcctestdir/ld
+ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+x32_no_overflow_32.stdout: x32_no_overflow_32
+ $(TEST_OBJDUMP) -dw $< > $@
+
check_SCRIPTS += pr23016_1.sh
check_DATA += pr23016_1.stdout pr23016_1r.stdout
pr23016_1.stdout: pr23016_1.o
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index e8e4e6873b..64521fd124 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -296,6 +296,10 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@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@ x86_64_no_overflow_32s.sh \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_no_overflow_32.sh \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_no_overflow_32s.sh \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_no_overflow_32.sh \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1.sh \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_2.sh
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_30 = x86_64_mov_to_lea1.stdout \
@@ -317,6 +321,10 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@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@ x86_64_no_overflow_32s.stdout \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_no_overflow_32.stdout \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_no_overflow_32s.stdout \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_no_overflow_32.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1r.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_2.stdout
@@ -338,7 +346,11 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@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@ x32_overflow_pc32.err \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_no_overflow_32s \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_no_overflow_32 \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_no_overflow_32s \
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_no_overflow_32
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_32 = pr17704a_test
@DEFAULT_TARGET_X86_64_OR_X32_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_33 = pr20216a_test \
@DEFAULT_TARGET_X86_64_OR_X32_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr20216b_test \
@@ -5697,6 +5709,34 @@ x32_overflow_pc32.sh.log: x32_overflow_pc32.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_no_overflow_32s.sh.log: x86_64_no_overflow_32s.sh
+ @p='x86_64_no_overflow_32s.sh'; \
+ b='x86_64_no_overflow_32s.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_no_overflow_32.sh.log: x86_64_no_overflow_32.sh
+ @p='x86_64_no_overflow_32.sh'; \
+ b='x86_64_no_overflow_32.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)
+x32_no_overflow_32s.sh.log: x32_no_overflow_32s.sh
+ @p='x32_no_overflow_32s.sh'; \
+ b='x32_no_overflow_32s.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)
+x32_no_overflow_32.sh.log: x32_no_overflow_32.sh
+ @p='x32_no_overflow_32.sh'; \
+ b='x32_no_overflow_32.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)
pr23016_1.sh.log: pr23016_1.sh
@p='pr23016_1.sh'; \
b='pr23016_1.sh'; \
@@ -8417,6 +8457,34 @@ uninstall-am:
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ rm -f $@; \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ exit 1; \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ fi
+
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_no_overflow_32s.o: x86_64_no_overflow_32s.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_no_overflow_32s: x86_64_no_overflow_32s.o gcctestdir/ld
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_no_overflow_32s.stdout: x86_64_no_overflow_32s
+@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_no_overflow_32.o: x86_64_no_overflow_32.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_no_overflow_32: x86_64_no_overflow_32.o gcctestdir/ld
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_no_overflow_32.stdout: x86_64_no_overflow_32
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -dw $< > $@
+
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x32_no_overflow_32s.o: x86_64_no_overflow_32s.s
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) --x32 -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x32_no_overflow_32s: x32_no_overflow_32s.o gcctestdir/ld
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x32_no_overflow_32s.stdout: x32_no_overflow_32s
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -dw $< > $@
+
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x32_no_overflow_32.o: x86_64_no_overflow_32.s
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) --x32 -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x32_no_overflow_32: x32_no_overflow_32.o gcctestdir/ld
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -pie -z noreloc-overflow -z notext -o $@ $<
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x32_no_overflow_32.stdout: x32_no_overflow_32
+@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -dw $< > $@
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1.stdout: pr23016_1.o
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -rSW $< >$@ 2>/dev/null
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1.o: pr23016_1a.o pr23016_1b.o gcctestdir/ld
diff --git a/gold/testsuite/x32_no_overflow_32.sh b/gold/testsuite/x32_no_overflow_32.sh
new file mode 100755
index 0000000000..0e9075f3a7
--- /dev/null
+++ b/gold/testsuite/x32_no_overflow_32.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# x32_no_overflow_32.sh -- a test case to disable overflow checking
+# for R_X86_64_32.
+
+# 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]\+,%eax" x32_no_overflow_32.stdout
diff --git a/gold/testsuite/x32_no_overflow_32s.sh b/gold/testsuite/x32_no_overflow_32s.sh
new file mode 100755
index 0000000000..d8b2e40dcb
--- /dev/null
+++ b/gold/testsuite/x32_no_overflow_32s.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# x32_no_overflow_32s.sh -- a test case to disable overflow checking
+# for R_X86_64_32S.
+
+# 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]\+,%rax" x32_no_overflow_32s.stdout
diff --git a/gold/testsuite/x86_64_no_overflow_32.s b/gold/testsuite/x86_64_no_overflow_32.s
new file mode 100644
index 0000000000..2b309f2411
--- /dev/null
+++ b/gold/testsuite/x86_64_no_overflow_32.s
@@ -0,0 +1,8 @@
+ .globl _start
+ .type _start, @function
+_start:
+ movl $foo, %eax
+ .size _start, .-_start
+ .data
+foo:
+ .quad 0
diff --git a/gold/testsuite/x86_64_no_overflow_32.sh b/gold/testsuite/x86_64_no_overflow_32.sh
new file mode 100755
index 0000000000..4033c5ff2d
--- /dev/null
+++ b/gold/testsuite/x86_64_no_overflow_32.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# x86_64_no_overflow_32.sh -- a test case to disable overflow checking
+# for R_X86_64_32.
+
+# 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]\+,%eax" x86_64_no_overflow_32.stdout
diff --git a/gold/testsuite/x86_64_no_overflow_32s.s b/gold/testsuite/x86_64_no_overflow_32s.s
new file mode 100644
index 0000000000..0870f6ade0
--- /dev/null
+++ b/gold/testsuite/x86_64_no_overflow_32s.s
@@ -0,0 +1,8 @@
+ .globl _start
+ .type _start, @function
+_start:
+ movq $foo, %rax
+ .size _start, .-_start
+ .data
+foo:
+ .quad 0
diff --git a/gold/testsuite/x86_64_no_overflow_32s.sh b/gold/testsuite/x86_64_no_overflow_32s.sh
new file mode 100755
index 0000000000..52c41bdbe7
--- /dev/null
+++ b/gold/testsuite/x86_64_no_overflow_32s.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# x86_64_no_overflow_32s.sh -- a test case to disable overflow checking
+# for R_X86_64_32S.
+
+# 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]\+,%rax" x86_64_no_overflow_32s.stdout
diff --git a/gold/x86_64.cc b/gold/x86_64.cc
index 378bac16f7..6c3e39c030 100644
--- a/gold/x86_64.cc
+++ b/gold/x86_64.cc
@@ -3514,8 +3514,9 @@ Target_x86_64<size>::Scan::check_non_pic(Relobj* object, unsigned int r_type,
return;
// Fall through.
case elfcpp::R_X86_64_32:
- // R_X86_64_32 is OK for x32.
- if (size == 32 && r_type == elfcpp::R_X86_64_32)
+ // R_X86_64_32 is OK for x32 or with -z noreloc-overflow.
+ if (r_type == elfcpp::R_X86_64_32
+ && (size == 32 || parameters->options().noreloc_overflow()))
return;
if (this->issued_non_pic_error_)
return;
@@ -3549,6 +3550,12 @@ Target_x86_64<size>::Scan::check_non_pic(Relobj* object, unsigned int r_type,
this->issued_non_pic_error_ = true;
return;
+ case elfcpp::R_X86_64_32S:
+ // -z noreloc-overflow
+ if (parameters->options().noreloc_overflow())
+ return;
+ // Fall through.
+
default:
// This prevents us from issuing more than one error per reloc
// section. But we can still wind up issuing more than one
--
2.28.0
More information about the Binutils
mailing list