Skip to content

Commit 1085fd5

Browse files
committed
linker: forcefully remove exceptions and pack sections
There's no way to convince the compiler to consider the provided flags when linking modern c++ code (std::). Get rid of the useless symbols in the linker and add the (then) missing implementations in abi.cpp
1 parent 45fb8cf commit 1085fd5

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Diff for: cores/arduino/abi.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66

77
#include <stdlib.h>
88

9-
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
10-
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
11-
12-
namespace std {
13-
[[gnu::weak, noreturn]] void terminate() {
14-
abort();
15-
}
9+
extern "C" void __cxa_pure_virtual(void) {}
10+
extern "C" void __cxa_deleted_virtual(void) {}
11+
extern "C" int __cxa_atexit(void (*func) (void *), void * arg, void * dso_handle) {
12+
return 0;
1613
}
1714

18-
void __cxa_pure_virtual(void) {
19-
std::terminate();
20-
}
15+
namespace std {
16+
void __throw_length_error(const char* __s __attribute__((unused))) {}
17+
};
2118

22-
void __cxa_deleted_virtual(void) {
23-
std::terminate();
19+
extern "C" int strcmp(const char* s1, const char* s2) {
20+
while(*s1 && (*s1 == *s2))
21+
{
22+
s1++;
23+
s2++;
24+
}
25+
return *(const unsigned char*)s1 - *(const unsigned char*)s2;
2426
}

Diff for: variants/llext/linker_script.ld

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FORCE_COMMON_ALLOCATION
1+
FORCE_GROUP_ALLOCATION
22

33
SECTIONS {
44

@@ -15,6 +15,12 @@ SECTIONS {
1515
*(.comment.*)
1616
*(.llvmbc)
1717
*(.llvmcmd)
18+
*(.eh_frame)
19+
*stdexcept.o
20+
*eh_*.o
21+
*cow-stdexcept.o
22+
*functexcept.o
23+
*cow-string-inst.o
1824
}
1925

2026
.text 0x00000000 : ALIGN(4) {

0 commit comments

Comments
 (0)