From owner-freebsd-arm@freebsd.org Wed Jan 11 14:42:42 2017 Return-Path: Delivered-To: freebsd-arm@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2CDC8CAA37C for ; Wed, 11 Jan 2017 14:42:42 +0000 (UTC) (envelope-from jiashiun@gmail.com) Received: from mail-qk0-x22e.google.com (mail-qk0-x22e.google.com [IPv6:2607:f8b0:400d:c09::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D9C74163F for ; Wed, 11 Jan 2017 14:42:41 +0000 (UTC) (envelope-from jiashiun@gmail.com) Received: by mail-qk0-x22e.google.com with SMTP id 11so111849461qkl.3 for ; Wed, 11 Jan 2017 06:42:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=TKI7517j7WIEnly/MaQKy4shd2BaPF6MrbSI5mX7KVs=; b=UjwuvtuohgtnS0c5AeVzlQjoMU2mnU4m2CuBlttSFeM1iDZM5QSGNwDUyT4Bc0iCMT MLUCp/Jvqye1FD9SBba9NpXtggDzH7/FMy8Q+Pphx8sHnVdAco9A0fRa/2ugxRmd4Qc1 xiL5H7bun910eK9orVlimvDWrzETjobvgve+IC5o7FNBWsF+kqc8kO/DiAd+OO9xukjY 7S23anHszOzooZ/rBYMS2RvrAweS/PI904PSEryFAMDsV6VSiTzl5/ibqLeIGTRo7RTJ azrorsolnUrH1GgfX5dXgkNYyIFbkGtBsUb1peOxRSOhUNxKDDwMoB3tZuAI7yJQdaXV RI4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=TKI7517j7WIEnly/MaQKy4shd2BaPF6MrbSI5mX7KVs=; b=A9WdyB5jHs0x9eawsHdGio/ClIOdWVu9JxLTkDduoZ1KILT+HOxIN2PtA7EPD+rMZw trNjaAYL8SZAbVouC/ZnpXJiKz+UPkD5FL3ksSsyaRNeHh3X/6WOkSxLGkzAULhJ2YgP Z+JqRIqvjSzUgCr7yyH432VDOrKAk/1J4lPHhdH6fGIxhYLAlzk98nBFPqEixPGdeUv1 ELvfHiKwjRakrdBO9Exhq8S+k59BMYrKMtpyPyvqd5ti5Jsgz+kB7XLDfP5As3yv+dUv ALf/q0MvanfaIriP8LFDYZEs5UMNvOC0Ted3fEMzxzShbyLasBWILgBxFmz2XgQbB9p9 PATw== X-Gm-Message-State: AIkVDXL9ygH/y/RgqAkrsZrVQ5oCxsttscY/troTeZpK5KS7U/Vy7+D+SWXl3Igje+tUPP4XYcXIYxFFIX+KaQ== X-Received: by 10.55.42.34 with SMTP id q34mr9159608qkh.91.1484145760683; Wed, 11 Jan 2017 06:42:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.140.82.149 with HTTP; Wed, 11 Jan 2017 06:42:10 -0800 (PST) From: Jia-Shiun Li Date: Wed, 11 Jan 2017 22:42:10 +0800 Message-ID: Subject: clang on armv6 incorrectly emits call to sincos() To: "freebsd-arm@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jan 2017 14:42:42 -0000 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 #include #include 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@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