public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>, Roland McGrath <roland@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix sparc64 non-pic relocation handling
Date: Thu, 07 Sep 2006 22:09:00 -0000	[thread overview]
Message-ID: <20060907220939.GZ4556@sunsite.mff.cuni.cz> (raw)

Hi!

These 4 are all non-PIC relocations, so they are pretty unlikely to
work well in 64-bit programs, still, we shouldn't clobber the rest of
the instructions (bits outside of the immediate field).
E.g. for R_SPARC_WDISP30 that can happen even when the relocation
doesn't overflow (if it is a call to a function located below the call
insn, from -2GB to 4 bytes before it).

2006-09-07  Jakub Jelinek  <jakub@redhat.com>

	[BZ #1006]
	* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela)
	Ensure relocation doesn't clobber any bits outside of the
	immediate field for R_SPARC_TLS_LE_HIX22, R_SPARC_WDISP30,
	R_SPARC_HI22 and R_SPARC_H44.

--- libc/sysdeps/sparc/sparc64/dl-machine.h	14 Apr 2005 21:39:27 -0000	1.50
+++ libc/sysdeps/sparc/sparc64/dl-machine.h	7 Sep 2006 21:54:30 -0000
@@ -1,5 +1,5 @@
 /* Machine-dependent ELF dynamic relocation inline functions.  Sparc64 version.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
 	Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -623,7 +623,8 @@ elf_machine_rela (struct link_map *map, 
 	  value = sym->st_value - sym_map->l_tls_offset
 	    + reloc->r_addend;
 	  if (r_type == R_SPARC_TLS_LE_HIX22)
-	    *reloc_addr = (*reloc_addr & 0xffc00000) | ((~value) >> 10);
+	    *reloc_addr = (*reloc_addr & 0xffc00000)
+	      | (((~value) >> 10) & 0x3fffff);
 	  else
 	    *reloc_addr = (*reloc_addr & 0xffffe000) | (value & 0x3ff)
 	      | 0x1c00;
@@ -653,7 +654,7 @@ elf_machine_rela (struct link_map *map, 
     case R_SPARC_WDISP30:
       *(unsigned int *) reloc_addr =
 	((*(unsigned int *)reloc_addr & 0xc0000000) |
-	 ((value - (Elf64_Addr) reloc_addr) >> 2));
+	 (((value - (Elf64_Addr) reloc_addr) >> 2) & 0x3fffffff));
       break;
 
       /* MEDLOW code model relocs */
@@ -665,7 +666,7 @@ elf_machine_rela (struct link_map *map, 
     case R_SPARC_HI22:
       *(unsigned int *) reloc_addr =
 	((*(unsigned int *)reloc_addr & 0xffc00000) |
-	 (value >> 10));
+	 ((value >> 10) & 0x3fffff));
       break;
     case R_SPARC_OLO10:
       *(unsigned int *) reloc_addr =
@@ -677,7 +678,7 @@ elf_machine_rela (struct link_map *map, 
     case R_SPARC_H44:
       *(unsigned int *) reloc_addr =
 	((*(unsigned int *)reloc_addr & 0xffc00000) |
-	 (value >> 22));
+	 ((value >> 22) & 0x3fffff));
       break;
     case R_SPARC_M44:
       *(unsigned int *) reloc_addr =

	Jakub

                 reply	other threads:[~2006-09-07 22:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060907220939.GZ4556@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    --cc=roland@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).