Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel build fails on FreeBSD with "undefined symbol: ceilf" #2190

Open
Tracked by #3602
asomers opened this issue Mar 20, 2019 · 8 comments
Open
Tracked by #3602

bazel build fails on FreeBSD with "undefined symbol: ceilf" #2190

asomers opened this issue Mar 20, 2019 · 8 comments

Comments

@asomers
Copy link

asomers commented Mar 20, 2019

The latest master fails to build on FreeBSD because bazel doesn't use -lm when building googletest-printers-test.cc:

bazel --output_user_root=/tmp/googletest build --curses=no --sandbox_debug  //...:all
Loading: 
Loading: 0 packages loaded
Analyzing: 64 targets (0 packages loaded, 0 targets configured)
INFO: Analysed 64 targets (0 packages loaded, 0 targets configured).
INFO: Found 64 targets...
[0 / 4] [-----] BazelWorkspaceStatusAction stable-status.txt
ERROR: /usr/home/somers/src/github/google/googletest/googletest/test/BUILD.bazel:38:1: Linking of rule '//googletest/test:gtest_all_test' failed (Exit 1) process-wrapper failed: error executing command 
  (cd /tmp/googletest/2cf661df848944827730f6d001863d27/sandbox/processwrapper-sandbox/1/execroot/com_google_googletest && \
  exec env - \
    PATH=/bin:/usr/bin/:/usr/local/bin \
    PWD=/proc/self/cwd \
    TMPDIR=/tmp \
  /tmp/googletest/install/f87e147311f717bac250eff8d1b892cf/_embedded_binaries/process-wrapper '--timeout=0' '--kill_delay=15' /usr/bin/clang -o bazel-out/freebsd-fastbuild/bin/googletest/test/gtest_all_test '-Wl,-rpath,$ORIGIN/../../_solib_freebsd/' -Lbazel-out/freebsd-fastbuild/bin/_solib_freebsd bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-death-test-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-filepath-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-message-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-options-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-param-test2-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-port-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-printers-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-test-part-test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-test2_test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/gtest-typed-test2_test.pic.o bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/gtest-typed-test_test.pic.o -llibgtest_Umain -llibgtest -pthread -pthread -Wl,-S -lstdc++ -Wl,-z,relro,-z,now -no-canonical-prefixes)
ld: error: undefined symbol: ceilf
>>> referenced by googletest-printers-test.cc
>>>               bazel-out/freebsd-fastbuild/bin/googletest/test/_objs/gtest_all_test/googletest-printers-test.pic.o:(ceil(float))
clang: error: linker command failed with exit code 1 (use -v to see invocation)
INFO: Elapsed time: 0.518s, Critical Path: 0.06s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
@asomers
Copy link
Author

asomers commented Mar 20, 2019

cc @ngie-eign

@asomers
Copy link
Author

asomers commented Mar 20, 2019

I should mention that this is FreeBSD 13.0-CURRENT amd64 with clang 8.0.0

@ngie-eign
Copy link
Contributor

ngie-eign commented Mar 20, 2019

-lstdc++ -- this is the bug I think (it should be -lc++). Is this a bug with Bazel? I've never used it outside of FB (where it's called "buck").

@ngie-eign
Copy link
Contributor

ngie-eign commented Mar 30, 2019

Hmmm... the cmake build does link properly and it includes libm (however, cmake doesn't do this directly AFAICT):

$ ldd /home/ngie/git/googletest/googlemock/gtest/googletest-printers-test
/home/ngie/git/googletest/googlemock/gtest/googletest-printers-test:
        libgtest_main.so => /home/ngie/git/googletest/lib/libgtest_main.so (0x8008ef000)
        libgtest.so => /home/ngie/git/googletest/lib/libgtest.so (0x800af0000)
        libthr.so.3 => /lib/libthr.so.3 (0x800dca000)
        libc++.so.1 => /usr/lib/libc++.so.1 (0x800ff2000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x8012c0000)
        libm.so.5 => /lib/libm.so.5 (0x8014df000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x80170c000)
        libc.so.7 => /lib/libc.so.7 (0x80191b000)
$ strings /home/ngie/git/googletest/googlemock/gtest/googletest-printers-test | grep ceilf
ceilf
$

Digging through the headers in /usr/include, it looks like ceilf is being used by the cmath interface header in its ceil implementation.

@asomers: what libstdc++ are you linking with? Could you please run ldd on it to list its dependent libraries?

@ngie-eign
Copy link
Contributor

ngie-eign commented Mar 30, 2019

Hmmm... bazelbuild/bazel@a89c7ef looks like an interesting feature to test. Could you please try running bazel like env BAZEL_LINKOPTS="-lc++:-lm" bazel build?

CC: @PiotrSikora.

@asomers
Copy link
Author

asomers commented Mar 30, 2019

I actually don't even have a libstdc++ installed. It's surprising that I don't get an even worse link error. Perhaps clang internally translates -lstdc++ to -lc++ ? And using your env BAZEL_LINKOPTS... suggestion does not make a difference.

@yesudeep
Copy link
Contributor

yesudeep commented Aug 27, 2020

What would be a correct fix for this?

Linker flags for cc_binary targets within bazel's own source tree specify:

"//src/conditions:freebsd": ["-lm"],
"//src/conditions:openbsd": ["-lm"],

which I believe should fix this problem unless you have a better suggestion.

@yesudeep
Copy link
Contributor

yesudeep commented Aug 30, 2020

Found the problem I think.

Bazel is using /usr/bin/clang instead of using /usr/bin/clang++ to link C++ code.
While -lm would fix it for the library, the correct solution would be to use /usr/bin/clang++ instead.

bazelbuild/bazel#12023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants