From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id 2F28F385801D for ; Fri, 10 Dec 2021 22:50:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F28F385801D Received: by mail-qt1-x834.google.com with SMTP id j17so9884870qtx.2 for ; Fri, 10 Dec 2021 14:50:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=nJhk+WWqXbGeQHntNYBB+9THwkbZf1W8UpkfoihDcxk=; b=L/xP1nxTaPK+/BCGkslARJHo6vQQo10sH6JX6siWFBKDGkQnvPkHWwcsdAW4Rvx6Be 5vJqCZEaDxeIE9mD+z2dIC1hPUJSST8pRGr/w7GqXcQHr/lnN9O/l2tooRS0kzfFZRPb RmNYRGUp/D0WJcr76VgTQuqEl1PNo8XvG//ZpTWoLEcL01DAcapowTGrEe8Lyg8ClI+Z RpxM4HFRtS8gARjzkOkM9eSGQ9wKWkcx75304GSYZhjd4b9+Uu5zVBS4yIYi713tuq3D iaEyR9wpzAoKCXgDJfVqhxCoLIYndFDlSIWm3yInWllghlzSnO5epurbLMKyWrD1/JcT 1ZXA== X-Gm-Message-State: AOAM5318UeI0/CUThWxhVFkLHVyFqxnAkc5cOmh33CdwjPrTfCHHrGAn NmoPug/+dntHXiQHM6lrJHKt+jj4EjAllA== X-Google-Smtp-Source: ABdhPJwcpMExiTtPR61jKPprXetfSdQLU3dGphLLyZmIHruH5vQoVi3Ti1+ALZLxO+wIM7Es8RPYyg== X-Received: by 2002:ac8:4e41:: with SMTP id e1mr30139533qtw.116.1639176606593; Fri, 10 Dec 2021 14:50:06 -0800 (PST) Received: from ?IPV6:2804:431:c7ca:a776:ce11:d591:8bd5:613f? ([2804:431:c7ca:a776:ce11:d591:8bd5:613f]) by smtp.gmail.com with ESMTPSA id j21sm1982766qkk.27.2021.12.10.14.50.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Dec 2021 14:50:06 -0800 (PST) Message-ID: Date: Fri, 10 Dec 2021 19:50:04 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH] Check alignment of PT_LOAD segment only if possible Content-Language: en-US To: "H.J. Lu" Cc: GNU C Library References: <20211210205922.2865613-1-hjl.tools@gmail.com> From: Adhemerval Zanella In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2021 22:50:10 -0000 On 10/12/2021 18:54, H.J. Lu wrote: > On Fri, Dec 10, 2021 at 1:36 PM Adhemerval Zanella > wrote: >> >> >> >> On 10/12/2021 17:59, H.J. Lu wrote: >>> Add a configure check for 2MB variable alignment and check alignment of >>> PT_LOAD segment only if 2MB variable alignment is supported. >>> >>> Tested with cross build to glibcs-alpha-linux-gnu. >>> --- >>> configure | 40 +++++++++++++++++++++++++++++++++++++++- >>> configure.ac | 11 +++++++++++ >>> elf/Makefile | 15 ++++++++++----- >>> 3 files changed, 60 insertions(+), 6 deletions(-) >>> >>> diff --git a/configure b/configure >>> index e4d013907c..9da30f428f 100755 >>> --- a/configure >>> +++ b/configure >>> @@ -732,6 +732,7 @@ infodir >>> docdir >>> oldincludedir >>> includedir >>> +runstatedir >>> localstatedir >>> sharedstatedir >>> sysconfdir >>> @@ -845,6 +846,7 @@ datadir='${datarootdir}' >>> sysconfdir='${prefix}/etc' >>> sharedstatedir='${prefix}/com' >>> localstatedir='${prefix}/var' >>> +runstatedir='${localstatedir}/run' >>> includedir='${prefix}/include' >>> oldincludedir='/usr/include' >>> docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' >>> @@ -1097,6 +1099,15 @@ do >>> | -silent | --silent | --silen | --sile | --sil) >>> silent=yes ;; >>> >>> + -runstatedir | --runstatedir | --runstatedi | --runstated \ >>> + | --runstate | --runstat | --runsta | --runst | --runs \ >>> + | --run | --ru | --r) >>> + ac_prev=runstatedir ;; >>> + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ >>> + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ >>> + | --run=* | --ru=* | --r=*) >>> + runstatedir=$ac_optarg ;; >>> + >>> -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) >>> ac_prev=sbindir ;; >>> -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ >> >> Please use a non patched autoconf (usually debian based one adds the runstatedir). > > Fixed. > >>> @@ -1234,7 +1245,7 @@ fi >>> for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ >>> datadir sysconfdir sharedstatedir localstatedir includedir \ >>> oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ >>> - libdir localedir mandir >>> + libdir localedir mandir runstatedir >>> do >>> eval ac_val=\$$ac_var >>> # Remove trailing slashes. >>> @@ -1387,6 +1398,7 @@ Fine tuning of the installation directories: >>> --sysconfdir=DIR read-only single-machine data [PREFIX/etc] >>> --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] >>> --localstatedir=DIR modifiable single-machine data [PREFIX/var] >>> + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] >>> --libdir=DIR object code libraries [EPREFIX/lib] >>> --includedir=DIR C header files [PREFIX/include] >>> --oldincludedir=DIR C header files for non-gcc [/usr/include] >>> @@ -6817,6 +6829,32 @@ if test $libc_cv_builtin_trap = yes; then >>> >>> fi >>> >>> +# Check target support for 2MB variable alignment. >>> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for 2MB variable alignment" >&5 >>> +$as_echo_n "checking for 2MB variable alignment... " >&6; } >>> +if ${libc_cv_have_2MB_alignment+:} false; then : >>> + $as_echo_n "(cached) " >&6 >>> +else >>> + >>> +cat confdefs.h - <<_ACEOF >conftest.$ac_ext >>> +/* end confdefs.h. */ >>> + >>> +int foo __attribute__((aligned(0x200000))) = 1; >>> + >>> +_ACEOF >>> +if ac_fn_c_try_compile "$LINENO"; then : >>> + libc_cv_have_2MB_alignment=yes >>> +else >>> + libc_cv_have_2MB_alignment=no >>> +fi >>> +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext >>> + >>> +fi >>> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_have_2MB_alignment" >&5 >>> +$as_echo "$libc_cv_have_2MB_alignment" >&6; } >>> +config_vars="$config_vars >>> +have-2MB-alignment = $libc_cv_have_2MB_alignment" >>> + >>> ac_ext=cpp >>> ac_cpp='$CXXCPP $CPPFLAGS' >>> ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' >>> diff --git a/configure.ac b/configure.ac >>> index a91a7f399c..57d4572c26 100644 >>> --- a/configure.ac >>> +++ b/configure.ac >>> @@ -1726,6 +1726,17 @@ if test $libc_cv_builtin_trap = yes; then >>> AC_DEFINE([HAVE_BUILTIN_TRAP]) >>> fi >>> >>> +# Check target support for 2MB variable alignment. >>> +AC_CACHE_CHECK([for 2MB variable alignment], >>> + libc_cv_have_2MB_alignment, [ >>> +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ >>> +int foo __attribute__((aligned(0x200000))) = 1; >>> +])], >>> + [libc_cv_have_2MB_alignment=yes], >>> + [libc_cv_have_2MB_alignment=no]) >>> +]) >>> +LIBC_CONFIG_VAR([have-2MB-alignment], [$libc_cv_have_2MB_alignment]) >>> + >>> dnl C++ feature tests. >>> AC_LANG_PUSH([C++]) >>> >> >> Would be better to check 2 times the maximum supported pagesize instead? > > Why 2 times? The test only uses 2MB alignment. The implementation > self doesn't depend on the maximum supported page size. The limit > is available free address space. It is an arbitrary value larger than the pagesize to make the test check for it even on architecture that do no support 2MB alignment.