From patchwork Fri May 23 14:13:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 30793 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 540E020369 for ; Fri, 23 May 2014 14:14:05 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf23668792iec.6 for ; Fri, 23 May 2014 07:14:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:subject:date :message-id:x-original-sender:x-original-authentication-results; bh=PZG2TjZXcI0JTh38iX3tY58TO/7OabWpc+2UcRPiCR0=; b=Mb5qgXVUZGg6dHCY2M0vzv6NAsflBvL0gN4p/MQzsnaVXxnNI8o+zKikcHQU9+FNIS wWuJU8mLJLOy2fn5+PTCeS1F+SJttWc39saDWPAdR1PBwTtDIxdQp+a69U68/j6RZoYa lhxkd7zx1N1NhwoCZLlJdvOaR+w0hkxmGvHVklTA9mL3zLi3P4MueI/F3uKZ42Yi25I/ Qe25gcrk0RCQvvp5jVnL4AocMkPK+3dTlCAnj3tN+N/csXEOOpSH5ol+I1hoKBXJNaH0 +REziwJnUSAr4JSCtvGOnXh/HnPKgW4dmKwGnlfMEiYCNOpcYekg6Hm54+FU2bipiWFc /aOw== X-Gm-Message-State: ALoCoQl+mE9A0QQ5k7XU0SJmN7VK34+4OoO1+F22AhhcRU/nm9us0OHy8P7AzRM+oCzqhrq3Rfz5 X-Received: by 10.182.252.166 with SMTP id zt6mr2178621obc.17.1400854444651; Fri, 23 May 2014 07:14:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.84 with SMTP id h78ls1806182qge.54.gmail; Fri, 23 May 2014 07:14:04 -0700 (PDT) X-Received: by 10.58.246.164 with SMTP id xx4mr696761vec.52.1400854444430; Fri, 23 May 2014 07:14:04 -0700 (PDT) Received: from mail-vc0-x22f.google.com (mail-vc0-x22f.google.com [2607:f8b0:400c:c03::22f]) by mx.google.com with ESMTPS id u14si1674263vdj.101.2014.05.23.07.14.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 May 2014 07:14:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22f as permitted sender) client-ip=2607:f8b0:400c:c03::22f; Received: by mail-vc0-f175.google.com with SMTP id id10so2908030vcb.20 for ; Fri, 23 May 2014 07:14:04 -0700 (PDT) X-Received: by 10.58.186.207 with SMTP id fm15mr4459731vec.4.1400854444307; Fri, 23 May 2014 07:14:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp35014vcb; Fri, 23 May 2014 07:14:03 -0700 (PDT) X-Received: by 10.68.224.198 with SMTP id re6mr6491352pbc.8.1400854443576; Fri, 23 May 2014 07:14:03 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id co3si4056927pad.238.2014.05.23.07.14.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 May 2014 07:14:03 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-return-83812-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 23848 invoked by alias); 23 May 2014 14:13:46 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Subscribe: List-Archive: List-Post: , List-Help: , Sender: binutils-owner@sourceware.org Delivered-To: mailing list binutils@sourceware.org Received: (qmail 23837 invoked by uid 89); 23 May 2014 14:13:45 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f175.google.com Received: from mail-wi0-f175.google.com (HELO mail-wi0-f175.google.com) (209.85.212.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 23 May 2014 14:13:44 +0000 Received: by mail-wi0-f175.google.com with SMTP id f8so915572wiw.8 for ; Fri, 23 May 2014 07:13:41 -0700 (PDT) X-Received: by 10.180.92.69 with SMTP id ck5mr3560109wib.15.1400854421526; Fri, 23 May 2014 07:13:41 -0700 (PDT) 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 o10sm4072023wjy.0.2014.05.23.07.13.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 May 2014 07:13:40 -0700 (PDT) From: Will Newton To: binutils@sourceware.org Subject: [PATCH] ld/ARM: Fix IFUNC and TLS descriptors in the same shared object Date: Fri, 23 May 2014 15:13:36 +0100 Message-Id: <1400854416-3764-1-git-send-email-will.newton@linaro.org> X-IsSubscribed: yes X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22f as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 Combining TLS descriptors and GNU indirect functions in the same object could lead to assertions or multiple dynamic relocations for the same GOT slot. Fix the bookkeeping so this doesn't happen. This allows building and make checking glibc with -mtls-dialect=gnu2. bfd/ChangeLog: 2014-05-21 Will Newton * elf32-arm.c (elf32_arm_allocate_plt_entry): Increment htab->next_tls_desc_index in the non-IPLT case. Calculate GOT offset correctly for the non-IPLT case. (allocate_dynrelocs_for_symbol): Don't increment htab->next_tls_desc_index here. ld/testsuite/ChangeLog: 2014-05-21 Will Newton * ld-arm/arm-elf.exp: Add ifunc-gdesc test. * ld-arm/ifunc-gdesc.r: New file. * ld-arm/ifunc-gdesc.s: Likewise. * ld-arm/ifunc-gdesc.ver: Likewise. --- bfd/elf32-arm.c | 9 ++++++--- ld/testsuite/ld-arm/arm-elf.exp | 3 +++ ld/testsuite/ld-arm/ifunc-gdesc.r | 6 ++++++ ld/testsuite/ld-arm/ifunc-gdesc.s | 29 +++++++++++++++++++++++++++++ ld/testsuite/ld-arm/ifunc-gdesc.ver | 4 ++++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 ld/testsuite/ld-arm/ifunc-gdesc.r create mode 100644 ld/testsuite/ld-arm/ifunc-gdesc.s create mode 100644 ld/testsuite/ld-arm/ifunc-gdesc.ver \ No newline at end of file diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 526d4f8..6a20baf 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -7521,6 +7521,8 @@ elf32_arm_allocate_plt_entry (struct bfd_link_info *info, first entry. */ if (splt->size == 0) splt->size += htab->plt_header_size; + + htab->next_tls_desc_index++; } /* Allocate the PLT entry itself, including any leading Thumb stub. */ @@ -7533,7 +7535,10 @@ elf32_arm_allocate_plt_entry (struct bfd_link_info *info, { /* We also need to make an entry in the .got.plt section, which will be placed in the .got section by the linker script. */ - arm_plt->got_offset = sgotplt->size - 8 * htab->num_tls_desc; + if (is_iplt_entry) + arm_plt->got_offset = sgotplt->size; + else + arm_plt->got_offset = sgotplt->size - 8 * htab->num_tls_desc; sgotplt->size += 4; } } @@ -13359,8 +13364,6 @@ allocate_dynrelocs_for_symbol (struct elf_link_hash_entry *h, void * inf) h->target_internal = ST_BRANCH_TO_ARM; } - htab->next_tls_desc_index++; - /* VxWorks executables have a second set of relocations for each PLT entry. They go in a separate relocation section, which is processed by the kernel loader. */ diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp index c255587..2e7e164 100644 --- a/ld/testsuite/ld-arm/arm-elf.exp +++ b/ld/testsuite/ld-arm/arm-elf.exp @@ -460,6 +460,9 @@ set armelftests_nonacl { "" {long-plt-format.s} {{objdump "-d -j .plt" long-plt-format.d}} "long-plt-format"} + {"IFUNC and TLS descriptor shared library" "-shared -T arm-lib.ld --version-script=ifunc-gdesc.ver" "" "" {ifunc-gdesc.s} + {{objdump "-Rw" ifunc-gdesc.r}} + "ifunc-gdesc.so"} } run_ld_link_tests $armelftests_common diff --git a/ld/testsuite/ld-arm/ifunc-gdesc.r b/ld/testsuite/ld-arm/ifunc-gdesc.r new file mode 100644 index 0000000..a49dd2b --- /dev/null +++ b/ld/testsuite/ld-arm/ifunc-gdesc.r @@ -0,0 +1,6 @@ +tmpdir/ifunc-gdesc.so: file format elf32-(big|little)arm +DYNAMIC RELOCATION RECORDS +OFFSET TYPE VALUE +0000825c R_ARM_IRELATIVE \*ABS\* +00008248 R_ARM_TLS_DESC \*ABS\* +00008250 R_ARM_TLS_DESC \*ABS\* diff --git a/ld/testsuite/ld-arm/ifunc-gdesc.s b/ld/testsuite/ld-arm/ifunc-gdesc.s new file mode 100644 index 0000000..a07a5d5 --- /dev/null +++ b/ld/testsuite/ld-arm/ifunc-gdesc.s @@ -0,0 +1,29 @@ + + .arm + +foo: + bl ifunc1(PLT) + ldr r0,1f +2: bl loc1(tlscall) + nop +1: .word loc1(tlsdesc) + (. - 2b) + + ldr r0,1f +2: bl loc2(tlscall) + nop +1: .word loc2(tlsdesc) + (. - 2b) + + .type ifunc1,%gnu_indirect_function + .global ifunc1 +ifunc1: + mov pc,lr + .size ifunc1,.-ifunc1 + + + .section .tdata,"awT",%progbits + .space 8 + .type loc1, %object +loc1: .space 4 + .type loc2, %object +loc2: .space 4 + diff --git a/ld/testsuite/ld-arm/ifunc-gdesc.ver b/ld/testsuite/ld-arm/ifunc-gdesc.ver new file mode 100644 index 0000000..a82ffc4 --- /dev/null +++ b/ld/testsuite/ld-arm/ifunc-gdesc.ver @@ -0,0 +1,4 @@ +{ +global: foo; +local: *; +};