From patchwork Wed May 14 20:32:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle McMartin X-Patchwork-Id: 30198 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B10D120446 for ; Wed, 14 May 2014 20:33:07 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id va2sf497639obc.5 for ; Wed, 14 May 2014 13:33:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-subscribe:list-archive:list-post:list-help :sender:delivered-to:date:from:to:subject:message-id:mime-version :user-agent:x-original-sender:x-original-authentication-results :content-type:content-disposition; bh=2lxQM7UMW422CvP4L641Nd82LRQX5qJfuEXdqqPYRT8=; b=QSiOx9XFaWkiYwi5MnjpcV166LCy/MMmFupFXPA3mHom6obkcIX/45pwu+k0vEwChR PqRI5p0yy3Vx0WwjR0ehlCaAncYkbApPMgdCQ3sF0iD3clsUrRTZDN5pI9A55PTf4lp+ X+mpwKNvSs1sSQupYaNq6WO6uKo26/MPNqg6cgZYyrs4q0UBJkosBJC5X4ZVvJ3Lwzby xfQOdX8KdmJkE4Qe+3483yjKqkh+Cckytlvv38I4T5Ovu6mTjpPgGuLPB69pkDof4nhc 5MIK80vfHkRhfQeAzrJeFvXrlsJ/qFKmGhkkjNFqjgY3lBAKnQmwM+WzzsQJokfZhodT SCFg== X-Gm-Message-State: ALoCoQn0vvpKSbkP8V5e6xNQayKT0i3bzj6P7eMxQ9o46yyoOdJy6BjdvPNeHtdHQcIv/bGP8Tqx X-Received: by 10.43.92.68 with SMTP id bp4mr2550351icc.26.1400099587214; Wed, 14 May 2014 13:33:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.98.52 with SMTP id n49ls2638745qge.29.gmail; Wed, 14 May 2014 13:33:07 -0700 (PDT) X-Received: by 10.52.241.98 with SMTP id wh2mr3871111vdc.37.1400099587060; Wed, 14 May 2014 13:33:07 -0700 (PDT) Received: from mail-ve0-x22a.google.com (mail-ve0-x22a.google.com [2607:f8b0:400c:c01::22a]) by mx.google.com with ESMTPS id xc8si523176vcb.18.2014.05.14.13.33.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 May 2014 13:33:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22a as permitted sender) client-ip=2607:f8b0:400c:c01::22a; Received: by mail-ve0-f170.google.com with SMTP id db11so126121veb.29 for ; Wed, 14 May 2014 13:33:07 -0700 (PDT) X-Received: by 10.58.186.207 with SMTP id fm15mr4633794vec.4.1400099586976; Wed, 14 May 2014 13:33:06 -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 ib8csp269570vcb; Wed, 14 May 2014 13:33:06 -0700 (PDT) X-Received: by 10.69.31.11 with SMTP id ki11mr7071622pbd.88.1400099585688; Wed, 14 May 2014 13:33:05 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ap2si1498110pbc.347.2014.05.14.13.33.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 May 2014 13:33:05 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-49834-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 13992 invoked by alias); 14 May 2014 20:32:57 -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: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 13979 invoked by uid 89); 14 May 2014 20:32:56 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Wed, 14 May 2014 16:32:51 -0400 From: Kyle McMartin To: libc-alpha@sourceware.org Subject: [PATCH] fix static TLS consumption by TLS descriptors Message-ID: <20140514203250.GK26038@redacted.bos.redhat.com> MIME-Version: 1.0 User-Agent: Mutt/1.5.21 (2010-09-15) X-Original-Sender: kmcmarti@redhat.com 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:c01::22a as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 Content-Disposition: inline AArch64 presently defaults to use TLS descriptors, as opposed to traditional dynamic TLS relocations, and has hit a bug in the copy-pasta used in elf_machine_rel{,a} for all TLS descriptor implementations. When a program calls dlopen() with R_AARCH64_TLSDESC relocs, we're consuming static TLS until it's exhausted (presumably as an optimisation.) However, this means that once our static TLS space is consumed, attempting to dlopen() any shared object which contain an R_AARCH64_TPREL reloc will fail, since we've exhausted all the space. Instead, always use dynamic TLS for TLS descriptors, which lets us load arbitrarily many proper dynamic TLS using shared objects, and allow the static TLS fallback only in the non-SHARED case. This issue is reproducible on x86_64, by specifying -ftls-dialect=gnu2 when building with gcc. I've written a test for this: https://github.com/jkkm/test-tls_desc.git Tweak DIALECT to be appropriate, and run ./test-tls_desc.sh, ./main and it should fail with: % ./test-tls_desc.sh; ./main ./tmp16.so: cannot allocate memory in static TLS block ./test-tls_desc.sh: line 18: 10141 Aborted (core dumped) ./main 2014-05-14 Kyle McMartin * sysdeps/aarch64/dl-machine.h (elf_machine_rela): always allocate dynamic TLS space for TLS descriptors. * sysdeps/x86_64/dl-machine.h (elf_machine_rela): ditto. * sysdeps/arm/dl-machine.h (elf_machine_rel): ditto. * sysdeps/i386/dl-machine.h (elf_machine_rel): ditto. --- a/sysdeps/aarch64/dl-machine.h +++ b/sysdeps/aarch64/dl-machine.h @@ -295,13 +295,12 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, # ifndef SHARED CHECK_STATIC_TLS (map, sym_map); # else - if (!TRY_STATIC_TLS (map, sym_map)) { td->arg = _dl_make_tlsdesc_dynamic (sym_map, sym->st_value + reloc->r_addend); td->entry = _dl_tlsdesc_dynamic; } - else + if (0) # endif #endif { diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h index 899b256..dcb2127 100644 --- a/sysdeps/arm/dl-machine.h +++ b/sysdeps/arm/dl-machine.h @@ -458,13 +458,12 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc, # ifndef SHARED CHECK_STATIC_TLS (map, sym_map); # else - if (!TRY_STATIC_TLS (map, sym_map)) { td->argument.pointer = _dl_make_tlsdesc_dynamic (sym_map, value); td->entry = _dl_tlsdesc_dynamic; } - else + if (0) # endif # endif { diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 368bee2..64cf74c 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -394,13 +394,12 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc, # ifndef SHARED CHECK_STATIC_TLS (map, sym_map); # else - if (!TRY_STATIC_TLS (map, sym_map)) { td->arg = _dl_make_tlsdesc_dynamic (sym_map, sym->st_value + (ElfW(Word))td->arg); td->entry = _dl_tlsdesc_dynamic; } - else + if (0) # endif # endif { diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 8df04a9..67e98d1 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -359,13 +359,12 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc, # ifndef SHARED CHECK_STATIC_TLS (map, sym_map); # else - if (!TRY_STATIC_TLS (map, sym_map)) { td->arg = _dl_make_tlsdesc_dynamic (sym_map, sym->st_value + reloc->r_addend); td->entry = _dl_tlsdesc_dynamic; } - else + if (0) # endif # endif {