* [PATCH] Check alignment of PT_LOAD segment only if possible
@ 2021-12-10 20:59 H.J. Lu
2021-12-10 21:36 ` Adhemerval Zanella
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2021-12-10 20:59 UTC (permalink / raw)
To: libc-alpha
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=* \
@@ -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++])
diff --git a/elf/Makefile b/elf/Makefile
index fe42caeb0e..1bf77bc5ac 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -207,7 +207,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
tst-tls4 tst-tls5 \
tst-tls10 tst-tls11 tst-tls12 tst-tls13 tst-tls14 tst-tls15 \
tst-tls16 tst-tls17 tst-tls18 tst-tls19 tst-tls-dlinfo \
- tst-align tst-align2 tst-align3 \
+ tst-align tst-align2 \
tst-dlmodcount tst-dlopenrpath tst-deep1 \
tst-dlmopen1 tst-dlmopen3 tst-dlmopen4 \
unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \
@@ -241,9 +241,6 @@ tests-internal += loadtest unload unload2 circleload1 \
tests-container += tst-pldd tst-dlopen-tlsmodid-container \
tst-dlopen-self-container tst-preload-pthread-libc
test-srcs = tst-pathopt
-ifeq (yes,$(have-fpie))
-tests-pie += tst-align3
-endif
selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
ifneq ($(selinux-enabled),1)
tests-execstack-yes = tst-execstack tst-execstack-needed tst-execstack-prog
@@ -305,7 +302,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
circlemod3 circlemod3a \
reldep8mod1 reldep8mod2 reldep8mod3 \
reldep9mod1 reldep9mod2 reldep9mod3 \
- tst-alignmod tst-alignmod2 tst-alignmod3 \
+ tst-alignmod tst-alignmod2 \
$(modules-execstack-$(have-z-execstack)) \
tst-dlopenrpathmod tst-deep1mod1 tst-deep1mod2 tst-deep1mod3 \
tst-dlmopen1mod tst-auditmod1 \
@@ -418,6 +415,14 @@ endif
modules-execstack-yes = tst-execstack-mod
extra-test-objs += $(addsuffix .os,$(strip $(modules-names)))
+ifeq (yes,$(have-2MB-alignment))
+tests += tst-align3
+modules-names += tst-alignmod3
+ifeq (yes,$(have-fpie))
+tests-pie += tst-align3
+endif
+endif
+
# filtmod1.so, tst-big-note-lib.so, tst-ro-dynamic-mod.so have special
# rules.
modules-names-nobuild := filtmod1 tst-big-note-lib tst-ro-dynamic-mod
--
2.33.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Check alignment of PT_LOAD segment only if possible
2021-12-10 20:59 [PATCH] Check alignment of PT_LOAD segment only if possible H.J. Lu
@ 2021-12-10 21:36 ` Adhemerval Zanella
2021-12-10 21:54 ` H.J. Lu
0 siblings, 1 reply; 4+ messages in thread
From: Adhemerval Zanella @ 2021-12-10 21:36 UTC (permalink / raw)
To: H.J. Lu, libc-alpha
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).
> @@ -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?
> diff --git a/elf/Makefile b/elf/Makefile
> index fe42caeb0e..1bf77bc5ac 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -207,7 +207,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
> tst-tls4 tst-tls5 \
> tst-tls10 tst-tls11 tst-tls12 tst-tls13 tst-tls14 tst-tls15 \
> tst-tls16 tst-tls17 tst-tls18 tst-tls19 tst-tls-dlinfo \
> - tst-align tst-align2 tst-align3 \
> + tst-align tst-align2 \
> tst-dlmodcount tst-dlopenrpath tst-deep1 \
> tst-dlmopen1 tst-dlmopen3 tst-dlmopen4 \
> unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \
> @@ -241,9 +241,6 @@ tests-internal += loadtest unload unload2 circleload1 \
> tests-container += tst-pldd tst-dlopen-tlsmodid-container \
> tst-dlopen-self-container tst-preload-pthread-libc
> test-srcs = tst-pathopt
> -ifeq (yes,$(have-fpie))
> -tests-pie += tst-align3
> -endif
> selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
> ifneq ($(selinux-enabled),1)
> tests-execstack-yes = tst-execstack tst-execstack-needed tst-execstack-prog
> @@ -305,7 +302,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
> circlemod3 circlemod3a \
> reldep8mod1 reldep8mod2 reldep8mod3 \
> reldep9mod1 reldep9mod2 reldep9mod3 \
> - tst-alignmod tst-alignmod2 tst-alignmod3 \
> + tst-alignmod tst-alignmod2 \
> $(modules-execstack-$(have-z-execstack)) \
> tst-dlopenrpathmod tst-deep1mod1 tst-deep1mod2 tst-deep1mod3 \
> tst-dlmopen1mod tst-auditmod1 \
> @@ -418,6 +415,14 @@ endif
> modules-execstack-yes = tst-execstack-mod
> extra-test-objs += $(addsuffix .os,$(strip $(modules-names)))
>
> +ifeq (yes,$(have-2MB-alignment))
> +tests += tst-align3
> +modules-names += tst-alignmod3
> +ifeq (yes,$(have-fpie))
> +tests-pie += tst-align3
> +endif
> +endif
> +
> # filtmod1.so, tst-big-note-lib.so, tst-ro-dynamic-mod.so have special
> # rules.
> modules-names-nobuild := filtmod1 tst-big-note-lib tst-ro-dynamic-mod
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Check alignment of PT_LOAD segment only if possible
2021-12-10 21:36 ` Adhemerval Zanella
@ 2021-12-10 21:54 ` H.J. Lu
2021-12-10 22:50 ` Adhemerval Zanella
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2021-12-10 21:54 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: GNU C Library
On Fri, Dec 10, 2021 at 1:36 PM Adhemerval Zanella
<adhemerval.zanella@linaro.org> 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.
> > diff --git a/elf/Makefile b/elf/Makefile
> > index fe42caeb0e..1bf77bc5ac 100644
> > --- a/elf/Makefile
> > +++ b/elf/Makefile
> > @@ -207,7 +207,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
> > tst-tls4 tst-tls5 \
> > tst-tls10 tst-tls11 tst-tls12 tst-tls13 tst-tls14 tst-tls15 \
> > tst-tls16 tst-tls17 tst-tls18 tst-tls19 tst-tls-dlinfo \
> > - tst-align tst-align2 tst-align3 \
> > + tst-align tst-align2 \
> > tst-dlmodcount tst-dlopenrpath tst-deep1 \
> > tst-dlmopen1 tst-dlmopen3 tst-dlmopen4 \
> > unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \
> > @@ -241,9 +241,6 @@ tests-internal += loadtest unload unload2 circleload1 \
> > tests-container += tst-pldd tst-dlopen-tlsmodid-container \
> > tst-dlopen-self-container tst-preload-pthread-libc
> > test-srcs = tst-pathopt
> > -ifeq (yes,$(have-fpie))
> > -tests-pie += tst-align3
> > -endif
> > selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
> > ifneq ($(selinux-enabled),1)
> > tests-execstack-yes = tst-execstack tst-execstack-needed tst-execstack-prog
> > @@ -305,7 +302,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
> > circlemod3 circlemod3a \
> > reldep8mod1 reldep8mod2 reldep8mod3 \
> > reldep9mod1 reldep9mod2 reldep9mod3 \
> > - tst-alignmod tst-alignmod2 tst-alignmod3 \
> > + tst-alignmod tst-alignmod2 \
> > $(modules-execstack-$(have-z-execstack)) \
> > tst-dlopenrpathmod tst-deep1mod1 tst-deep1mod2 tst-deep1mod3 \
> > tst-dlmopen1mod tst-auditmod1 \
> > @@ -418,6 +415,14 @@ endif
> > modules-execstack-yes = tst-execstack-mod
> > extra-test-objs += $(addsuffix .os,$(strip $(modules-names)))
> >
> > +ifeq (yes,$(have-2MB-alignment))
> > +tests += tst-align3
> > +modules-names += tst-alignmod3
> > +ifeq (yes,$(have-fpie))
> > +tests-pie += tst-align3
> > +endif
> > +endif
> > +
> > # filtmod1.so, tst-big-note-lib.so, tst-ro-dynamic-mod.so have special
> > # rules.
> > modules-names-nobuild := filtmod1 tst-big-note-lib tst-ro-dynamic-mod
> >
--
H.J.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Check alignment of PT_LOAD segment only if possible
2021-12-10 21:54 ` H.J. Lu
@ 2021-12-10 22:50 ` Adhemerval Zanella
0 siblings, 0 replies; 4+ messages in thread
From: Adhemerval Zanella @ 2021-12-10 22:50 UTC (permalink / raw)
To: H.J. Lu; +Cc: GNU C Library
On 10/12/2021 18:54, H.J. Lu wrote:
> On Fri, Dec 10, 2021 at 1:36 PM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-10 22:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-10 20:59 [PATCH] Check alignment of PT_LOAD segment only if possible H.J. Lu
2021-12-10 21:36 ` Adhemerval Zanella
2021-12-10 21:54 ` H.J. Lu
2021-12-10 22:50 ` Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).