[libc-commits] [libc] [libc][math] Optimize nearest integer functions using builtins when available (PR #98376)

via libc-commits libc-commits at lists.llvm.org
Mon Jul 15 06:37:55 PDT 2024


overmighty wrote:

Rebased to fix the merge conflicts.

I still get these "undefined hidden symbol" linking errors I've been getting since the switch to `LIBC_NAMESPACE_DECL`:

```
[4/5] Linking CXX executable projects/libc/test/src/math/libc.test.src.math.cosf_test.__unit__.__NO_ROUND_OPT.__build__
FAILED: projects/libc/test/src/math/libc.test.src.math.cosf_test.__unit__.__NO_ROUND_OPT.__build__
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fuse-ld=lld -Wl,--color-diagnostics projects/libc/test/src/math/CMakeFiles/libc.test.src.math.cosf_test.__unit__.__NO_ROUND_OPT.__build__.dir/cosf_test.cpp.o -o projects/libc/test/src/math/libc.test.src.math.cosf_test.__unit__.__NO_ROUND_OPT.__build__  -Wl,-rpath,/tmp/llvm-build-overlay/lib  projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.__internal__.dir/./libc_errno.cpp.o  projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/./exit.cpp.o  projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/./fcntl.cpp.o  projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.cosf.__NO_ROUND_OPT.__internal__.dir/./cosf.cpp.o  projects/libc/src/__support/StringUtil/CMakeFiles/libc.src.__support.StringUtil.error_to_string.dir/./error_to_string.cpp.o  lib/liblibcMPFRWrapper.so  -lmpfr  -lgmp  lib/libLibcFPTestHelpers.unit.a  lib/libLibcDeathTestExecutors.unit.a  lib/libLibcTest.unit.a  -lmpfr  -lgmp && :
ld.lld: error: undefined hidden symbol: void __llvm_libc_19_0_0_git::testing::mpfr::internal::explain_unary_operation_single_output_error<float, float>(__llvm_libc_19_0_0_git::testing::mpfr::Operation, float, float, double, __llvm_libc_19_0_0_git::fputil::testing::RoundingMode)
>>> referenced by MPFRUtils.h:277 (/home/overmighty/projects/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.h:277)
>>>               projects/libc/test/src/math/CMakeFiles/libc.test.src.math.cosf_test.__unit__.__NO_ROUND_OPT.__build__.dir/cosf_test.cpp.o:(void __llvm_libc_19_0_0_git::testing::mpfr::internal::MPFRMatcher<(__llvm_libc_19_0_0_git::testing::mpfr::Operation)10, false, float, float>::explain_error<float, float>(float, float))

ld.lld: error: undefined hidden symbol: bool __llvm_libc_19_0_0_git::testing::mpfr::internal::compare_unary_operation_single_output<float, float>(__llvm_libc_19_0_0_git::testing::mpfr::Operation, float, float, double, __llvm_libc_19_0_0_git::fputil::testing::RoundingMode)
>>> referenced by MPFRUtils.h:248 (/home/overmighty/projects/llvm-project/libc/utils/MPFRWrapper/MPFRUtils.h:248)
>>>               projects/libc/test/src/math/CMakeFiles/libc.test.src.math.cosf_test.__unit__.__NO_ROUND_OPT.__build__.dir/cosf_test.cpp.o:(bool __llvm_libc_19_0_0_git::testing::mpfr::internal::MPFRMatcher<(__llvm_libc_19_0_0_git::testing::mpfr::Operation)10, false, float, float>::match<float, float>(float, float))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
```

I change MPFRUtils to use `LIBC_NAMESPACE` again when testing locally to fix these errors:

```diff
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index b67a9da40bd7..3f1758b20519 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -23,7 +23,7 @@

 template <typename T> using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;

-namespace LIBC_NAMESPACE_DECL {
+namespace LIBC_NAMESPACE {
 namespace testing {
 namespace mpfr {

diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h
index 28390af9ee6d..9b0002209bed 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.h
+++ b/libc/utils/MPFRWrapper/MPFRUtils.h
@@ -16,7 +16,7 @@

 #include <stdint.h>

-namespace LIBC_NAMESPACE_DECL {
+namespace LIBC_NAMESPACE {
 namespace testing {
 namespace mpfr {
 ```

https://github.com/llvm/llvm-project/pull/98376


More information about the libc-commits mailing list