From patchwork Tue Nov 26 08:57:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 21767 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f71.google.com (mail-qe0-f71.google.com [209.85.128.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2E858202DA for ; Tue, 26 Nov 2013 08:57:55 +0000 (UTC) Received: by mail-qe0-f71.google.com with SMTP id b10sf5669283qen.10 for ; Tue, 26 Nov 2013 00:57:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=Om/y0NTixqkxItpOUQPt4zH9Qwszurk9hsnBZScG1w0=; b=T2TRtG3O7csyEg3papIGTfvHwds8B2SJtSoM8j/vZbbR/fBqm98fEUer9bS2R/CG5c Q20Y2/vaTIOOgD2/Sho7vUrX0OYNPMboq9vN6NghanZCqYHtjmHUgQK1wg0A7nZwc+Cm 1Dh+hKZ95dTuPGBGP/5l5mYILDmF+At58sU9eePvOQsFgc4U7mIKt//1PrCIBpT+lx3k AvCYHidJN9+TTANm24Soa5xF37cj4Pk45OYw+pp0GBbm7avFLAXhAl0fiViTrKogOFke 1iexzonCUTu7/6rf7FPOetPxpjOTmAmg/h2YzviB8f4nU5tNCfXTLmdpT4VKEbjx5ZDj HCQg== X-Gm-Message-State: ALoCoQmzyjMA2dysUdetr6a2ZWkyX0JkM14SxYHS0Tzre9+sqfN94jcIpFxACdUQGNq5NU4gp3KF X-Received: by 10.236.118.17 with SMTP id k17mr508417yhh.47.1385456275550; Tue, 26 Nov 2013 00:57:55 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.105.34 with SMTP id gj2ls2574785qeb.52.gmail; Tue, 26 Nov 2013 00:57:55 -0800 (PST) X-Received: by 10.52.168.106 with SMTP id zv10mr25111688vdb.21.1385456275460; Tue, 26 Nov 2013 00:57:55 -0800 (PST) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id 1si19180087vel.150.2013.11.26.00.57.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Nov 2013 00:57:55 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id ia6so3604175vcb.18 for ; Tue, 26 Nov 2013 00:57:55 -0800 (PST) X-Received: by 10.52.0.9 with SMTP id 9mr969793vda.47.1385456275367; Tue, 26 Nov 2013 00:57:55 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp196343vcz; Tue, 26 Nov 2013 00:57:54 -0800 (PST) X-Received: by 10.180.75.46 with SMTP id z14mr16902319wiv.58.1385456274395; Tue, 26 Nov 2013 00:57:54 -0800 (PST) Received: from mail-wg0-f52.google.com (mail-wg0-f52.google.com [74.125.82.52]) by mx.google.com with ESMTPS id mz16si8440189wic.13.2013.11.26.00.57.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Nov 2013 00:57:54 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.52 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=74.125.82.52; Received: by mail-wg0-f52.google.com with SMTP id x13so4991244wgg.31 for ; Tue, 26 Nov 2013 00:57:53 -0800 (PST) X-Received: by 10.195.13.45 with SMTP id ev13mr25457635wjd.20.1385456273875; Tue, 26 Nov 2013 00:57:53 -0800 (PST) Received: from localhost.localdomain (cpc6-seac21-2-0-cust453.7-2.cable.virginm.net. [82.1.113.198]) by mx.google.com with ESMTPSA id x19sm58563614wia.5.2013.11.26.00.57.51 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Nov 2013 00:57:52 -0800 (PST) Message-ID: <5294628E.30507@linaro.org> Date: Tue, 26 Nov 2013 08:57:50 +0000 From: Will Newton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: libc-ports@sourceware.org CC: Patch Tracking Subject: [PATCH] aarch64: Enable ifunc support. X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add support for handling the R_AARCH64_IRELATIVE relocation and STT_GNU_IFUNC symbols to the aarch64 port. ports/ChangeLog.aarch64: 2013-11-25 Will Newton * sysdeps/aarch64/dl-irel.h: Include ldsodefs.h. (ELF_MACHINE_IRELA): Define. (elf_ifunc_invoke): Pass hwcap to ifunc resolver function. (elf_irela): New function. * sysdeps/aarch64/dl-machine.h: Include dl-irel.h. (elf_machine_rela) Handle STT_GNU_IFUNC symbols and R_AARCH64_IRELATIVE relocations. (elf_machine_lazy_rel): Handle R_AARCH64_IRELATIVE relocations. --- ports/sysdeps/aarch64/dl-irel.h | 22 +++++++++++++++++++--- ports/sysdeps/aarch64/dl-machine.h | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ports/sysdeps/aarch64/dl-irel.h b/ports/sysdeps/aarch64/dl-irel.h index 1a3811e..f37ee39 100644 --- a/ports/sysdeps/aarch64/dl-irel.h +++ b/ports/sysdeps/aarch64/dl-irel.h @@ -22,15 +22,31 @@ #include #include +#include -/* AArch64 does not yet implement IFUNC support. However since - 2011-06-20 provision of a elf_ifunc_invoke has been mandatory. */ +#define ELF_MACHINE_IRELA 1 static inline ElfW(Addr) __attribute ((always_inline)) elf_ifunc_invoke (ElfW(Addr) addr) { - return ((ElfW(Addr) (*) (void)) (addr)) (); + return ((ElfW(Addr) (*) (unsigned long int)) (addr)) (GLRO(dl_hwcap)); +} + +static inline void +__attribute ((always_inline)) +elf_irela (const ElfW(Rela) *reloc) +{ + ElfW(Addr) *const reloc_addr = (void *) reloc->r_offset; + const unsigned long int r_type = ELFW(R_TYPE) (reloc->r_info); + + if (__glibc_likely (r_type == R_AARCH64_IRELATIVE)) + { + ElfW(Addr) value = elf_ifunc_invoke (reloc->r_addend); + *reloc_addr = value; + } + else + __libc_fatal ("unexpected reloc type in static binary"); } #endif diff --git a/ports/sysdeps/aarch64/dl-machine.h b/ports/sysdeps/aarch64/dl-machine.h index 71dd6b3..01a214f 100644 --- a/ports/sysdeps/aarch64/dl-machine.h +++ b/ports/sysdeps/aarch64/dl-machine.h @@ -23,6 +23,7 @@ #include #include +#include /* Return nonzero iff ELF header is compatible with the running host. */ static inline int __attribute__ ((unused)) @@ -243,6 +244,12 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); ElfW(Addr) value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; + if (sym != NULL + && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC) + && __glibc_likely (sym->st_shndx != SHN_UNDEF) + && __glibc_likely (!skip_ifunc)) + value = elf_ifunc_invoke (value); + switch (r_type) { case R_AARCH64_COPY: @@ -331,6 +338,12 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, } break; + case R_AARCH64_IRELATIVE: + value = map->l_addr + reloc->r_addend; + value = elf_ifunc_invoke (value); + *reloc_addr = value; + break; + default: _dl_reloc_bad_type (map, r_type, 0); break; @@ -374,6 +387,13 @@ elf_machine_lazy_rel (struct link_map *map, td->entry = (void*)(D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)]) + map->l_addr); } + else if (__glibc_unlikely (r_type == R_AARCH64_IRELATIVE)) + { + ElfW(Addr) value = map->l_addr + reloc->r_addend; + if (__glibc_likely (!skip_ifunc)) + value = elf_ifunc_invoke (value); + *reloc_addr = value; + } else _dl_reloc_bad_type (map, r_type, 1); }