STM32: libstdc++ tweaks. Code size reduced to 61k (release, -Os, LTO) with no functional changes. Shall be refactored later.

This commit is contained in:
Pavel Kirienko 2014-04-11 02:09:43 +04:00
parent 59fd0224e0
commit 154f4e2e0d
2 changed files with 88 additions and 1 deletions

View File

@ -43,6 +43,8 @@ SERIAL_CLI_PORT_NUMBER = 2
RELEASE_OPT = -Os -fomit-frame-pointer
DEBUG_OPT = -Os -g3
#USE_OPT = -flto -u_port_lock -u_port_unlock -uchThdExit
USE_OPT = -flto -u_port_lock -u_port_unlock -u_exit -u_kill -u_getpid -uchThdExit
USE_OPT += -fno-unwind-tables -fno-stack-protector
USE_CPPOPT = -fno-threadsafe-statics
include crdr_chibios/rules_stm32f105_107.mk

View File

@ -3,6 +3,7 @@
*/
#include <cstdlib>
#include <sys/types.h>
/*
* stdlibc++ workaround.
@ -48,3 +49,87 @@ void __throw_future_error(int) { std::abort(); }
void __throw_bad_function_call() { std::abort(); }
}
/*
* The default pulls in 70K of garbage
*/
namespace __gnu_cxx
{
void __verbose_terminate_handler()
{
std::abort();
}
}
__extension__ typedef int __guard __attribute__((mode (__DI__)));
extern "C" void __cxa_atexit(void(*)(void *), void*, void*) { }
extern "C" int __aeabi_atexit(void*, void(*)(void*), void*)
{
return 0;
}
extern "C" int __cxa_guard_acquire(__guard* g) { return !*(char*)(g); }
extern "C" void __cxa_guard_release (__guard* g) { *(char *)g = 1; }
extern "C" void __cxa_guard_abort (__guard*) { }
/*
* The default pulls in about 12K of garbage
*/
extern "C" void __cxa_pure_virtual()
{
std::abort();
}
void* operator new(size_t)
{
std::abort();
return reinterpret_cast<void*>(0xFFFFFFFF);
}
void* operator new[](size_t)
{
std::abort();
return reinterpret_cast<void*>(0xFFFFFFFF);
}
void operator delete(void*)
{
std::abort();
}
void operator delete[](void*)
{
std::abort();
}
/*
* sbrk function for getting space for malloc and friends
*/
extern "C"
{
extern int _end;
caddr_t _sbrk(int incr)
{
static unsigned char *heap = NULL;
unsigned char *prev_heap;
if (heap == NULL)
{
heap = (unsigned char *) &_end;
}
prev_heap = heap;
/* check removed to show basic approach */
heap += incr;
return (caddr_t) prev_heap;
}
}