From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 70D7F3858D32 for ; Tue, 2 Jan 2024 18:30:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70D7F3858D32 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 70D7F3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704220261; cv=none; b=ZB7gwcBs6yci+BOtPB70U6FQNAX2X4e1wPwdMfT+OOKaslBfm+ilkVWxWwqTd/2mOtdMcDfoA4ZedRBnIpQPulXbf9hdHnBj3CJiNH60l9VqEUua88v41E4KEF1HkbLJpFPZn/h5oHfXnlT5Svrltr2JOiwtorHEhci0aS0HJ6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704220261; c=relaxed/simple; bh=qecDgF7BnKFZ2IYKoKd3EvOWKGWwZ0TnEpxjxmyTkZU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=bjsCiY5HONQ0TL3UlQORVNNc50PsziliDi73mFUmZvO1LtPKs8aVOZSFW9uXBiIcPhDP50BSUe3XxM9PShacS2Ps1eWXAWzkkTzTn30HOahd4hKlh3HDQOcfUq3yP4Ct6NUGBGAFuX+GcnANdYmVTEXjg2o4bqoa6O6TW8cr2U4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1d43df785c2so21612295ad.1 for ; Tue, 02 Jan 2024 10:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704220258; x=1704825058; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=GkRFdRjrr1iTXRblbQcqbClqZqyVDh+SzvyIMOBDcFw=; b=VnRJpwoGwrgnbFT5vV4jO0nQgYTzyafMr/zWzu8I4JHEAS6GJ4k/7Y+cCEaen64vVA mEzdy553NCGFMMpyD4Zr9xmUG0w3tSApmvK8ffgReOko3dbLoQbf+Q8UMNofCiV93rE8 H+T5QBq0dUYTFWgClRD3F+4PlpTQCjP8hge5RCCoJ1KRz7HYmLVIUoavhsuZjmKxT0+F kexCyE3Y7XKXeDWQMaLKn7ErSZuF15yUI/up8XDMMo6US/lcIvLhkWlqa3PoWMUTAIEQ FKKraMrWRmyZbkN1VHUpRiCQPjGc1jZr7PHZtxKlOPChxYjnwQLo4pIoSBXc6VmltRSI gI4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704220258; x=1704825058; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GkRFdRjrr1iTXRblbQcqbClqZqyVDh+SzvyIMOBDcFw=; b=uu3P6k0jHKMGpZs2/McA7cIRva0n0aU2L+eRiZRW79ocTn+Zs/kr7Sjwdqur7L4IvZ dovG6NMAvdCV1jK3JN6QyHzgUES2+Vn8bAf9GtienzopM/krb/sAGxXZJy7nbDfKRJWu CTNDoYyj6yLvI+KZ1d1+InPhjXU2Rb89402gRvwwYBZs5R4h6vbMbTHbCKMiJxC6E2KU 30IxZzlgbVrGrCso9srtd5mvHlpRJRyEY4XHcPKnpZ/a91LkoclmnKuX7Ii5IBVKnL+i QG6xGZxzNyEv0zs4u7t0ZJ08esdlCawgefntds2G7ckQExbAiqmWUelJIctQhFS7M3nU Jskw== X-Gm-Message-State: AOJu0YwSUdYRw3Lh4rTy5P4qJ30BA3khU3lDAQW/GwslhjE2ntCa5uCE ts9EQyu6j6NrJ08mZDUW+Fu7uGWGYtI5xA== X-Google-Smtp-Source: AGHT+IFXwbpLuap3vO3M+UAt/ppSrUz2qdd/m4z22XbkUfi87mdgx86MF90E1hK62isJqIQ7n4Lk8A== X-Received: by 2002:a17:903:184:b0:1d0:c986:8ac9 with SMTP id z4-20020a170903018400b001d0c9868ac9mr9810747plg.22.1704220258339; Tue, 02 Jan 2024 10:30:58 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c1:bd9:448f:81bb:20fa:7543? ([2804:1b3:a7c1:bd9:448f:81bb:20fa:7543]) by smtp.gmail.com with ESMTPSA id z16-20020a170903019000b001d3bf27000csm22214517plg.293.2024.01.02.10.30.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Jan 2024 10:30:57 -0800 (PST) Message-ID: Date: Tue, 2 Jan 2024 15:30:54 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] RISC-V: Enable static-pie. Content-Language: en-US To: yanzhang.wang@intel.com, libc-alpha@sourceware.org References: <20230810233348.1214955-1-yanzhang.wang@intel.com> <20240102105415.516313-1-yanzhang.wang@intel.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20240102105415.516313-1-yanzhang.wang@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 02/01/24 07:54, yanzhang.wang@intel.com wrote: > From: Yanzhang Wang > > This patch referents the commit 374cef3 to add static-pie support. And > because the dummy link map is used when relocating ourselves, so need > not to set __global_pointer$ at this time. > > It will also check whether toolchain supports to build static-pie. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > sysdeps/riscv/configure | 49 ++++++++++++++++++++++++++++++++++++++ > sysdeps/riscv/configure.ac | 27 +++++++++++++++++++++ > sysdeps/riscv/dl-machine.h | 2 +- > 3 files changed, 77 insertions(+), 1 deletion(-) > > diff --git a/sysdeps/riscv/configure b/sysdeps/riscv/configure > index acd1f5e743..c8f01709f8 100644 > --- a/sysdeps/riscv/configure > +++ b/sysdeps/riscv/configure > @@ -31,3 +31,52 @@ printf "%s\n" "$libc_cv_riscv_r_align" >&6; } > config_vars="$config_vars > riscv-r-align = $libc_cv_riscv_r_align" > > +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the toolchain is sufficient to build static PIE on RISC-V" >&5 > +printf %s "checking if the toolchain is sufficient to build static PIE on RISC-V... " >&6; } > +if test ${libc_cv_static_pie_on_riscv+y} > +then : > + printf %s "(cached) " >&6 > +else $as_nop > + > + cat > conftest1.S <<\EOF > + .globl _start > + .type _start, @function > +_start: > + nop > + > + .data > + /* This should produce an R_RISCV_RELATIVE in the static PIE. */ > + .dword _start > +EOF > + > + libc_cv_static_pie_on_riscv=no > + if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest1 conftest1.S' > + { { 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; }; } \ > + && { ac_try='LC_ALL=C $READELF -Wr conftest1 | grep -q R_RISCV_RELATIVE' > + { { 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; }; } \ > + && ! { ac_try='LC_ALL=C $READELF -Wl conftest1 | grep -q INTERP' > + { { 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_static_pie_on_riscv=yes > + fi > + rm -rf conftest* > +fi > +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie_on_riscv" >&5 > +printf "%s\n" "$libc_cv_static_pie_on_riscv" >&6; } > + > +if test "$libc_cv_static_pie_on_riscv" = yes; then > + printf "%s\n" "#define SUPPORT_STATIC_PIE 1" >>confdefs.h > + > +fi > diff --git a/sysdeps/riscv/configure.ac b/sysdeps/riscv/configure.ac > index dbcc216689..ee3d1ed014 100644 > --- a/sysdeps/riscv/configure.ac > +++ b/sysdeps/riscv/configure.ac > @@ -16,3 +16,30 @@ EOF > fi > rm -rf conftest.*]) > LIBC_CONFIG_VAR([riscv-r-align], [$libc_cv_riscv_r_align]) > + > +dnl Test if the toolchain is new enough for static PIE. > +AC_CACHE_CHECK([if the toolchain is sufficient to build static PIE on RISC-V], > +libc_cv_static_pie_on_riscv, [ > + cat > conftest1.S <<\EOF > + .globl _start > + .type _start, @function > +_start: > + nop > + > + .data > + /* This should produce an R_RISCV_RELATIVE in the static PIE. */ > + .dword _start > +EOF > + > + libc_cv_static_pie_on_riscv=no > + if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest1 conftest1.S]) \ > + && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest1 | grep -q R_RISCV_RELATIVE]) \ > + && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest1 | grep -q INTERP]) > + then > + libc_cv_static_pie_on_riscv=yes > + fi > + rm -rf conftest* ]) > + > +if test "$libc_cv_static_pie_on_riscv" = yes; then > + AC_DEFINE(SUPPORT_STATIC_PIE) > +fi > diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h > index ffb8c4aaa0..0cbb476c05 100644 > --- a/sysdeps/riscv/dl-machine.h > +++ b/sysdeps/riscv/dl-machine.h > @@ -348,7 +348,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], > gotplt[1] = (ElfW(Addr)) l; > } > > - if (l->l_type == lt_executable) > + if (l->l_type == lt_executable && l->l_scope != NULL) > { > /* The __global_pointer$ may not be defined by the linker if the > $gp register does not be used to access the global variable