From patchwork Tue Feb 27 17:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1905347 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=TipJnt3u; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tkkdr06hbz23qP for ; Wed, 28 Feb 2024 04:15:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC2753858D28 for ; Tue, 27 Feb 2024 17:15:41 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id C73C53858D20 for ; Tue, 27 Feb 2024 17:15:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C73C53858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C73C53858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709054125; cv=none; b=CxrURntSbSAtAjWB8fdnynsYVVxsQZXYjhbBfZQ1HB9qO2yaaiU4870SphBUTqu0S7MB5sTteUUq0ysr5gMteFL1qhgY5V2DxIn1pmUOlfpz4HQ8jNzDmcSBJEAlADegUW2A8wHrykTil9jsg6GQxf+AjElXJQXp10JtAH65Auw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709054125; c=relaxed/simple; bh=dIqDFz/5VPJIKGF0+Gidkqyvy27PS8/Gu8eUQxYPsA4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=m84nGHhQZbNb3T+3LA88Nel6wfqiIeJC9R0qT++DwOagr25840hh/jj0fuUomcMV5bnC51HXGmm6UjpWYaoQUeo+ZycxqjANlsjRjVooHCvti7kw+gDYjpXHblNtg2NLuUrdsobLOVB0QAYFWBENYDGNgeuG/R0qNHv/xokUfP8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dc75972f25so38348405ad.1 for ; Tue, 27 Feb 2024 09:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709054120; x=1709658920; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nTeczQt0YV5PJJM4dL6jxYVpo3h1ACjvymaSqraGl3Q=; b=TipJnt3u5i9rak5U0V5sIa6X5TzXVC59N4wAMiIvwt/RhiVL8xqz+lKL8dANSTMiOe uiTgvoVmcqbrZjjVWJitx3GFL1ol7plL0BV/rtVTbixnpE7dR3QYhErdKRv9S068shQ/ 9fiOkqa9UC3HWKwGiwGG5cYo/YJUiZDCeLRuqoEGBvt4gTHG8NMMZEXtUUsUnyWl/nuo SLc67HC9WyNeu7NwmQW7N04r1rdsId/HgaSmqm2T8NBvTX5oJMOzf7GzTod6afN/m/cZ PMcYRTLt/uiQNFpcTz9Q+Zj2bWb0XpRjyWaW+p4T/2CDZWtwhPUt/c8uKIbDoiqUQfc2 P41A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709054120; x=1709658920; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nTeczQt0YV5PJJM4dL6jxYVpo3h1ACjvymaSqraGl3Q=; b=EUUX/nOFfutoYlFSDQR3NV9ssTgN06SBdtL0VvPwcN+PVb6yZ8T5GEVXsbcIOwpdun SiKfm5IB5NKWqf24zZNgpm6SfYq1vfSWKnOh6JDuJoenQcZlP7dsLm1F0nLxbbqfNgNH Kb4XrptX9n2JQJaFxStsjJsxHVg3o8wTOGW+hTuZAzAWynFM+6xTP4eMLrHoXX2mDilj ZjmFO+IBFMKKwWBtKmVfXi+t91XIR+r9GV1r5cKYk0BdDm0YXNRfitcarz2avfdcf4bt s/fsOR+S4xqGnVA8kxAEjMIPTcpHovHXwhSLgbUwtD7q7qHSpmmREEk/hcOhBDNUS4Ae /Ujg== X-Gm-Message-State: AOJu0YzNvlnfv60nCHnIEi/yZSn8YPVDbu8eOk6thucnoiW+GUjvApk1 5/XEtlsGQ5D9getBa3bQeegFdolYbuOusMQcmS2+v3oSnBeiqe0AhAKWE8A451acp/ATddZQId+ E X-Google-Smtp-Source: AGHT+IG+0MJy7X/zs4i15suJyJ/D93uXIgOCBGWL+OtrhV/3kKUxwYfMiTiWOkWn0qarPnLW8R7p2w== X-Received: by 2002:a17:903:1250:b0:1db:cea0:9d62 with SMTP id u16-20020a170903125000b001dbcea09d62mr11460471plh.9.1709054119542; Tue, 27 Feb 2024 09:15:19 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:3a1a:4afd:44bc:8c5a:b839]) by smtp.gmail.com with ESMTPSA id g24-20020a170902fe1800b001db3bffd1a8sm1767093plj.42.2024.02.27.09.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 09:15:18 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Stefan Liebler Subject: [PATCH] s390: Improve static-pie configure tests Date: Tue, 27 Feb 2024 14:14:55 -0300 Message-Id: <20240227171455.468028-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Instead of tying based on the linker name and version, check for the required support: * whether it does not generate dynamic TLS relocations in PIE (binutils PR ld/22263); * if it accepts --no-dynamic-linker (by using -static-pie); * and if it adds a DT_JMPREL pointing to .rela.iplt with static pie. The patch also trims the comments, for binutils one of the tests should already cover it. The kernel ones are not clear which version should have the backport, nor it is something that glibc can do much about it. Finally, the glibc is somewhat confusing, since it refers to commits not related to s390x. Checked with a build for s390x-linux-gnu. Reviewed-by: Stefan Liebler --- sysdeps/s390/s390-64/configure | 170 ++++-------------------------- sysdeps/s390/s390-64/configure.ac | 101 ++++-------------- 2 files changed, 40 insertions(+), 231 deletions(-) diff --git a/sysdeps/s390/s390-64/configure b/sysdeps/s390/s390-64/configure index 824ae9c129..e5824b98da 100644 --- a/sysdeps/s390/s390-64/configure +++ b/sysdeps/s390/s390-64/configure @@ -1,100 +1,6 @@ # This file is generated from configure.ac by Autoconf. DO NOT EDIT! # Local configure fragment for sysdeps/s390/s390-64. -# Bypass result of runtime configure check for known linker versions as -# e.g. crt-files or libc.so might not be available in bootstrapping -# environments. -case $($LD --version) in - "GNU gold"*) - # As of 2023-08-07, gold does not support static PIE due to - # Bug 22221 - add --no-dynamic-linker option - # https://sourceware.org/bugzilla/show_bug.cgi?id=22221 - libc_cv_s390x_staticpie_req_version=no - ;; - "LLD"*) - # As of 2023-08-07, there is no lld which supports s390x. - libc_cv_s390x_staticpie_req_version=no - ;; - *) - # The required binutils patches are available with bintuils 2.39 - libc_cv_s390x_staticpie_req_version=yes - # Skip AC_CHECK_PROGS and just use the result from main configure.ac. - libc_cv_s390x_staticpie_req_LD=$LD - for ac_prog in $LD -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_libc_cv_s390x_staticpie_req_LD+y} -then : - printf %s "(cached) " >&6 -else $as_nop - if test -n "$libc_cv_s390x_staticpie_req_LD"; then - ac_cv_prog_libc_cv_s390x_staticpie_req_LD="$libc_cv_s390x_staticpie_req_LD" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then - ac_cv_prog_libc_cv_s390x_staticpie_req_LD="$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -libc_cv_s390x_staticpie_req_LD=$ac_cv_prog_libc_cv_s390x_staticpie_req_LD -if test -n "$libc_cv_s390x_staticpie_req_LD"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_s390x_staticpie_req_LD" >&5 -printf "%s\n" "$libc_cv_s390x_staticpie_req_LD" >&6; } -else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } -fi - - - test -n "$libc_cv_s390x_staticpie_req_LD" && break -done - -if test -z "$libc_cv_s390x_staticpie_req_LD"; then - ac_verc_fail=yes -else - # Found it, now check the version. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking version of $libc_cv_s390x_staticpie_req_LD" >&5 -printf %s "checking version of $libc_cv_s390x_staticpie_req_LD... " >&6; } - ac_prog_version=`$libc_cv_s390x_staticpie_req_LD --version 2>&1 | sed -n 's/^.*GNU ld.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'` - case $ac_prog_version in - '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; - 2.1[0-9][0-9]*|2.39*|2.[4-9][0-9]*|[3-9].*|[1-9][0-9]*) - ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; - *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; - - esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5 -printf "%s\n" "$ac_prog_version" >&6; } -fi -if test $ac_verc_fail = yes; then - libc_cv_s390x_staticpie_req_version=no -fi - - ;; -esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for s390-specific static PIE requirements (version check)" >&5 -printf %s "checking for s390-specific static PIE requirements (version check)... " >&6; } -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_s390x_staticpie_req_version" >&5 -printf "%s\n" "$libc_cv_s390x_staticpie_req_version" >&6; } - # Minimal checking for static PIE support in ld. # Compare to ld testcase/bugzilla: # /ld/testsuite/ld-elf/pr22263-1.rd @@ -113,20 +19,31 @@ bar (void) { *foo = 1; } + +void bar2 (void); +void* bar2_ifunc (void) __asm__ ("bar2"); +__asm__ (".type bar2, %gnu_indirect_function"); +void* bar2_ifunc (void) { return 0; } EOF cat > conftest2.c <&5 (eval $ac_try) 2>&5 @@ -139,7 +56,7 @@ EOF ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } \ - && { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -o conftest conftest1.o conftest2.o' + && { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostartfiles -nostdlib -fPIE -o conftest conftest1.o conftest2.o' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -150,6 +67,12 @@ EOF (eval $ac_try) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } \ + && { ac_try='LC_ACLL=C $READELF -d conftest | grep JMPREL' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } then libc_cv_s390x_staticpie_req_runtime=yes @@ -161,59 +84,10 @@ libc_cv_s390x_staticpie_req_runtime { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } -if test $libc_cv_s390x_staticpie_req_runtime = yes \ - || test $libc_cv_s390x_staticpie_req_version = yes; then - # Static PIE is supported only on 64bit. - # Ensure you also have those patches for: - # - binutils (ld) - # - "[PR ld/22263] s390: Avoid dynamic TLS relocs in PIE" - # https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=26b1426577b5dcb32d149c64cca3e603b81948a9 - # (Tested by configure check above) - # Otherwise there will be a R_390_TLS_TPOFF relocation, which fails to - # be processed in _dl_relocate_static_pie() as static TLS map is not setup. - # - "s390: Add DT_JMPREL pointing to .rela.[i]plt with static-pie" - # https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d942d8db12adf4c9e5c7d9ed6496a779ece7149e - # (We can't test it in configure as we are not able to link a static PIE - # executable if the system glibc lacks static PIE support) - # Otherwise there won't be DT_JMPREL, DT_PLTRELA, DT_PLTRELASZ entries - # and the IFUNC symbols are not processed, which leads to crashes. - # - # - kernel (the mentioned links to the commits belong to 5.19 merge window): - # - "s390/mmap: increase stack/mmap gap to 128MB" - # https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=f2f47d0ef72c30622e62471903ea19446ea79ee2 - # - "s390/vdso: move vdso mapping to its own function" - # https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=57761da4dc5cd60bed2c81ba0edb7495c3c740b8 - # - "s390/vdso: map vdso above stack" - # https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=9e37a2e8546f9e48ea76c839116fa5174d14e033 - # - "s390/vdso: add vdso randomization" - # https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=41cd81abafdc4e58a93fcb677712a76885e3ca25 - # (We can't test the kernel of the target system) - # Otherwise if /proc/sys/kernel/randomize_va_space is turned off (0), - # static PIE executables like ldconfig will crash. While startup sbrk is - # used to enlarge the HEAP. Unfortunately the underlying brk syscall fails - # as there is not enough space after the HEAP. Then the address of the TLS - # image is invalid and the following memcpy in __libc_setup_tls() leads - # to a segfault. - # If /proc/sys/kernel/randomize_va_space is activated (default: 2), there - # is enough space after HEAP. - # - # - glibc - # - "Linux: Define MMAP_CALL_INTERNAL" - # https://sourceware.org/git/?p=glibc.git;a=commit;h=c1b68685d438373efe64e5f076f4215723004dfb - # - "i386: Remove OPTIMIZE_FOR_GCC_5 from Linux libc-do-syscall.S" - # https://sourceware.org/git/?p=glibc.git;a=commit;h=6e5c7a1e262961adb52443ab91bd2c9b72316402 - # - "i386: Honor I386_USE_SYSENTER for 6-argument Linux system calls" - # https://sourceware.org/git/?p=glibc.git;a=commit;h=60f0f2130d30cfd008ca39743027f1e200592dff - # - "ia64: Always define IA64_USE_NEW_STUB as a flag macro" - # https://sourceware.org/git/?p=glibc.git;a=commit;h=18bd9c3d3b1b6a9182698c85354578d1d58e9d64 - # - "Linux: Implement a useful version of _startup_fatal" - # https://sourceware.org/git/?p=glibc.git;a=commit;h=a2a6bce7d7e52c1c34369a7da62c501cc350bc31 - # - "Linux: Introduce __brk_call for invoking the brk system call" - # https://sourceware.org/git/?p=glibc.git;a=commit;h=b57ab258c1140bc45464b4b9908713e3e0ee35aa - # - "csu: Implement and use _dl_early_allocate during static startup" - # https://sourceware.org/git/?p=glibc.git;a=commit;h=f787e138aa0bf677bf74fa2a08595c446292f3d7 - # The mentioned patch series by Florian Weimer avoids the mentioned failing - # sbrk syscall by falling back to mmap. +if test $libc_cv_s390x_staticpie_req_runtime = yes; then + # Some kernels might fail with /proc/sys/kernel/randomize_va_space set to 0 + # due not enough space for a rk call. However, there is no reliable way to + # test it. printf "%s\n" "#define SUPPORT_STATIC_PIE 1" >>confdefs.h fi diff --git a/sysdeps/s390/s390-64/configure.ac b/sysdeps/s390/s390-64/configure.ac index 4657de0d37..565542d526 100644 --- a/sysdeps/s390/s390-64/configure.ac +++ b/sysdeps/s390/s390-64/configure.ac @@ -1,34 +1,6 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. # Local configure fragment for sysdeps/s390/s390-64. -# Bypass result of runtime configure check for known linker versions as -# e.g. crt-files or libc.so might not be available in bootstrapping -# environments. -case $($LD --version) in - "GNU gold"*) - # As of 2023-08-07, gold does not support static PIE due to - # Bug 22221 - add --no-dynamic-linker option - # https://sourceware.org/bugzilla/show_bug.cgi?id=22221 - libc_cv_s390x_staticpie_req_version=no - ;; - "LLD"*) - # As of 2023-08-07, there is no lld which supports s390x. - libc_cv_s390x_staticpie_req_version=no - ;; - *) - # The required binutils patches are available with bintuils 2.39 - libc_cv_s390x_staticpie_req_version=yes - # Skip AC_CHECK_PROGS and just use the result from main configure.ac. - libc_cv_s390x_staticpie_req_LD=$LD - AC_CHECK_PROG_VER(libc_cv_s390x_staticpie_req_LD, $LD, --version, - [GNU ld.* \([0-9][0-9]*\.[0-9.]*\)], - [2.1[0-9][0-9]*|2.39*|2.[4-9][0-9]*|[3-9].*|[1-9][0-9]*], - libc_cv_s390x_staticpie_req_version=no) - ;; -esac -AC_MSG_CHECKING([for s390-specific static PIE requirements (version check)]) -AC_MSG_RESULT($libc_cv_s390x_staticpie_req_version) - # Minimal checking for static PIE support in ld. # Compare to ld testcase/bugzilla: # /ld/testsuite/ld-elf/pr22263-1.rd @@ -42,81 +14,44 @@ bar (void) { *foo = 1; } + +void bar2 (void); +void* bar2_ifunc (void) __asm__ ("bar2"); +__asm__ (".type bar2, %gnu_indirect_function"); +void* bar2_ifunc (void) { return 0; } EOF cat > conftest2.c <