This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: PR gold/16945: Executable with -fpie and -mcmodel=large gives segfault on start

There are 2 issues:

1. Since the GOT offset is always negative, we need to use signed int
to support 64-bit GOT relocations.
2. R_X86_64_PLTOFF64 uses the address of GLOBAL_OFFSET_TABLE, which is
the address of the .got.plt section, not the .got section.

This patch fixes both.  OK for master and 2.24 branch?


2014-05-15  H.J. Lu  <>

	PR gold/16945
	* (Target_x86_64::Relocate::relocate): Use signed int
	for got_offset.  Properly get GOT address for R_X86_64_PLTOFF64.

diff --git a/gold/ b/gold/
index 479fb42..f58c843 100644
--- a/gold/
+++ b/gold/
@@ -3327,7 +3327,9 @@ Target_x86_64<size>::Relocate::relocate(
   // We need to subtract the size of the GOT section to get
   // the actual offset to use in the relocation.
   bool have_got_offset = false;
-  unsigned int got_offset = 0;
+  // Since the actual offset is always negative, we use signed int to
+  // support 64-bit GOT relocations.
+  int got_offset = 0;
   switch (r_type)
     case elfcpp::R_X86_64_GOT32:
@@ -3430,7 +3432,8 @@ Target_x86_64<size>::Relocate::relocate(
 		    || gsym->final_value_is_known());
 	typename elfcpp::Elf_types<size>::Elf_Addr got_address;
-	got_address = target->got_section(NULL, NULL)->address();
+	// This is the address of GLOBAL_OFFSET_TABLE.
+	got_address = target->got_plt_section()->address();
 	Relocate_functions<size, false>::rela64(view, object, psymval,
 						addend - got_address);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]