Skip to content

Commit 321ed4c

Browse files
committed
Added glibc_wrap to provide Linux OS backwards compatibility
Use target_link_libraries instead due to OS support Clang format for glibc_wrap Remove unneeded functions link against math lib modify manifest modify manifest modify manifest Add arm only definitions Add back changes Revert "Add back changes" This reverts commit 152cf55. Remove reference to internal links Update CHANGELOG.md Update RELEASE.md Update RELEASE.md Delete cmake/manifests/linux/install_manifest.txt Add files via upload
1 parent 47050cc commit 321ed4c

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ set(CPACK_PACKAGE_VERSION_PATCH "0")
1919
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
2020
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
2121

22+
if (NOT WIN32)
23+
set(GLIBC_WRAP_FUNCTIONS
24+
-Wl,--wrap=gettid
25+
-Wl,--wrap=log2)
26+
endif()
2227
# Enforce keeping the source directory clean by building in a separate
2328
# directory. This avoids unnecessary corner cases, e.g., copying files
2429
# from source to binary directory with identical relative paths.
@@ -333,7 +338,10 @@ target_link_libraries(acl PRIVATE
333338
if(UNIX)
334339
# we need this flag to expose symbols, otherwise linking will fail with:
335340
# "relocation against protected symbol X can not be used when making a shared object"
341+
add_subdirectory(glibc_wrap)
336342
set_target_properties(acl PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
343+
target_include_directories(acl PRIVATE ${CMAKE_SOURCE_DIR}/glibc_wrap)
344+
target_link_libraries(acl PRIVATE glibc_wrap)
337345
endif()
338346

339347
set_property(TARGET acl PROPERTY PUBLIC_HEADER

cmake/manifests/linux/install_manifest.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@
3636
/fpga-runtime-for-opencl/include/CL/opencl.h
3737
/fpga-runtime-for-opencl/include/CL/opencl.hpp
3838
/fpga-runtime-for-opencl/include/MMD/aocl_mmd.h
39-
/fpga-runtime-for-opencl/include/MMD/aocl_mmd_deprecated.h
39+
/fpga-runtime-for-opencl/include/MMD/aocl_mmd_deprecated.h
40+
/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/glibc_wrap/libglibc_wrap.a

glibc_wrap/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
if (NOT WIN32)
2+
add_library(glibc_wrap STATIC glibc_wrap.c)
3+
# Ensure position-independent code is generated
4+
set_target_properties(glibc_wrap PROPERTIES POSITION_INDEPENDENT_CODE ON)
5+
target_include_directories(glibc_wrap PRIVATE ${CMAKE_SOURCE_DIR}/src)
6+
# Specify the wrapped functions on the interface link options.
7+
# This causes libraries linking against this one to use the wrapped
8+
# functions rather than those in a potentially too new glibc for
9+
# our minimum supported OS. See glibc_wrap.c for details.
10+
target_link_libraries(glibc_wrap INTERFACE ${GLIBC_WRAP_FUNCTIONS})
11+
12+
# Link the math library for debian-11-arm-dev
13+
target_link_libraries(glibc_wrap INTERFACE m)
14+
15+
install(TARGETS glibc_wrap DESTINATION ${CMAKE_SOURCE_DIR}/glibc_wrap)
16+
endif()

glibc_wrap/glibc_wrap.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// These functions are only called by our code when built on newer distros. We
2+
// add '-Wl,--wrap={funcname}' to the link line which changes all calls to
3+
// '{funcname}' to '__wrap_{funcname}'
4+
5+
// For all the gritty details:
6+
// https://www.win.tue.nl/~aeb/linux/misc/gcc-semibug.html
7+
// https://stackoverflow.com/questions/4032373/linking-against-an-old-version-of-libc-to-provide-greater-application-coverage
8+
9+
#include <linux/unistd.h>
10+
#include <math.h>
11+
#include <sys/syscall.h>
12+
#include <unistd.h>
13+
14+
#ifndef __arm__
15+
// Use GLIBC 2.2.5 versioning only if not on ARM
16+
asm(".symver log2_glibc_225, log2@GLIBC_2.2.5");
17+
extern double log2_glibc_225(double num);
18+
#endif
19+
20+
double __wrap_log2(double num) {
21+
#ifdef __arm__
22+
// If compiling for ARM, just call the system-native log2 function
23+
return log2(num);
24+
#else
25+
// Call the GLIBC 2.2.5 version of log2 if not on ARM
26+
return log2_glibc_225(num);
27+
#endif
28+
}
29+
30+
pid_t __wrap_gettid(void) { return (pid_t)syscall(SYS_gettid); }

0 commit comments

Comments
 (0)