clang on armv6 incorrectly emits call to sincos()

Jia-Shiun Li jiashiun at gmail.com
Wed Jan 11 14:42:42 UTC 2017


Hi all,

I was looking into build failure after graphviz been updated to 2.40.1. On
amd64 it builds fine. But on armv6 aka rpi2 when linking, it complained
about undefined reference to sincos. [1]

Turns out it was not graphviz but clang.

When compling with -ffast-math, clang folds adjancent calls to sin() and
cos() into one call to sincos(), which FreeBSD does not have. Thus the
linking error. A minimal example source file is provided in [2]. Commands
[3], and my environment. [4]

Think this optimization should be turned off for armv6 from base
clang/llvm, instead of patching individual ports or ports infrastructure.
Or is it possibly due to crosscompiling world? I haven't tried if natively
built world works. Ideas?


-Jia-shiun.


[1]:
libtool: link: cc -O -pipe -DLIBICONV_PLUG -fno-strict-aliasing -Wall
-Wextra -Wmissing-include-dirs -Wswitch-default -Wfloat-equal -Wundef
-Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wconversion
-Wstrict-prototypes -Wmissing-prototypes -Wnested-externs
-Wstrict-prototypes -Wpointer-arith -Wall -ffast-math -o .libs/dot
dot-dot.o dot-no_builtins.o  -L/usr/local/lib ../../lib/gvc/.libs/libgvc.so
/usr/local/lib/libltdl.so
/mnt/usr/ports/graphics/graphviz/work/graphviz-2.40.1/lib/xdot/.libs/libxdot.so
/mnt/usr/ports/graphics/graphviz/work/graphviz-2.40.1/lib/cgraph/.libs/libcgraph.so
/mnt/usr/ports/graphics/graphviz/work/graphviz-2.40.1/lib/pathplan/.libs/libpathplan.so
../../lib/cgraph/.libs/libcgraph.so
/mnt/usr/ports/graphics/graphviz/work/graphviz-2.40.1/lib/cdt/.libs/libcdt.so
-lexpat -lz -lm -lpthread -Wl,-rpath -Wl,/usr/local/lib/graphviz -Wl,-rpath
-Wl,/usr/local/lib
../../lib/gvc/.libs/libgvc.so: undefined reference to `sincos'
cc: ESC[0;1;31merror: ESC[0mlinker command failed with exit code 1 (use -v
to see invocation)ESC[0m
gmake[4]: *** [Makefile:779: dot] Error 1
gmake[4]: *** Waiting for unfinished jobs....


[2]:
#include <math.h>
#include <stdio.h>
#include <time.h>

int main()
{
    double sin1;
    double cos1;
    double a = (double)time(NULL);

    sin1 = sin(a);
    cos1 = cos(a);
    printf("a %f sin %f cos %f\n", a, sin1, cos1);

    return 0;
}


[3]:
% cc -O1 -ffast-math -lm sincos.c
/tmp/sincos-913575.o: In function `main':
sincos.c:(.text+0x2c): undefined reference to `sincos'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
% cc -O1 -fno-fast-math -lm sincos.c
%


[4]:
% uname -a
FreeBSD rpi2 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r311687: Tue Jan 10
21:36:16 CST 2017
jsli at 4cbsd:/personal/freebsd/obj/x64/arm.armv6/personal/freebsd/fbsdsrc/sys/RPI2
 arm
% clang --version
FreeBSD clang version 3.9.1 (tags/RELEASE_391/final 289601) (based on LLVM
3.9.1)
Target: armv6--freebsd12.0-gnueabihf
Thread model: posix
InstalledDir: /usr/bin


More information about the freebsd-arm mailing list