1/*******************************************************************************
2 Copyright (c) The Taichi Authors (2016- ). All Rights Reserved.
3 The use of this software is governed by the LICENSE file.
4*******************************************************************************/
5
6#include "taichi/common/platform_macros.h"
7#include <math.h>
8
9#if defined(TI_PLATFORM_WINDOWS)
10#include "taichi/platform/windows/windows.h"
11#else
12// Mac and Linux
13#include <unistd.h>
14#endif
15
16namespace taichi {
17extern "C" {
18#if defined(TI_PLATFORM_LINUX) && defined(TI_ARCH_x64)
19// Avoid dependency on higher glibc versions such as 2.27 or 2.29
20// Related issue: https://github.com/taichi-dev/taichi/issues/3174
21// log2f is used by a third party .a file, so we have to define a wrapper.
22// https://stackoverflow.com/questions/8823267/linking-against-older-symbol-version-in-a-so-file
23// The wrapper should be linked using target_link_libraries in TaichiCore.cmake
24__asm__(".symver log2f,log2f@GLIBC_2.2.5");
25float __wrap_log2f(float x) {
26 return log2f(x);
27}
28// The following are offending symbols using higher GLIBC versions
29// They will fail Vulkan tests if wrapping is enabled
30__asm__(".symver exp2,exp2@GLIBC_2.2.5");
31float __wrap_exp2(float x) {
32 return exp2(x);
33}
34__asm__(".symver log2,log2@GLIBC_2.2.5");
35float __wrap_log2(float x) {
36 return log2(x);
37}
38__asm__(".symver logf,logf@GLIBC_2.2.5");
39float __wrap_logf(float x) {
40 return logf(x);
41}
42__asm__(".symver powf,powf@GLIBC_2.2.5");
43float __wrap_powf(float x, float y) {
44 return powf(x, y);
45}
46__asm__(".symver exp,exp@GLIBC_2.2.5");
47float __wrap_exp(float x) {
48 return exp(x);
49}
50__asm__(".symver log,log@GLIBC_2.2.5");
51float __wrap_log(float x) {
52 return log(x);
53}
54__asm__(".symver pow,pow@GLIBC_2.2.5");
55float __wrap_pow(float x, float y) {
56 return pow(x, y);
57}
58#endif
59}
60} // namespace taichi
61