From patchwork Tue Sep 6 13:44:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1674860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=P+lQ1W+T; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MMRTm5QX8z1yh5 for ; Tue, 6 Sep 2022 23:45:16 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id BA49131E04DB; Tue, 6 Sep 2022 15:45:06 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=P+lQ1W+T; dkim-atps=neutral Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by helium.openadk.org (Postfix) with ESMTPS id F015231E0304 for ; Tue, 6 Sep 2022 15:45:01 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id 65so1182936pfx.0 for ; Tue, 06 Sep 2022 06:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=faI7AjwJZPO4mycqd+WEo1Sb8xQR3CFxXkKBCWA8F/o=; b=P+lQ1W+TFdVUoteuSJDc0K1dd+fDfzctQWzsIMmVkEhuJuFiUUDmxMvOUaXhVIJCA6 R2EkGNjQ0/jcRsyBw8dZAMSBOAKz/0gPTTTrwUFYK04vjozDc6GvdE72L7OraPIy1cGA PAHPtQRJLtyhmqc57wG5GJsySY7AIA2sPmH16zJwlmIPUG8F9AgE7h3Y4mR+83pje9cr Y28CHPJXBkrqTUqKp5Volne74xInuZlXuLafqiiyYG7mauV24DPj4giRVIMS6i4sO48s cTNDkLc/ep5X1DxI/rbINyRzZPJIJXJFNbDWVM9suL14RUm+U7gpt6B1Q9Gn2Mbh3MGu 1HyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=faI7AjwJZPO4mycqd+WEo1Sb8xQR3CFxXkKBCWA8F/o=; b=2PqexJ1EV0VexoLdUsQNKQUhSw7zOWBbV0ECyLcQS3D8tvQ5K2LZnRpSjy+dkYDjpu O8Wb7e2LzO2vNHcGTSXCMO5c75YGnu/wOLes99EeWpalUoS4WFyNpxXggVraKhdnSh6v kdl0oWKK9jtm9WU9t5FcHIJ6KjAba227KP8LBCIAqL6azaPIzt9ka/Z47yxxJURvZ+VN WVi1CpH9YZutM32MpJRW5K3mDVLhs/Y14JFeXNy2vWYxqzjJoly7hNei+5k+0Kf25NzQ P1gotp/BxXsVgulRppvZwgjPTW/bOxqGVC9EhXW1vRjbNGOnjYVFr7tJVpA74qjJXIsQ jHmA== X-Gm-Message-State: ACgBeo23BvIv3LpvIaOCSF9tBBSAs9LAzZ6kGSPXaGwiGrNa30B5GzeQ 5HQVi2nr6kuZoVwFOHHACmJRR8+AxfbIow== X-Google-Smtp-Source: AA6agR5eNn1Yrx65FDeF0MTfuGbeP1CAVeOrBfXDHnMK4i991KoaRAW4eNTqQEH6Nz9rwLlldbUTQg== X-Received: by 2002:a63:170d:0:b0:415:f76d:45e1 with SMTP id x13-20020a63170d000000b00415f76d45e1mr46098928pgl.171.1662471899768; Tue, 06 Sep 2022 06:44:59 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id t66-20020a625f45000000b00537ff911a89sm10290711pfb.105.2022.09.06.06.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 06:44:59 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Tue, 6 Sep 2022 06:44:44 -0700 Message-Id: <20220906134444.1970426-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Message-ID-Hash: P2EA6VFQVRGERF6WUP3MESHC2RFSMRFV X-Message-ID-Hash: P2EA6VFQVRGERF6WUP3MESHC2RFSMRFV X-MailFrom: jcmvbkbc@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linted X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH v2] nptl: use mmap to allocate initial TLS data for static PIE on noMMU List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Static PIE ELFs may be loaded on noMMU linux platforms with FDPIC support, but they don't have adjustable brk, and thus cannot allocate memory for the TLS. Use mmap instead of sbrk to allocate initial TLS memory when building with static PIE support for noMMU. Signed-off-by: Max Filippov --- Change v1->v2: - fix typo and add clarification in comment libpthread/nptl/sysdeps/generic/libc-tls.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libpthread/nptl/sysdeps/generic/libc-tls.c b/libpthread/nptl/sysdeps/generic/libc-tls.c index d9c09fdd6667..7cfe9ac1a85c 100644 --- a/libpthread/nptl/sysdeps/generic/libc-tls.c +++ b/libpthread/nptl/sysdeps/generic/libc-tls.c @@ -169,10 +169,13 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) for FDPIC MMU-less platforms: fs/binfmt_elf_fdpic.c: fix brk area overlap with stack on NOMMU https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/binfmt_elf_fdpic.c?id=4ac313111018cb44ecc250445de5ccb93026a980 + Loading static PIE ELFs on noMMU is possible since the linux kernel commit + 1bde925d2354 ("fs/binfmt_elf_fdpic.c: provide NOMMU loader for regular ELF binaries") + and it is subject to the same brk restriction. */ # if defined(TLS_TCB_AT_TP) tcb_offset = roundup (memsz + GL(dl_tls_static_size), tcbalign); -# if defined(__FDPIC__) +# if defined(__FDPIC__) || (!defined(__ARCH_USE_MMU__) && defined(STATIC_PIE)) tlsblock = mmap (NULL, tcb_offset + tcbsize + max_align, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); # else @@ -180,7 +183,7 @@ __libc_setup_tls (size_t tcbsize, size_t tcbalign) # endif # elif defined(TLS_DTV_AT_TP) tcb_offset = roundup (tcbsize, align ?: 1); -# if defined(__FDPIC__) +# if defined(__FDPIC__) || (!defined(__ARCH_USE_MMU__) && defined(STATIC_PIE)) tlsblock = mmap (NULL, tcb_offset + memsz + max_align + TLS_PRE_TCB_SIZE + GL(dl_tls_static_size), PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); # else