Skip to content

Commit 42f55ef

Browse files
jiayifengfacebook-github-bot
authored andcommitted
Make loader.cpp compatible with glibc <= 2.17 (#173)
Summary: In the current `loader.cpp`, the symbol `__cxa_thread_atexit_impl` is introduced by `extern "C"`: https://github.com/pytorch/multipy/blob/main/multipy/runtime/loader.cpp#L247-L248 However, this symbol is exposed in libc.so.6 only when glibc version is >=2.18. With old glibc, compile fails. In this PR, the problem is solved by replacing `__cxa_thread_atexit_impl` with `__cxxabiv1::__cxa_thread_atexit`. The function `__cxxabiv1::__cxa_thread_atexit` is a simple wrapper of `__cxa_thread_atexit_impl` and does exactly the same job: https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/libsupc%2B%2B/atexit_thread.cc#L41-L47. The function is declared in the `cxxabi.h`. So we can use it by `include <cxxabi.h>` and the code no longer depends on glibc version. Pull Request resolved: #173 Reviewed By: anirbanr-fb-r2p Differential Revision: D39580718 Pulled By: d4l3k fbshipit-source-id: 0d396599f2a9eabfb1bea62083f5c4acf065c61e
1 parent 2afcb43 commit 42f55ef

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

multipy/runtime/loader.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* SUCH DAMAGE.
3636
*/
3737

38+
#include <cxxabi.h>
3839
#include <dlfcn.h>
3940
#include <elf.h>
4041
#include <fcntl.h>
@@ -244,9 +245,6 @@ struct EH_Frame_HDR {
244245
// with the module_id and offset.
245246
extern "C" void* __tls_get_addr(void*);
246247

247-
extern "C" int
248-
__cxa_thread_atexit_impl(void (*dtor)(void*), void* obj, void* dso_symbol);
249-
250248
// This object performs TLS emulation for modules not loaded by dlopen.
251249
// Normally modules have a module_id that is used as a key in libc for the
252250
// thread local data for that module. However, there is no public API for
@@ -987,7 +985,7 @@ struct __attribute__((visibility("hidden"))) CustomLibraryImpl
987985
return (Elf64_Addr)local__tls_get_addr;
988986
}
989987
if (strcmp(sym_name, "__cxa_thread_atexit") == 0) {
990-
return (Elf64_Addr)__cxa_thread_atexit_impl;
988+
return (Elf64_Addr)__cxxabiv1::__cxa_thread_atexit;
991989
}
992990
}
993991

@@ -1242,7 +1240,7 @@ struct __attribute__((visibility("hidden"))) CustomLibraryImpl
12421240
void* start = pthread_getspecific(tls_key_);
12431241
if (!start) {
12441242
start = malloc(tls_mem_size_);
1245-
__cxa_thread_atexit_impl(free, start, &__dso_handle);
1243+
__cxxabiv1::__cxa_thread_atexit(free, start, &__dso_handle);
12461244
memcpy(start, tls_initalization_image_, tls_file_size_);
12471245
memset(
12481246
(void*)((const char*)start + tls_file_size_),

0 commit comments

Comments
 (0)