From patchwork Tue Jun 3 17:50:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle McMartin X-Patchwork-Id: 31332 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f199.google.com (mail-ig0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E5E4E203AC for ; Tue, 3 Jun 2014 17:50:57 +0000 (UTC) Received: by mail-ig0-f199.google.com with SMTP id c1sf17172013igq.2 for ; Tue, 03 Jun 2014 10:50:57 -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=p+utbT+485dZXPZtzwCqcgEz7mv6/hY38WSPYQwAp8M=; b=jdUBo4v0E1v7P/4AjePH4nBNWI3H+8uKxj0ZSOt9YLpgXz0GW5NRjldWhoevA17oh9 KW5hdzmedPiX5W0aH2lcip9bSD/v9cbV3DptYr7kQHHP+L6KepP7LcJG6/CWao2/9f7l T0vnrtnoLr8/Ig2VWwATR5fw2YH+AFmWlabtqfWIVmCLJUsbvhVF81Wu5pt1cqvxrZqb fHT2Ba8FSr5FKDJojShrkgC7pJdq7YxgLf6GeDwe63iqVkpBql7FudmBJNPlRJVvcCTC +n0lT5j2P3ENyCAu7U2pwl6tvYlujCaUwEIUpyW0i8FTC5GefAdzGwd9uzHWli80cegl YZqA== X-Gm-Message-State: ALoCoQm89r7qlNDTQhbUr50Wi20YXrHiI8gGtt4coXmNa7T1hBs1MOoRd+waqMG4WsFIbmX1tdE7 X-Received: by 10.43.92.195 with SMTP id br3mr15854461icc.1.1401817857128; Tue, 03 Jun 2014 10:50:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.196 with SMTP id l62ls2216891qgl.35.gmail; Tue, 03 Jun 2014 10:50:57 -0700 (PDT) X-Received: by 10.58.100.244 with SMTP id fb20mr9311620veb.39.1401817856944; Tue, 03 Jun 2014 10:50:56 -0700 (PDT) Received: from mail-ve0-x22d.google.com (mail-ve0-x22d.google.com [2607:f8b0:400c:c01::22d]) by mx.google.com with ESMTPS id qg3si10447614veb.84.2014.06.03.10.50.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Jun 2014 10:50:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22d as permitted sender) client-ip=2607:f8b0:400c:c01::22d; Received: by mail-ve0-f173.google.com with SMTP id pa12so7346005veb.4 for ; Tue, 03 Jun 2014 10:50:56 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr38780256vcg.16.1401817856863; Tue, 03 Jun 2014 10:50:56 -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 ib8csp14632vcb; Tue, 3 Jun 2014 10:50:56 -0700 (PDT) X-Received: by 10.68.125.228 with SMTP id mt4mr53182489pbb.55.1401817856136; Tue, 03 Jun 2014 10:50:56 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id sg10si22346353pbb.249.2014.06.03.10.50.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jun 2014 10:50:56 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-50490-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 10720 invoked by alias); 3 Jun 2014 17:50:47 -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 10709 invoked by uid 89); 3 Jun 2014 17:50:46 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 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: Tue, 3 Jun 2014 13:50:42 -0400 From: Kyle McMartin To: libc-alpha@sourceware.org Subject: [PATCHv2] Fix static TLS exhaustion by TLS descriptors Message-ID: <20140603175042.GH15355@redacted.bos.redhat.com> MIME-Version: 1.0 User-Agent: Mutt/1.5.23 (2014-03-12) 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::22d 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 -mtls-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-06-03 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,7 +295,7 @@ 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)) + if (1) { td->arg = _dl_make_tlsdesc_dynamic (sym_map, sym->st_value + reloc->r_addend); diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h index 899b256..f55a991 100644 --- a/sysdeps/arm/dl-machine.h +++ b/sysdeps/arm/dl-machine.h @@ -458,7 +458,7 @@ 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)) + if (1) { td->argument.pointer = _dl_make_tlsdesc_dynamic (sym_map, value); diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 368bee2..b6b5802 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -394,7 +394,7 @@ 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)) + if (1) { td->arg = _dl_make_tlsdesc_dynamic (sym_map, sym->st_value + (ElfW(Word))td->arg); diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 8df04a9..4ec4340 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -359,7 +359,7 @@ 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)) + if (1) { td->arg = _dl_make_tlsdesc_dynamic (sym_map, sym->st_value + reloc->r_addend);