[x264-devel] configure: test for log2f fails, external reference folded out
Dirk Fieldhouse
fieldhouse at gmx.net
Tue Oct 16 01:04:41 CEST 2018
On 15/10/18 19:55, BugMaster wrote:
> On Wed, 10 Oct 2018 12:16:22 +0100, Dirk Fieldhouse wrote:
>> I'm building the 8 October stable version on a MIPS Broadcom 7405 SoC
>> platform with gcc-4.5.2 and uClibc-0.9.29.
>
>> The test at configure l1070 for support of log2f() in libm
>> (here:<http://git.videolan.org/?p=x264.git;a=blob;f=configure;h=07ba4490f4be6699549c8ac2f2745a0512ccea77;hb=HEAD#l1070>)
>> succeeds incorrectly.
>
>> The program fragment used by configure's cc_check call is
>>
>> #include <math.h>
>>
>> int main(void) {
>> log2f(2);
>> return 0;
>> }
>>
>> gcc 4.5.2 folds the constant expression log2f(2) leaving no external
>> reference to log2f. It even does this with no optimisation set.
>> Consequently the build defines HAVE_LOG2F to 1 when in fact there is no
>> log2f() in the libm provided by this version of uClibc.
>>
>> Whereas this reference survives:
>>
>> #include <math.h>
>>
>> int main(void) {
>> float x = 2; x = log2f(x);
>> return 0;
>> }
>
>> I suppose that even this is not guaranteed by the C standard(s) to
>> survive compile-time evaluation, but it beats this version of gcc.
>
>> To implement this, replace configure l1070 by this line
>
>> if cc_check 'math.h' '' 'float x = 2; x = log2f(x);' ; then
>
>> I'm not subscribed to the list at the moment so please CC: me as well.
> So log2f exists at compile time for constant evolution but not at
> runtime for variables? It is weird system/environment. Or is this only
> due use of uClibc instead of glibc (and gcc still use glibc during
> constant evolution)?
Exactly. This uClibc's libmath doesn't have log2f(), but perhaps this
gcc was built with the equivalent of HAVE_LOGF=0, causing its internal
log2f() to be defined through logf(). Or perhaps it does enough static
analysis to determine that log2f(2) is never used and so discards it. Or
both?
> Anyway for even more obstacle to compiler to optimize it out we can
> also add volatile to variable declaration.
>
> Check that it works as expected with attached patch.
Supporting the 2nd hypothesis above, it's not enough just to mention
log2f(x). You actually have to assign it as in my original proposal
above, so the proposed patch doesn't quite work even with the "volatile"
qualifier. I've made the trivial mod in the attached.
regards
/df
--
London SW6
UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-configure-Fix-log2f-support-check-at-some-systems_v2.patch
Type: text/x-patch
Size: 509 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20181016/9ac29a8e/attachment.bin>
More information about the x264-devel
mailing list