bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memcmp and cross-compilation


From: Simon Josefsson
Subject: Re: memcmp and cross-compilation
Date: Wed, 21 May 2008 11:15:54 +0200
User-agent: Gnus/5.110009 (No Gnus v0.9) Emacs/22.2 (gnu/linux)

Jim Meyering <address@hidden> writes:

> Simon Josefsson <address@hidden> wrote:
>>>>> MinGW apparently needs gnulib's memcmp module
>>>>
>>>> That was rather surprising to me, so I started investigating why that is
>>>> the case.
>>>
>>> The reason was that Autoconf's AC_FUNC_MEMCMP uses AC_RUN_IFELSE with a
>>> cross-compile default of no.  I prefer to assume memcmp exists on
>>> cross-compile targets since I assume C89 or later in my projects.  That
>>> is probably not the right choice for autoconf, but I think it is for
>
> Hi Simon,
>
> These days, I'd guess that the least common denominator cross-compiling
> target environment is C89 -- and consistently more modern than the minimal
> native environment, so Autoconf might need to review assumptions like that.
> The trouble is that the penalty for making a mistake is incorrect operation,
> while maintaining the status quo is merely degraded performance.

Right, it is a tricky trade-off.  I think we would need to first
understand how many tests in autoconf are similar to the memcmp test.
If memcmp is unique, then maybe it could be handled with my patch.  If
there are many functions that are tested like this, and result in poor
performance on cross-compiles, maybe a AC_ASSUME_C89_TARGET or similar
could be introduced to override this behavior.  It would be optional and
thus wouldn't cause incorrect operation by default.

>>> gnulib.  Thus it seems gnulib needs to extend autoconf's test somewhat?
>>> I'll suggest something for review.
>>
>> The patch below works in the sense that, for cross-compilations only, it
>> will assume that memcmp works when it is declared.  This works better
>> for MinGW.
> ...
>> Jim, what do you think?
> ...
>>  AC_DEFUN([gl_FUNC_MEMCMP],
>>  [
>> +  if test $cross_compiling != no; then
>> +    # AC_FUNC_MEMCMP as of 2.62 defaults to 'no' when cross compiling.
>> +    # We default to yes if memcmp appears to exist, which works
>> +    # better for MinGW.
>> +    AC_CACHE_CHECK([whether cross-compiling target has memcmp],
>> +                   [ac_cv_func_memcmp_working],
>> +                   [AC_LINK_IFELSE([
>> +                    AC_LANG_PROGRAM([[#include <string.h>
>> +                            ]], [[int ret = memcmp ("foo", "bar", 0)]])],
>
> That looks fine.
> However, please add the conventional semicolon:
>
>                               ]], [[int ret = memcmp ("foo", "bar", 0);]])],
>
> I know it's not officially needed, since AC_LANG_PROGRAM
> provides one, but I had to look to confirm that.
> You're welcome to commit the result.

Thanks, I have pushed it now.  gnutls 2.3.11 have been released with
this code in it, so maybe I'll get feedback if it doesn't work well.
I'll try to cross-compile it to openwrt next.

/Simon




reply via email to

[Prev in Thread] Current Thread [Next in Thread]