Add some relocation overflow checks for x86_64.

2016-02-05  Cary Coutant  <ccoutant@gmail.com>
	    Andrew Senkevich  <andrew.senkevich@intel.com>

gold/
	PR gold/18695
	* x86_64.cc (Target_x86_64::Relocate::relocate): Add overflow
	checking for R_X86_64_32, R_X86_64_32S, R_X86_64_PC32, and
	R_X86_64_PLT32.
	* testsuite/Makefile.am (x86_64_overflow_pc32): New test.
	* testsuite/x86_64_overflow_pc32.sh: New test script.
	* testsuite/x86_64_overflow_pc32.s: New source file.
This commit is contained in:
Cary Coutant 2016-02-05 09:19:47 -08:00
parent 44803b5d87
commit c34c98ed62
6 changed files with 157 additions and 47 deletions

View File

@ -1,4 +1,15 @@
2016-02-06 Cary Coutant <ccoutant@gmail.com> 2016-02-05 Cary Coutant <ccoutant@gmail.com>
Andrew Senkevich <andrew.senkevich@intel.com>
PR gold/18695
* x86_64.cc (Target_x86_64::Relocate::relocate): Add overflow
checking for R_X86_64_32, R_X86_64_32S, R_X86_64_PC32, and
R_X86_64_PLT32.
* testsuite/Makefile.am (x86_64_overflow_pc32): New test.
* testsuite/x86_64_overflow_pc32.sh: New test script.
* testsuite/x86_64_overflow_pc32.s: New source file.
2016-02-05 Cary Coutant <ccoutant@gmail.com>
PR gold/18695 PR gold/18695
* reloc.h (Relocate_functions::Address): New typedef. * reloc.h (Relocate_functions::Address): New typedef.

View File

@ -1074,6 +1074,20 @@ x86_64_mov_to_lea13.stdout: x86_64_mov_to_lea13
x86_64_mov_to_lea14.stdout: x86_64_mov_to_lea14 x86_64_mov_to_lea14.stdout: x86_64_mov_to_lea14
$(TEST_OBJDUMP) -dw $< > $@ $(TEST_OBJDUMP) -dw $< > $@
check_SCRIPTS += x86_64_overflow_pc32.sh
check_DATA += x86_64_overflow_pc32.err
MOSTLYCLEANFILES += x86_64_overflow_pc32.err
x86_64_overflow_pc32.o: x86_64_overflow_pc32.s
$(TEST_AS) -o $@ $<
x86_64_overflow_pc32.err: x86_64_overflow_pc32.o gcctestdir/ld
@echo $(CXXLINK) -Bgcctestdir/ -shared -o x86_64_overflow_pc32 x86_64_overflow_pc32.o "2>$@"
@if $(CXXLINK) -Bgcctestdir/ -shared -o x86_64_overflow_pc32 x86_64_overflow_pc32.o 2>$@; \
then \
echo 1>&2 "Link of x86_64_overflow_pc32 should have failed"; \
rm -f $@; \
exit 1; \
fi
endif DEFAULT_TARGET_X86_64 endif DEFAULT_TARGET_X86_64
if DEFAULT_TARGET_I386 if DEFAULT_TARGET_I386

View File

@ -199,21 +199,38 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@HAVE_STATIC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@am__append_24 = tls_static_test \ @GCC_TRUE@@HAVE_STATIC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@am__append_24 = tls_static_test \
@GCC_TRUE@@HAVE_STATIC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@ tls_static_pic_test @GCC_TRUE@@HAVE_STATIC_TRUE@@NATIVE_LINKER_TRUE@@STATIC_TLS_TRUE@@TLS_TRUE@ tls_static_pic_test
@FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_25 = tls_shared_nonpic_test @FN_PTRS_IN_SO_WITHOUT_PIC_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_25 = tls_shared_nonpic_test
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_26 = x86_64_mov_to_lea.sh @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_26 = x86_64_mov_to_lea.sh \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_27 = x86_64_mov_to_lea1.stdout x86_64_mov_to_lea2.stdout \ @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@ x86_64_mov_to_lea3.stdout x86_64_mov_to_lea4.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_27 = x86_64_mov_to_lea1.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea5.stdout x86_64_mov_to_lea6.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea2.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea7.stdout x86_64_mov_to_lea8.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea3.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea9.stdout x86_64_mov_to_lea10.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea4.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea11.stdout x86_64_mov_to_lea12.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea5.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea13.stdout x86_64_mov_to_lea14.stdout @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea6.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea7.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_28 = x86_64_mov_to_lea1 x86_64_mov_to_lea2 \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea8.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea3 x86_64_mov_to_lea4 x86_64_mov_to_lea5 \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea9.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea6 x86_64_mov_to_lea7 x86_64_mov_to_lea8 \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea10.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea9 x86_64_mov_to_lea10 x86_64_mov_to_lea11 \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea11.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea12 x86_64_mov_to_lea13 x86_64_mov_to_lea14 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea12.stdout \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea13.stdout \
@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_overflow_pc32.err
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_28 = x86_64_mov_to_lea1 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea2 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea3 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea4 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea5 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea6 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea7 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea8 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea9 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea10 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea11 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea12 \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea13 \
@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_overflow_pc32.err
@DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_29 = i386_mov_to_lea.sh @DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_29 = i386_mov_to_lea.sh
@DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_30 = i386_mov_to_lea1.stdout i386_mov_to_lea2.stdout \ @DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_30 = i386_mov_to_lea1.stdout i386_mov_to_lea2.stdout \
@DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ i386_mov_to_lea3.stdout i386_mov_to_lea4.stdout \ @DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ i386_mov_to_lea3.stdout i386_mov_to_lea4.stdout \
@ -4426,6 +4443,8 @@ tls_pie_test.sh.log: tls_pie_test.sh
@p='tls_pie_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) @p='tls_pie_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
x86_64_mov_to_lea.sh.log: x86_64_mov_to_lea.sh x86_64_mov_to_lea.sh.log: x86_64_mov_to_lea.sh
@p='x86_64_mov_to_lea.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) @p='x86_64_mov_to_lea.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
x86_64_overflow_pc32.sh.log: x86_64_overflow_pc32.sh
@p='x86_64_overflow_pc32.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
i386_mov_to_lea.sh.log: i386_mov_to_lea.sh i386_mov_to_lea.sh.log: i386_mov_to_lea.sh
@p='i386_mov_to_lea.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) @p='i386_mov_to_lea.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
debug_msg.sh.log: debug_msg.sh debug_msg.sh.log: debug_msg.sh
@ -5469,6 +5488,16 @@ uninstall-am:
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -dw $< > $@ @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_mov_to_lea14.stdout: x86_64_mov_to_lea14 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@x86_64_mov_to_lea14.stdout: x86_64_mov_to_lea14
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -dw $< > $@ @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
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ @echo $(CXXLINK) -Bgcctestdir/ -shared -o x86_64_overflow_pc32 x86_64_overflow_pc32.o "2>$@"
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ @if $(CXXLINK) -Bgcctestdir/ -shared -o x86_64_overflow_pc32 x86_64_overflow_pc32.o 2>$@; \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ then \
@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ echo 1>&2 "Link of x86_64_overflow_pc32 should have failed"; \
@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_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@i386_mov_to_lea1.o: i386_mov_to_lea1.s @DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@i386_mov_to_lea1.o: i386_mov_to_lea1.s
@DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) --32 -o $@ $< @DEFAULT_TARGET_I386_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) --32 -o $@ $<

View File

@ -0,0 +1,15 @@
.data
.space 0x8ff00000
.hidden foo
.globl foo
foo:
.byte 20
local:
.byte 20
.text
.globl bar
.type bar, @function
bar:
lea foo(%rip), %rax
lea local(%rip), %rax
.size bar, .-bar

View File

@ -0,0 +1,42 @@
#!/bin/sh
# x86_64_overflow_pc32.sh -- a test case for overflow checking.
# Copyright (C) 2016 Free Software Foundation, Inc.
# Written by Cary Coutant <ccoutant@gmail.com>.
# 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.
check()
{
if ! grep -q "$2" "$1"
then
echo "Did not find expected error in $1:"
echo " $2"
echo ""
echo "Actual error output below:"
cat "$1"
exit 1
fi
}
# We don't know how the compiler might order these variables, so we
# can't test for the actual offset from .data, hence the regexp.
check x86_64_overflow_pc32.err "function bar: error: relocation overflow"
exit 0

View File

@ -3364,6 +3364,7 @@ Target_x86_64<size>::Relocate::relocate(
typename elfcpp::Elf_types<size>::Elf_Addr address, typename elfcpp::Elf_types<size>::Elf_Addr address,
section_size_type view_size) section_size_type view_size)
{ {
typedef Relocate_functions<size, false> Reloc_funcs;
const elfcpp::Rela<size, false> rela(preloc); const elfcpp::Rela<size, false> rela(preloc);
unsigned int r_type = elfcpp::elf_r_type<size>(rela.get_r_info()); unsigned int r_type = elfcpp::elf_r_type<size>(rela.get_r_info());
@ -3444,6 +3445,8 @@ Target_x86_64<size>::Relocate::relocate(
break; break;
} }
typename Reloc_funcs::Reloc_status rstatus = Reloc_funcs::RELOC_OK;
switch (r_type) switch (r_type)
{ {
case elfcpp::R_X86_64_NONE: case elfcpp::R_X86_64_NONE:
@ -3452,51 +3455,44 @@ Target_x86_64<size>::Relocate::relocate(
break; break;
case elfcpp::R_X86_64_64: case elfcpp::R_X86_64_64:
Relocate_functions<size, false>::rela64(view, object, psymval, addend); Reloc_funcs::rela64(view, object, psymval, addend);
break; break;
case elfcpp::R_X86_64_PC64: case elfcpp::R_X86_64_PC64:
Relocate_functions<size, false>::pcrela64(view, object, psymval, addend, Reloc_funcs::pcrela64(view, object, psymval, addend,
address); address);
break; break;
case elfcpp::R_X86_64_32: case elfcpp::R_X86_64_32:
// FIXME: we need to verify that value + addend fits into 32 bits: rstatus = Reloc_funcs::rela32_check(view, object, psymval, addend,
// uint64_t x = value + addend; Reloc_funcs::CHECK_UNSIGNED);
// x == static_cast<uint64_t>(static_cast<uint32_t>(x))
// Likewise for other <=32-bit relocations (but see R_X86_64_32S).
Relocate_functions<size, false>::rela32(view, object, psymval, addend);
break; break;
case elfcpp::R_X86_64_32S: case elfcpp::R_X86_64_32S:
// FIXME: we need to verify that value + addend fits into 32 bits: rstatus = Reloc_funcs::rela32_check(view, object, psymval, addend,
// int64_t x = value + addend; // note this quantity is signed! Reloc_funcs::CHECK_SIGNED);
// x == static_cast<int64_t>(static_cast<int32_t>(x))
Relocate_functions<size, false>::rela32(view, object, psymval, addend);
break; break;
case elfcpp::R_X86_64_PC32: case elfcpp::R_X86_64_PC32:
case elfcpp::R_X86_64_PC32_BND: case elfcpp::R_X86_64_PC32_BND:
Relocate_functions<size, false>::pcrela32(view, object, psymval, addend, rstatus = Reloc_funcs::pcrela32_check(view, object, psymval, addend,
address); address, Reloc_funcs::CHECK_SIGNED);
break; break;
case elfcpp::R_X86_64_16: case elfcpp::R_X86_64_16:
Relocate_functions<size, false>::rela16(view, object, psymval, addend); Reloc_funcs::rela16(view, object, psymval, addend);
break; break;
case elfcpp::R_X86_64_PC16: case elfcpp::R_X86_64_PC16:
Relocate_functions<size, false>::pcrela16(view, object, psymval, addend, Reloc_funcs::pcrela16(view, object, psymval, addend, address);
address);
break; break;
case elfcpp::R_X86_64_8: case elfcpp::R_X86_64_8:
Relocate_functions<size, false>::rela8(view, object, psymval, addend); Reloc_funcs::rela8(view, object, psymval, addend);
break; break;
case elfcpp::R_X86_64_PC8: case elfcpp::R_X86_64_PC8:
Relocate_functions<size, false>::pcrela8(view, object, psymval, addend, Reloc_funcs::pcrela8(view, object, psymval, addend, address);
address);
break; break;
case elfcpp::R_X86_64_PLT32: case elfcpp::R_X86_64_PLT32:
@ -3510,8 +3506,8 @@ Target_x86_64<size>::Relocate::relocate(
// Note: while this code looks the same as for R_X86_64_PC32, it // Note: while this code looks the same as for R_X86_64_PC32, it
// behaves differently because psymval was set to point to // behaves differently because psymval was set to point to
// the PLT entry, rather than the symbol, in Scan::global(). // the PLT entry, rather than the symbol, in Scan::global().
Relocate_functions<size, false>::pcrela32(view, object, psymval, addend, rstatus = Reloc_funcs::pcrela32_check(view, object, psymval, addend,
address); address, Reloc_funcs::CHECK_SIGNED);
break; break;
case elfcpp::R_X86_64_PLTOFF64: case elfcpp::R_X86_64_PLTOFF64:
@ -3522,14 +3518,13 @@ Target_x86_64<size>::Relocate::relocate(
typename elfcpp::Elf_types<size>::Elf_Addr got_address; typename elfcpp::Elf_types<size>::Elf_Addr got_address;
// This is the address of GLOBAL_OFFSET_TABLE. // This is the address of GLOBAL_OFFSET_TABLE.
got_address = target->got_plt_section()->address(); got_address = target->got_plt_section()->address();
Relocate_functions<size, false>::rela64(view, object, psymval, Reloc_funcs::rela64(view, object, psymval, addend - got_address);
addend - got_address);
} }
break; break;
case elfcpp::R_X86_64_GOT32: case elfcpp::R_X86_64_GOT32:
gold_assert(have_got_offset); gold_assert(have_got_offset);
Relocate_functions<size, false>::rela32(view, got_offset, addend); Reloc_funcs::rela32(view, got_offset, addend);
break; break;
case elfcpp::R_X86_64_GOTPC32: case elfcpp::R_X86_64_GOTPC32:
@ -3537,7 +3532,7 @@ Target_x86_64<size>::Relocate::relocate(
gold_assert(gsym); gold_assert(gsym);
typename elfcpp::Elf_types<size>::Elf_Addr value; typename elfcpp::Elf_types<size>::Elf_Addr value;
value = target->got_plt_section()->address(); value = target->got_plt_section()->address();
Relocate_functions<size, false>::pcrela32(view, value, addend, address); Reloc_funcs::pcrela32(view, value, addend, address);
} }
break; break;
@ -3546,7 +3541,7 @@ Target_x86_64<size>::Relocate::relocate(
// R_X86_64_GOTPLT64 is obsolete and treated the the same as // R_X86_64_GOTPLT64 is obsolete and treated the the same as
// GOT64. // GOT64.
gold_assert(have_got_offset); gold_assert(have_got_offset);
Relocate_functions<size, false>::rela64(view, got_offset, addend); Reloc_funcs::rela64(view, got_offset, addend);
break; break;
case elfcpp::R_X86_64_GOTPC64: case elfcpp::R_X86_64_GOTPC64:
@ -3554,7 +3549,7 @@ Target_x86_64<size>::Relocate::relocate(
gold_assert(gsym); gold_assert(gsym);
typename elfcpp::Elf_types<size>::Elf_Addr value; typename elfcpp::Elf_types<size>::Elf_Addr value;
value = target->got_plt_section()->address(); value = target->got_plt_section()->address();
Relocate_functions<size, false>::pcrela64(view, value, addend, address); Reloc_funcs::pcrela64(view, value, addend, address);
} }
break; break;
@ -3563,7 +3558,7 @@ Target_x86_64<size>::Relocate::relocate(
typename elfcpp::Elf_types<size>::Elf_Addr value; typename elfcpp::Elf_types<size>::Elf_Addr value;
value = (psymval->value(object, 0) value = (psymval->value(object, 0)
- target->got_plt_section()->address()); - target->got_plt_section()->address());
Relocate_functions<size, false>::rela64(view, value, addend); Reloc_funcs::rela64(view, value, addend);
} }
break; break;
@ -3582,7 +3577,7 @@ Target_x86_64<size>::Relocate::relocate(
&& Target_x86_64<size>::can_convert_mov_to_lea(gsym)))) && Target_x86_64<size>::can_convert_mov_to_lea(gsym))))
{ {
view[-2] = 0x8d; view[-2] = 0x8d;
Relocate_functions<size, false>::pcrela32(view, object, psymval, addend, Reloc_funcs::pcrela32(view, object, psymval, addend,
address); address);
} }
else else
@ -3601,7 +3596,7 @@ Target_x86_64<size>::Relocate::relocate(
} }
typename elfcpp::Elf_types<size>::Elf_Addr value; typename elfcpp::Elf_types<size>::Elf_Addr value;
value = target->got_plt_section()->address() + got_offset; value = target->got_plt_section()->address() + got_offset;
Relocate_functions<size, false>::pcrela32(view, value, addend, address); Reloc_funcs::pcrela32(view, value, addend, address);
} }
} }
break; break;
@ -3611,7 +3606,7 @@ Target_x86_64<size>::Relocate::relocate(
gold_assert(have_got_offset); gold_assert(have_got_offset);
typename elfcpp::Elf_types<size>::Elf_Addr value; typename elfcpp::Elf_types<size>::Elf_Addr value;
value = target->got_plt_section()->address() + got_offset; value = target->got_plt_section()->address() + got_offset;
Relocate_functions<size, false>::pcrela64(view, value, addend, address); Reloc_funcs::pcrela64(view, value, addend, address);
} }
break; break;
@ -3651,6 +3646,10 @@ Target_x86_64<size>::Relocate::relocate(
break; break;
} }
if (rstatus == Reloc_funcs::RELOC_OVERFLOW)
gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
_("relocation overflow"));
return true; return true;
} }