I am trying to decrease the binary size by overriding default __terminate_handler
. Normally, when compiling with GCC, this piece of code:
[[noreturn]] void terminate() noexcept
{
while (true)
;
}
namespace __cxxabiv1
{
std::terminate_handler __terminate_handler = terminate;
}
Makes the default __terminate_handler
overridden and the binary size decreases by 30-50 kB, depending on the release/debug build type.
When compiling with Clang I use -nostdlib
linker flag, thus I have to link the standard libraries explicitly, by putting -lstdc++ -lgcc
as the command line options. This means that I get an error:
ld.lld: error: duplicate symbol: __cxxabiv1::__terminate_handler
-> defined in armgnutoolchain-src/arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a(eh_term_handler.o)
-> defined in custom_terminate.cpp.obj
Both, custom code and libstdc++
define __cxxabiv1::__terminate_handler
(_ZN10__cxxabiv119__terminate_handlerE
) as a symbol initialized in data section. Ideally, I would like the symbol to be defined weak in the libstdc++
.
Is there a way to ignore the symbol defined in libstdc++
?