This might be the root cause of the problem in my previous question: Remove exception/unwind functions from Android NDK shared objects. I have distilled it into a minimal working example.
It happens in both C and C++ regardless of C/C++ version. (I thought C wasn't supposed to have exceptions?)
13472-byte shared object with exception-handling functions:
int buf[1];
__attribute__((optimize("-Os"))) void bar() {
buf[0] = 0;
}
__attribute__((visibility("default"))) void foo() {
bar();
}
5180-byte shared object without exception handling:
int buf[1];
void bar() {
buf[0] = 0;
}
__attribute__((visibility("default"))) void foo() {
bar();
}
Compiler flags:
LOCAL_C_INCLUDES :=
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O3 -flto -Wall -D__ANDROID__ -fvisibility=hidden -s
LOCAL_CPPFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O3 -flto -Wall -D__ANDROID__ -fvisibility=hidden -s
LOCAL_CFLAGS += -pipe
LOCAL_CPPFLAGS += -pipe
LOCAL_CFLAGS += -fno-exceptions -fno-rtti # IGNORED
LOCAL_CPPFLAGS += -fno-exceptions -fno-rtti # IGNORED
__attribute__((optimize("-Os")))
isn't useless, but how come it generates this exception-handling file size bloat which I definitely don't need?
How to fix this?
Edit: To show that it isn't just getting optimized away with -O3, this is also 5180 bytes without exception handling:
int buf[100];
void bar(int i, int j) {
buf[i] = j;
}
__attribute__((visibility("default"))) void foo(int i, int j) {
bar(i, j);
}
__attribute__((visibility("default"))) int getFoo(int i) {
return buf[i];
}
__attribute__((visibility("default"))) int* getBuf() {
return buf;
}