[libiberty] Make test for variables more robust

Message ID 5710259.lOV4Wx5bFT@fomalhaut
State New
Headers show
Series
  • [libiberty] Make test for variables more robust
Related show

Commit Message

Eric Botcazou May 3, 2021, 7:01 a.m.
Hi,

the test for the presence of variables (really symbols) does not work when you 
add -Ox -flto to CFLAGS:

  for v in $vars; do
    AC_MSG_CHECKING([for $v])
    AC_CACHE_VAL(libiberty_cv_var_$v,
      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[int *p;]],[[extern int $v []; p = 
$v;]])],
		      [eval "libiberty_cv_var_$v=yes"],
		      [eval "libiberty_cv_var_$v=no"])])
    if eval "test \"`echo '$libiberty_cv_var_'$v`\" = yes"; then
      AC_MSG_RESULT(yes)
      n=HAVE_`echo $v | tr 'abcdefghijklmnopqrstuvwxyz' 
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
      AC_DEFINE_UNQUOTED($n)
    else
      AC_MSG_RESULT(no)
    fi
  done

because the assignment to 'p' is optimized away by LTO.  This is visible on 
MinGW platforms in the form of a link failure for sys_siglist.

Tested on x86-64/Linux, x86-64/Windows and x86/Windows, OK for the mainline?


2021-05-03  Eric Botcazou  <ebotcazou@adacore.com>

	* configure.ac: Make test for variables more robust.
	* configure: Regenerate.

-- 
Eric Botcazou

Comments

Iain Buclaw via Gcc-patches May 3, 2021, 8:24 a.m. | #1
On Mon, May 3, 2021 at 9:51 AM Eric Botcazou <botcazou@adacore.com> wrote:
>

> Hi,

>

> the test for the presence of variables (really symbols) does not work when you

> add -Ox -flto to CFLAGS:

>

>   for v in $vars; do

>     AC_MSG_CHECKING([for $v])

>     AC_CACHE_VAL(libiberty_cv_var_$v,

>       [AC_LINK_IFELSE([AC_LANG_PROGRAM([[int *p;]],[[extern int $v []; p =

> $v;]])],

>                       [eval "libiberty_cv_var_$v=yes"],

>                       [eval "libiberty_cv_var_$v=no"])])

>     if eval "test \"`echo '$libiberty_cv_var_'$v`\" = yes"; then

>       AC_MSG_RESULT(yes)

>       n=HAVE_`echo $v | tr 'abcdefghijklmnopqrstuvwxyz'

> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`

>       AC_DEFINE_UNQUOTED($n)

>     else

>       AC_MSG_RESULT(no)

>     fi

>   done

>

> because the assignment to 'p' is optimized away by LTO.  This is visible on

> MinGW platforms in the form of a link failure for sys_siglist.

>

> Tested on x86-64/Linux, x86-64/Windows and x86/Windows, OK for the mainline?


OK.

>

> 2021-05-03  Eric Botcazou  <ebotcazou@adacore.com>

>

>         * configure.ac: Make test for variables more robust.

>         * configure: Regenerate.

>

> --

> Eric Botcazou

Patch

diff --git a/libiberty/configure.ac b/libiberty/configure.ac
index ad952963971..3c03f24d368 100644
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -665,7 +665,7 @@  if test -z "${setobjs}"; then
   for v in $vars; do
     AC_MSG_CHECKING([for $v])
     AC_CACHE_VAL(libiberty_cv_var_$v,
-      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[int *p;]],[[extern int $v []; p = $v;]])],
+      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern int $v [];]],[[if ($v [0]) return 1;]])],
 		      [eval "libiberty_cv_var_$v=yes"],
 		      [eval "libiberty_cv_var_$v=no"])])
     if eval "test \"`echo '$libiberty_cv_var_'$v`\" = yes"; then