-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added glibc_wrap to provide Linux OS backwards compatibility
- Loading branch information
1 parent
47050cc
commit a9bf79e
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
if (NOT WIN32) | ||
add_library(glibc_wrap STATIC glibc_wrap.c) | ||
# Ensure position-independent code is generated | ||
set_target_properties(glibc_wrap PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
target_include_directories(glibc_wrap PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||
# Specify the wrapped functions on the interface link options. | ||
# This causes libraries linking against this one to use the wrapped | ||
# functions rather than those in a potentially too new glibc for | ||
# our minimum supported OS. See glibc_wrap.c for details. | ||
target_link_libraries(glibc_wrap INTERFACE ${GLIBC_WRAP_FUNCTIONS}) | ||
|
||
# Link the math library for debian-11-arm-dev | ||
target_link_libraries(glibc_wrap INTERFACE m) | ||
|
||
install(TARGETS glibc_wrap DESTINATION ${CMAKE_SOURCE_DIR}/glibc_wrap) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// These functions are only called by our code when built on newer distros. We | ||
// add '-Wl,--wrap={funcname}' to the link line which changes all calls to | ||
// '{funcname}' to '__wrap_{funcname}' | ||
|
||
// For all the gritty details: | ||
// https://www.win.tue.nl/~aeb/linux/misc/gcc-semibug.html | ||
// https://stackoverflow.com/questions/4032373/linking-against-an-old-version-of-libc-to-provide-greater-application-coverage | ||
|
||
#include <linux/unistd.h> | ||
#include <math.h> | ||
#include <sys/syscall.h> | ||
#include <unistd.h> | ||
|
||
#ifndef __arm__ | ||
// Use GLIBC 2.2.5 versioning only if not on ARM | ||
asm(".symver log2_glibc_225, log2@GLIBC_2.2.5"); | ||
extern double log2_glibc_225(double num); | ||
#endif | ||
|
||
double __wrap_log2(double num) { | ||
#ifdef __arm__ | ||
// If compiling for ARM, just call the system-native log2 function | ||
return log2(num); | ||
#else | ||
// Call the GLIBC 2.2.5 version of log2 if not on ARM | ||
return log2_glibc_225(num); | ||
#endif | ||
} | ||
|
||
pid_t __wrap_gettid(void) { return (pid_t)syscall(SYS_gettid); } |