-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Bazel uses /usr/bin/clang instead of /usr/bin/clang++ to link C++ code on FreeBSD? #12023
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
P3We're not considering working on this, but happy to review a PR. (No assignee)We're not considering working on this, but happy to review a PR. (No assignee)staleIssues or PRs that are stale (no activity for 30 days)Issues or PRs that are stale (no activity for 30 days)team-Rules-CPPIssues for C++ rulesIssues for C++ rulestype: bug
Description
Description of the problem / feature request:
Apparently, Bazel uses /usr/bin/clang instead of /usr/bin/clang++ to compile/link C++ code. I'm not sure whether this is intentional, but the behavior for clang is different from clang++ resulting in subtle problems at compile/link time:
❯ /usr/bin/clang -o bazel-out/freebsd-fastbuild/bin/time_zone_lookup_test '-Wl,-rpath,$ORIGIN/_solib_freebsd/' -Lbazel-out/freebsd-fastbuild/bin/_solib_freebsd bazel-out/freebsd-fastbuild/bin/_objs/time_zone_lookup_test/time_zone_lookup_test.pic.o -llibtime_Uzone -llibcivil_Utime -lexternal_Scom_Ugoogle_Ugoogletest_Slibgtest_Umain -lexternal_Scom_Ugoogle_Ugoogletest_Slibgtest -pthread -Wl,-S -lstdc++ -Wl,-z,relro,-z,now -no-canonical-prefixes
ld: error: bazel-out/freebsd-fastbuild/bin/_solib_freebsd/liblibtime_Uzone.so: undefined reference to ceilf
clang: error: linker command failed with exit code 1 (use -v to see invocation)
❯ /usr/bin/clang++ -o bazel-out/freebsd-fastbuild/bin/time_zone_lookup_test '-Wl,-rpath,$ORIGIN/_solib_freebsd/' -Lbazel-out/freebsd-fastbuild/bin/_solib_freebsd bazel-out/freebsd-fastbuild/bin/_objs/time_zone_lookup_test/time_zone_lookup_test.pic.o -llibtime_Uzone -llibcivil_Utime -lexternal_Scom_Ugoogle_Ugoogletest_Slibgtest_Umain -lexternal_Scom_Ugoogle_Ugoogletest_Slibgtest -pthread -Wl,-S -lstdc++ -Wl,-z,relro,-z,now -no-canonical-prefixesThe first command is what Bazel uses for purely C++ code on my FreeBSD system and the latter is what it should use. The only difference is clang++ instead of clang.
Feature requests: what underlying problem are you trying to solve with this feature?
- Perhaps use clang++/g++ for C++ code and clang/gcc for C code.
- The two languages should use different rules as well:
cc_libraryfor C++ andc_libraryfor C code.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
❯ git clone https://github.com/google/cctz
...
❯ bazel test ...
...
ERROR: /usr/home/yesudeep/code/yesudeep/cctz/BUILD:165:10: Linking of rule '//:example3' failed (Exit 1) clang failed: error executing command /usr/bin/clang -o bazel-out/freebsd-fastbuild/bin/example3 bazel-out/freebsd-fastbuild/bin/_objs/example3/example3.pic.o bazel-out/freebsd-fastbuild/bin/libtime_zone.a ... (remaining 5 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
ld: error: undefined symbol: ceilf
>>> referenced by time_zone_impl.cc
>>> time_zone_impl.pic.o:(ceil(float)) in archive bazel-out/freebsd-fastbuild/bin/libtime_zone.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
INFO: Elapsed time: 0.357s, Critical Path: 0.03s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
//:cctz_benchmark NO STATUS
//:civil_time_test NO STATUS
//:time_zone_format_test NO STATUS
//:time_zone_lookup_test NO STATUS
FAILED: Build did NOT complete successfullyWhat operating system are you running Bazel on?
- FreeBSD 12.0-RELEASE
❯ uname -a
FreeBSD monalisa 12.1-RELEASE-p2 FreeBSD 12.1-RELEASE-p2 GENERIC amd64
❯ /usr/bin/clang++ --version
FreeBSD clang version 8.0.1 (tags/RELEASE_801/final 366581) (based on LLVM 8.0.1)
Target: x86_64-unknown-freebsd12.1
Thread model: posix
InstalledDir: /usr/binand
- GhostBSD 20.08.20 (FreeBSD 12.0-RELEASE based)
❯ uname -a
FreeBSD mevin 12.1-STABLE FreeBSD 12.1-STABLE GENERIC amd64
❯ /usr/bin/clang++ --version
FreeBSD clang version 10.0.0 (git@github.com:llvm/llvm-project.git llvmorg-10.0.0-0-gd32170dbd5b)
Target: x86_64-unknown-freebsd12.1
Thread model: posix
InstalledDir: /usr/binWhat's the output of bazel info release?
- FreeBSD
❯ bazel --version
bazel 3.3.0and
- GhostBSD (FreeBSD 12.0-RELEASE based)
❯ bazel info release
release 3.4.1What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?
❯ git remote get-url origin; git rev-parse master; git rev-parse HEAD
https://github.com/google/cctz
da5a52d91bf212a1f8c17f366ed8b947e2663d2a
da5a52d91bf212a1f8c17f366ed8b947e2663d2aHave you found anything relevant by searching the web?
Yes, apparently, everybody including me was getting around this by adding -lm linker flags until it was noticed that /usr/bin/clang is being used instead of /usr/bin/clang++ to link C++ code. Here's an example from the Bazel source tree.
Any other information, logs, or outputs that you want to share?
I think the above should include the logs, but please ask if you
need anything else.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3We're not considering working on this, but happy to review a PR. (No assignee)We're not considering working on this, but happy to review a PR. (No assignee)staleIssues or PRs that are stale (no activity for 30 days)Issues or PRs that are stale (no activity for 30 days)team-Rules-CPPIssues for C++ rulesIssues for C++ rulestype: bug