diff mbox

[2/2] configure: Make AVX2 test robust to non-ELF systems

Message ID 1466287502-18730-3-git-send-email-pmaydell@chiark.greenend.org.uk
State New
Headers show

Commit Message

Peter Maydell June 18, 2016, 10:05 p.m. UTC
From: Peter Maydell <peter.maydell@linaro.org>

The AVX2 optimization test assumes that the object format
is ELF and the system has the readelf utility. If this isn't
true then configure might fail or emit a warning (since in
a pipe "foo | bar >/dev/null 2>&1" does not redirect the
stderr of foo, only of bar). Adjust the check so that if
we don't have readelf or don't have an ELF object then we
just don't enable the AVX2 optimization.

Reported-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 configure | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Stefan Weil June 19, 2016, 5:53 a.m. UTC | #1
Am 19.06.2016 um 00:05 schrieb Peter Maydell:
> From: Peter Maydell <peter.maydell@linaro.org>
> 
> The AVX2 optimization test assumes that the object format
> is ELF and the system has the readelf utility. If this isn't
> true then configure might fail or emit a warning (since in
> a pipe "foo | bar >/dev/null 2>&1" does not redirect the
> stderr of foo, only of bar). Adjust the check so that if
> we don't have readelf or don't have an ELF object then we
> just don't enable the AVX2 optimization.
> 
> Reported-by: Stefan Weil <sw@weilnetz.de>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  configure | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 7beefcd..30bca55 100755
> --- a/configure
> +++ b/configure
> @@ -1792,8 +1792,10 @@ int foo(void *a) __attribute__((ifunc("bar_ifunc")));
>  int main(int argc, char *argv[]) { return foo(argv[0]);}
>  EOF
>  if compile_object "" ; then
> -    if readelf --syms $TMPO |grep "IFUNC.*foo" >/dev/null 2>&1; then
> -        avx2_opt="yes"
> +    if has readelf; then
> +        if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then
> +            avx2_opt="yes"
> +        fi
>      fi
>  fi
>  
> 

You could check "has readelf" earlier and avoid the compile test
if there is no readelf (saves a little time).

The final I/O redirection is still needed (otherwise Linux users will
see the grep output).

Regards
Stefan
Peter Maydell June 19, 2016, 9:41 a.m. UTC | #2
On 19 June 2016 at 06:53, Stefan Weil <sw@weilnetz.de> wrote:
> Am 19.06.2016 um 00:05 schrieb Peter Maydell:
>> From: Peter Maydell <peter.maydell@linaro.org>
>>
>> The AVX2 optimization test assumes that the object format
>> is ELF and the system has the readelf utility. If this isn't
>> true then configure might fail or emit a warning (since in
>> a pipe "foo | bar >/dev/null 2>&1" does not redirect the
>> stderr of foo, only of bar). Adjust the check so that if
>> we don't have readelf or don't have an ELF object then we
>> just don't enable the AVX2 optimization.
>>
>> Reported-by: Stefan Weil <sw@weilnetz.de>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>>  configure | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 7beefcd..30bca55 100755
>> --- a/configure
>> +++ b/configure
>> @@ -1792,8 +1792,10 @@ int foo(void *a) __attribute__((ifunc("bar_ifunc")));
>>  int main(int argc, char *argv[]) { return foo(argv[0]);}
>>  EOF
>>  if compile_object "" ; then
>> -    if readelf --syms $TMPO |grep "IFUNC.*foo" >/dev/null 2>&1; then
>> -        avx2_opt="yes"
>> +    if has readelf; then
>> +        if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then
>> +            avx2_opt="yes"
>> +        fi
>>      fi
>>  fi
>>
>>
>
> You could check "has readelf" earlier and avoid the compile test
> if there is no readelf (saves a little time).

I guess so, though there's not much in it.

> The final I/O redirection is still needed (otherwise Linux users will
> see the grep output).

I added -q which should suppress that, no ?

thanks
-- PMM
Stefan Weil June 19, 2016, 11:19 a.m. UTC | #3
Am 19.06.2016 um 11:41 schrieb Peter Maydell:
> On 19 June 2016 at 06:53, Stefan Weil <sw@weilnetz.de> wrote:
>> Am 19.06.2016 um 00:05 schrieb Peter Maydell:
>>> From: Peter Maydell <peter.maydell@linaro.org>
>>>
>>> The AVX2 optimization test assumes that the object format
>>> is ELF and the system has the readelf utility. If this isn't
>>> true then configure might fail or emit a warning (since in
>>> a pipe "foo | bar >/dev/null 2>&1" does not redirect the
>>> stderr of foo, only of bar). Adjust the check so that if
>>> we don't have readelf or don't have an ELF object then we
>>> just don't enable the AVX2 optimization.
>>>
>>> Reported-by: Stefan Weil <sw@weilnetz.de>
>>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>>> ---
>>>  configure | 6 ++++--
>>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/configure b/configure
>>> index 7beefcd..30bca55 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -1792,8 +1792,10 @@ int foo(void *a) __attribute__((ifunc("bar_ifunc")));
>>>  int main(int argc, char *argv[]) { return foo(argv[0]);}
>>>  EOF
>>>  if compile_object "" ; then
>>> -    if readelf --syms $TMPO |grep "IFUNC.*foo" >/dev/null 2>&1; then
>>> -        avx2_opt="yes"
>>> +    if has readelf; then
>>> +        if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then
>>> +            avx2_opt="yes"
>>> +        fi
>>>      fi
>>>  fi
>>>
>>>
>>
>> You could check "has readelf" earlier and avoid the compile test
>> if there is no readelf (saves a little time).
> 
> I guess so, though there's not much in it.
> 
>> The final I/O redirection is still needed (otherwise Linux users will
>> see the grep output).
> 
> I added -q which should suppress that, no ?
> 
> thanks
> -- PMM
> 

Sorry, I missed that detail.

Reviewed-by: Stefan Weil <sw@weilnetz.de>
diff mbox

Patch

diff --git a/configure b/configure
index 7beefcd..30bca55 100755
--- a/configure
+++ b/configure
@@ -1792,8 +1792,10 @@  int foo(void *a) __attribute__((ifunc("bar_ifunc")));
 int main(int argc, char *argv[]) { return foo(argv[0]);}
 EOF
 if compile_object "" ; then
-    if readelf --syms $TMPO |grep "IFUNC.*foo" >/dev/null 2>&1; then
-        avx2_opt="yes"
+    if has readelf; then
+        if readelf --syms $TMPO 2>/dev/null |grep -q "IFUNC.*foo"; then
+            avx2_opt="yes"
+        fi
     fi
 fi