Problem with string merging and PC relative relocations

Andreas Schwab schwab@suse.de
Tue Feb 12 14:39:00 GMT 2002


Jakub Jelinek <jakub@redhat.com> writes:

|> On Mon, Feb 11, 2002 at 06:27:13PM +0100, Andreas Jaeger wrote:
|> > 
|> > Andreas Schwab and myself looked closer into this message on x86-64:
|> > 
|> > x86_64-unknown-linux-ld: /abuild/aj/build/elf/librtld.os: access beyond end of merged section (-4 + 0)
|> > 
|> > We've located this relocation in dl-cache.os (part of glibc):
|> >  216:   48 8d 3d 00 00 00 00    lea    0(%rip),%rdi        # 21d <_dl_load_cache_lookup+0x12d>
|> >                         219: R_X86_64_PC32      .rodata.str1.1+0xfffffffffffffffc
|> > 
|> > The problem is the PC-relative addressing here.  The offset
|> > compensates for the fact that the addressing is relative to the *next*
|> > instruction.  So, it is not really an offset into the string section -
|> > and should not be treated as such.
|> 
|> This should not happen.
|> Only local relocs against SHF_MERGE section with zero addend should be
|> converted to STT_SECTION + addend.
|> This is what gas/write.c (adjust_reloc_syms):
|>         /* Never adjust a reloc against local symbol in a merge section
|>            with non-zero addend.  */
|>         if ((symsec->flags & SEC_MERGE) && fixp->fx_offset)
|>           {
|>             symbol_mark_used_in_reloc (fixp->fx_addsy);
|>             goto done;
|>           }
|> 
|> is for. If you modify the addend later in tc-*, you need to care about it in
|> your tc-* files.

This should fix the problem:

2002-02-12  Andreas Schwab  <schwab@suse.de>

	* config/tc-i386.c (tc_i386_fix_adjustable): Don't adjust
	pc-relative relocations to merge sections in 64-bit mode.

--- gas/config/tc-i386.c.~1.109.~	Tue Feb 12 10:30:44 2002
+++ gas/config/tc-i386.c	Tue Feb 12 18:04:13 2002
@@ -1178,7 +1178,12 @@
   /* Prevent all adjustments to global symbols, or else dynamic
      linking will not work correctly.  */
   if (S_IS_EXTERNAL (fixP->fx_addsy)
-      || S_IS_WEAK (fixP->fx_addsy))
+      || S_IS_WEAK (fixP->fx_addsy)
+      /* Don't adjust pc-relative references to merge sections in 64-bit
+	 mode.  */
+      || (use_rela_relocations
+	  && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0
+	  && fixP->fx_pcrel))
     return 0;
 #endif
   /* adjust_reloc_syms doesn't know about the GOT.  */

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



More information about the Binutils mailing list