Issue with __cxa_atexit
Posted: Thu Dec 03, 2015 9:09 am
In my setup, I have a set of shared libraries that I am compiling using the TARGET=elf-x86_64 gcc cross-compiler. I have written a custom ELF loader that is capable of taking memory that is allocated with the execution bit turned on, and loading my shared libraries into that memory, relocating everything as needed. From there I can resolve a symbol, and execute it.
This all works great. Even got this to work on Windows by writing some custom ABI conversion code, and it works great in the Linux kernel too. This also works great with C++.... up to the point where I create a globally defined class like the following:
When I do this, I get the following error:
If I add the "-fno-use-cxa-atexit" flag this goes away and everything is happy. I attempted to create my own versions of these functions, but that doesn't seem to make any difference, until I define my own "__dso_handle" which then causes the linker to complain that this is defined multiple times. Using this flag works fine, minus the fact that the constructor and destructor of my globally defined class is never called. This is something I can live with, but was wonder if there are other options?
Anyone else try to do this?
- Rian
This all works great. Even got this to work on Windows by writing some custom ABI conversion code, and it works great in the Linux kernel too. This also works great with C++.... up to the point where I create a globally defined class like the following:
Code: Select all
class A
{
public:
A() {}
~A() {}
};
A a;
Code: Select all
.build/cross/entry.o: In function `__static_initialization_and_destruction_0(int, int)':
entry.cpp:(.text+0xb4): undefined reference to `__dso_handle'
/home/user/opt/cross/bin/x86_64-elf-ld: .build/cross/entry.o: relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object
/home/user/opt/cross/bin/x86_64-elf-ld: final link failed: Bad value
Anyone else try to do this?
- Rian