[4/7] Add --early-cflags configure option

Message ID ba54ada5b853d96208f1ca434e25ca5caf93eb56.1642162312.git.fweimer@redhat.com
State New
Headers show
Series
  • Reliable CPU compatibility diagnostics in ld.so
Related show

Commit Message

Adhemerval Zanella via Libc-alpha Jan. 14, 2022, 12:40 p.m.
---
 config.make.in      |  1 +
 configure           | 13 +++++++++++++
 configure.ac        |  6 ++++++
 elf/Makefile        |  8 ++++++++
 manual/install.texi |  7 +++++++
 5 files changed, 35 insertions(+)

-- 
2.34.1

Comments

Adhemerval Zanella via Libc-alpha Jan. 14, 2022, 2:27 p.m. | #1
On Fri, Jan 14, 2022 at 4:43 AM Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>

> ---

>  config.make.in      |  1 +

>  configure           | 13 +++++++++++++

>  configure.ac        |  6 ++++++

>  elf/Makefile        |  8 ++++++++

>  manual/install.texi |  7 +++++++

>  5 files changed, 35 insertions(+)

>

> diff --git a/config.make.in b/config.make.in

> index e8630a8d0c..e06f1ff49f 100644

> --- a/config.make.in

> +++ b/config.make.in

> @@ -110,6 +110,7 @@ CFLAGS = @CFLAGS@

>  CPPFLAGS-config = @CPPFLAGS@

>  CPPUNDEFS = @CPPUNDEFS@

>  extra-nonshared-cflags = @extra_nonshared_cflags@

> +early-cflags = @early_cflags@

>  ASFLAGS-config = @ASFLAGS_config@

>  AR = @AR@

>  NM = @NM@

> diff --git a/configure b/configure

> index 3f956cf777..6eedd8c3a7 100755

> --- a/configure

> +++ b/configure

> @@ -681,6 +681,7 @@ force_install

>  bindnow

>  hardcoded_path_in_tests

>  enable_timezone_tools

> +early_cflags

>  extra_nonshared_cflags

>  use_default_link

>  sysheaders

> @@ -761,6 +762,7 @@ with_selinux

>  with_headers

>  with_default_link

>  with_nonshared_cflags

> +with_early_cflags

>  with_timeoutfactor

>  enable_sanity_checks

>  enable_shared

> @@ -1480,6 +1482,8 @@ Optional Packages:

>    --with-default-link     do not use explicit linker scripts

>    --with-nonshared-cflags=CFLAGS

>                            build nonshared libraries with additional CFLAGS

> +  --with-early-cflags=CFLAGS

> +                          build early initialization with additional CFLAGS

>    --with-timeoutfactor=NUM

>                            specify an integer to scale the timeout

>    --with-cpu=CPU          select code for CPU variant

> @@ -3386,6 +3390,15 @@ fi

>

>

>

> +# Check whether --with-early-cflags was given.

> +if test "${with_early_cflags+set}" = set; then :

> +  withval=$with_early_cflags; early_cflags=$withval

> +else

> +  early_cflags=

> +fi

> +

> +

> +

>

>  # Check whether --with-timeoutfactor was given.

>  if test "${with_timeoutfactor+set}" = set; then :

> diff --git a/configure.ac b/configure.ac

> index 277d3527d2..445b0b7f15 100644

> --- a/configure.ac

> +++ b/configure.ac

> @@ -162,6 +162,12 @@ AC_ARG_WITH([nonshared-cflags],

>             [extra_nonshared_cflags=$withval],

>             [extra_nonshared_cflags=])

>  AC_SUBST(extra_nonshared_cflags)

> +AC_ARG_WITH([early-cflags],

> +           AS_HELP_STRING([--with-early-cflags=CFLAGS],

> +                          [build early initialization with additional CFLAGS]),

> +           [early_cflags=$withval],

> +           [early_cflags=])

> +AC_SUBST(early_cflags)

>

>  AC_ARG_WITH([timeoutfactor],

>             AS_HELP_STRING([--with-timeoutfactor=NUM],

> diff --git a/elf/Makefile b/elf/Makefile

> index 0c4be43deb..9fcb4ebd13 100644

> --- a/elf/Makefile

> +++ b/elf/Makefile

> @@ -99,6 +99,14 @@ CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))

>  CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))

>  CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))

>

> +# Add the requested compiler flags to the early startup code.

> +CFLAGS-dl-printf.os += $(early-cflags)

> +CFLAGS-dl-sysdep.os += $(early-cflags)

> +CFLAGS-dl-tunables.os += $(early-cflags)

> +CFLAGS-dl-write.os += $(early-cflags)

> +CFLAGS-dl-writev.os += $(early-cflags)

> +CFLAGS-rtld.os += $(early-cflags)

> +

>  ifeq ($(unwind-find-fde),yes)

>  routines += unwind-dw2-fde-glibc

>  shared-only-routines += unwind-dw2-fde-glibc

> diff --git a/manual/install.texi b/manual/install.texi

> index b1afc56f5a..27d5893c5e 100644

> --- a/manual/install.texi

> +++ b/manual/install.texi

> @@ -131,6 +131,13 @@ that the objects in @file{libc_nonshared.a} are compiled with this flag

>  (although this will not affect the generated code in this particular

>  case and potentially change debugging information and metadata only).

>

> +@item --with-early-cflags=@var{cflags}

> +Use additional compiler flags @var{cflags} to build the early startup

> +code of the dynamic linker.  These flags can be used to enable early

> +dynamic linker diagnostics to run on CPUs which are not compatible with

> +the rest of @theglibc{}, for example, due to compiler flags which target

> +a later instruction set architecture (ISA).

> +


Isn't it limited to rtld?  If yes, I prefer --with-early-rtld-cflags

>  @item --with-timeoutfactor=@var{NUM}

>  Specify an integer @var{NUM} to scale the timeout of test programs.

>  This factor can be changed at run time using @env{TIMEOUTFACTOR}

> --

> 2.34.1

>

>



-- 
H.J.
Adhemerval Zanella via Libc-alpha Jan. 14, 2022, 2:29 p.m. | #2
* H. J. Lu:

>> +@item --with-early-cflags=@var{cflags}

>> +Use additional compiler flags @var{cflags} to build the early startup

>> +code of the dynamic linker.  These flags can be used to enable early

>> +dynamic linker diagnostics to run on CPUs which are not compatible with

>> +the rest of @theglibc{}, for example, due to compiler flags which target

>> +a later instruction set architecture (ISA).

>

> Isn't it limited to rtld?  If yes, I prefer --with-early-rtld-cflags


It's currently restricted to ld.so.  But we might enhance it to cover
static linking in the future, too.

Thanks,
Florian
Adhemerval Zanella via Libc-alpha Jan. 14, 2022, 2:33 p.m. | #3
On Fri, Jan 14, 2022 at 6:29 AM Florian Weimer <fweimer@redhat.com> wrote:
>

> * H. J. Lu:

>

> >> +@item --with-early-cflags=@var{cflags}

> >> +Use additional compiler flags @var{cflags} to build the early startup

> >> +code of the dynamic linker.  These flags can be used to enable early

> >> +dynamic linker diagnostics to run on CPUs which are not compatible with

> >> +the rest of @theglibc{}, for example, due to compiler flags which target

> >> +a later instruction set architecture (ISA).

> >

> > Isn't it limited to rtld?  If yes, I prefer --with-early-rtld-cflags

>

> It's currently restricted to ld.so.  But we might enhance it to cover

> static linking in the future, too.


But static linking may need a different early CFLAGS.

-- 
H.J.
Adhemerval Zanella via Libc-alpha Jan. 14, 2022, 2:34 p.m. | #4
* H. J. Lu:

> On Fri, Jan 14, 2022 at 6:29 AM Florian Weimer <fweimer@redhat.com> wrote:

>>

>> * H. J. Lu:

>>

>> >> +@item --with-early-cflags=@var{cflags}

>> >> +Use additional compiler flags @var{cflags} to build the early startup

>> >> +code of the dynamic linker.  These flags can be used to enable early

>> >> +dynamic linker diagnostics to run on CPUs which are not compatible with

>> >> +the rest of @theglibc{}, for example, due to compiler flags which target

>> >> +a later instruction set architecture (ISA).

>> >

>> > Isn't it limited to rtld?  If yes, I prefer --with-early-rtld-cflags

>>

>> It's currently restricted to ld.so.  But we might enhance it to cover

>> static linking in the future, too.

>

> But static linking may need a different early CFLAGS.


Fair point, I will send an updated patch.

Thanks,
Florian

Patch

diff --git a/config.make.in b/config.make.in
index e8630a8d0c..e06f1ff49f 100644
--- a/config.make.in
+++ b/config.make.in
@@ -110,6 +110,7 @@  CFLAGS = @CFLAGS@
 CPPFLAGS-config = @CPPFLAGS@
 CPPUNDEFS = @CPPUNDEFS@
 extra-nonshared-cflags = @extra_nonshared_cflags@
+early-cflags = @early_cflags@
 ASFLAGS-config = @ASFLAGS_config@
 AR = @AR@
 NM = @NM@
diff --git a/configure b/configure
index 3f956cf777..6eedd8c3a7 100755
--- a/configure
+++ b/configure
@@ -681,6 +681,7 @@  force_install
 bindnow
 hardcoded_path_in_tests
 enable_timezone_tools
+early_cflags
 extra_nonshared_cflags
 use_default_link
 sysheaders
@@ -761,6 +762,7 @@  with_selinux
 with_headers
 with_default_link
 with_nonshared_cflags
+with_early_cflags
 with_timeoutfactor
 enable_sanity_checks
 enable_shared
@@ -1480,6 +1482,8 @@  Optional Packages:
   --with-default-link     do not use explicit linker scripts
   --with-nonshared-cflags=CFLAGS
                           build nonshared libraries with additional CFLAGS
+  --with-early-cflags=CFLAGS
+                          build early initialization with additional CFLAGS
   --with-timeoutfactor=NUM
                           specify an integer to scale the timeout
   --with-cpu=CPU          select code for CPU variant
@@ -3386,6 +3390,15 @@  fi
 
 
 
+# Check whether --with-early-cflags was given.
+if test "${with_early_cflags+set}" = set; then :
+  withval=$with_early_cflags; early_cflags=$withval
+else
+  early_cflags=
+fi
+
+
+
 
 # Check whether --with-timeoutfactor was given.
 if test "${with_timeoutfactor+set}" = set; then :
diff --git a/configure.ac b/configure.ac
index 277d3527d2..445b0b7f15 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,6 +162,12 @@  AC_ARG_WITH([nonshared-cflags],
 	    [extra_nonshared_cflags=$withval],
 	    [extra_nonshared_cflags=])
 AC_SUBST(extra_nonshared_cflags)
+AC_ARG_WITH([early-cflags],
+	    AS_HELP_STRING([--with-early-cflags=CFLAGS],
+			   [build early initialization with additional CFLAGS]),
+	    [early_cflags=$withval],
+	    [early_cflags=])
+AC_SUBST(early_cflags)
 
 AC_ARG_WITH([timeoutfactor],
 	    AS_HELP_STRING([--with-timeoutfactor=NUM],
diff --git a/elf/Makefile b/elf/Makefile
index 0c4be43deb..9fcb4ebd13 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -99,6 +99,14 @@  CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))
 CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))
 CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))
 
+# Add the requested compiler flags to the early startup code.
+CFLAGS-dl-printf.os += $(early-cflags)
+CFLAGS-dl-sysdep.os += $(early-cflags)
+CFLAGS-dl-tunables.os += $(early-cflags)
+CFLAGS-dl-write.os += $(early-cflags)
+CFLAGS-dl-writev.os += $(early-cflags)
+CFLAGS-rtld.os += $(early-cflags)
+
 ifeq ($(unwind-find-fde),yes)
 routines += unwind-dw2-fde-glibc
 shared-only-routines += unwind-dw2-fde-glibc
diff --git a/manual/install.texi b/manual/install.texi
index b1afc56f5a..27d5893c5e 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -131,6 +131,13 @@  that the objects in @file{libc_nonshared.a} are compiled with this flag
 (although this will not affect the generated code in this particular
 case and potentially change debugging information and metadata only).
 
+@item --with-early-cflags=@var{cflags}
+Use additional compiler flags @var{cflags} to build the early startup
+code of the dynamic linker.  These flags can be used to enable early
+dynamic linker diagnostics to run on CPUs which are not compatible with
+the rest of @theglibc{}, for example, due to compiler flags which target
+a later instruction set architecture (ISA).
+
 @item --with-timeoutfactor=@var{NUM}
 Specify an integer @var{NUM} to scale the timeout of test programs.
 This factor can be changed at run time using @env{TIMEOUTFACTOR}