From patchwork Mon Mar 14 16:16:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 557 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:43:41 -0000 Delivered-To: patches@linaro.org Received: by 10.224.45.75 with SMTP id d11cs61133qaf; Mon, 14 Mar 2011 09:23:49 -0700 (PDT) Received: by 10.213.107.146 with SMTP id b18mr3208449ebp.51.1300119828306; Mon, 14 Mar 2011 09:23:48 -0700 (PDT) Received: from mail-wy0-f178.google.com (mail-wy0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id p46si9209669eeh.58.2011.03.14.09.23.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Mar 2011 09:23:48 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of richard.sandiford@linaro.org) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of richard.sandiford@linaro.org) smtp.mail=richard.sandiford@linaro.org Received: by wyj26 with SMTP id 26so5316136wyj.37 for ; Mon, 14 Mar 2011 09:23:47 -0700 (PDT) Received: by 10.216.182.20 with SMTP id n20mr71724wem.113.1300119421825; Mon, 14 Mar 2011 09:17:01 -0700 (PDT) Received: from richards-thinkpad (gbibp9ph1--blueice2n1.emea.ibm.com [195.212.29.75]) by mx.google.com with ESMTPS id o19sm3911039wee.26.2011.03.14.09.17.00 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Mar 2011 09:17:01 -0700 (PDT) From: Richard Sandiford To: libc-ports@sourceware.org Mail-Followup-To: libc-ports@sourceware.org, patches@linaro.org, richard.sandiford@linaro.org Cc: patches@linaro.org Subject: Support for R_ARM_IRELATIVE relocations Date: Mon, 14 Mar 2011 16:16:58 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 ARM have allocated R_ARM_IRELATIVE the relocation number 160 (thanks). This patch adds GLIBC support for it. Like PPC, the relocation is only allowed in the normal DT_REL(A) table, not in DT_JMPREL. Tested on arm-linux-gnueabi with --enable-multi-arch. All ifunc* tests passed. (I actually cross-tested using EGLIBC, with a local patch to make the ifunc tests cross-testing friendly. I also used a dummy arm/multiarch/Makefile, so that --enable-multi-arch was honoured.) Please install if OK. Richard 2011-03-14 Richard Sandiford libc/ * elf/elf.h (R_ARM_IRELATIVE): Define. ports/ * sysdeps/arm/dl-machine.h (elf_machine_rel): Handle STT_GNU_IFUNC and R_ARM_IRELATIVE. (elf_machine_rela): Likewise. * sysdeps/arm/dl-irel.h: New file. Index: libc/elf/elf.h =================================================================== --- libc/elf/elf.h 2011-03-14 16:12:41.000000000 +0000 +++ libc/elf/elf.h 2011-03-14 16:12:56.000000000 +0000 @@ -2353,6 +2353,7 @@ #define R_ARM_TLS_IE32 107 /* PC-rel 32 static TLS block offset */ #define R_ARM_TLS_LE32 108 /* 32 bit offset relative to static TLS block */ +#define R_ARM_IRELATIVE 160 #define R_ARM_RXPC25 249 #define R_ARM_RSBREL32 250 #define R_ARM_THM_RPC22 251 Index: ports/sysdeps/arm/dl-irel.h =================================================================== --- /dev/null 2011-03-14 08:51:58.266827044 +0000 +++ ports/sysdeps/arm/dl-irel.h 2011-03-14 16:12:56.000000000 +0000 @@ -0,0 +1,45 @@ +/* Machine-dependent ELF indirect relocation inline functions. + ARM version. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _DL_IREL_H +#define _DL_IREL_H + +#include +#include + +#define ELF_MACHINE_IREL 1 + +static inline void +__attribute ((always_inline)) +elf_irel (const Elf32_Rel *reloc) +{ + Elf32_Addr *const reloc_addr = (void *) reloc->r_offset; + const unsigned long int r_type = ELF32_R_TYPE (reloc->r_info); + + if (__builtin_expect (r_type == R_ARM_IRELATIVE, 1)) + { + Elf32_Addr value = ((Elf32_Addr (*) (void)) (*reloc_addr)) (); + *reloc_addr = value; + } + else + __libc_fatal ("unexpected reloc type in static binary"); +} + +#endif /* dl-irel.h */ Index: ports/sysdeps/arm/dl-machine.h =================================================================== --- ports/sysdeps/arm/dl-machine.h 2011-03-14 16:12:41.000000000 +0000 +++ ports/sysdeps/arm/dl-machine.h 2011-03-14 16:12:56.000000000 +0000 @@ -367,6 +367,12 @@ elf_machine_rel (struct link_map *map, c struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; + if (sym != NULL + && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, + 0) + && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)) + value = ((Elf32_Addr (*) (void)) value) (); + switch (r_type) { case R_ARM_COPY: @@ -447,7 +453,8 @@ elf_machine_rel (struct link_map *map, c *reloc_addr = value; } break; -#if defined USE_TLS && !defined RTLD_BOOTSTRAP +#if !defined RTLD_BOOTSTRAP +#if defined USE_TLS case R_ARM_TLS_DTPMOD32: /* Get the information from the link map returned by the resolv function. */ @@ -468,6 +475,12 @@ elf_machine_rel (struct link_map *map, c } break; #endif + case R_ARM_IRELATIVE: + value = map->l_addr + *reloc_addr; + value = ((Elf32_Addr (*) (void)) value) (); + *reloc_addr = value; + break; +#endif default: _dl_reloc_bad_type (map, r_type, 0); break; @@ -497,6 +510,12 @@ elf_machine_rela (struct link_map *map, struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; + if (sym != NULL + && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, + 0) + && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)) + value = ((Elf32_Addr (*) (void)) value) (); + switch (r_type) { # ifndef RESOLVE_CONFLICT_FIND_MAP @@ -548,7 +567,8 @@ elf_machine_rela (struct link_map *map, *reloc_addr = value; } break; -#if defined USE_TLS && !defined RTLD_BOOTSTRAP +#if !defined RTLD_BOOTSTRAP +#if defined USE_TLS case R_ARM_TLS_DTPMOD32: /* Get the information from the link map returned by the resolv function. */ @@ -569,6 +589,12 @@ elf_machine_rela (struct link_map *map, } break; #endif + case R_ARM_IRELATIVE: + value = map->l_addr + *reloc_addr; + value = ((Elf32_Addr (*) (void)) value) (); + *reloc_addr = value; + break; +#endif default: _dl_reloc_bad_type (map, r_type, 0); break;