OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 9:24 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Issue with __cxa_atexit
PostPosted: Thu Dec 03, 2015 9:09 am 
Offline

Joined: Thu Jan 21, 2010 9:31 pm
Posts: 16
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:
Code:
class A
{
public:
    A() {}
    ~A() {}
};

A a;


When I do this, I get the following error:
Code:
.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


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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group