Update crt0

This commit is contained in:
topjohnwu 2024-03-04 16:42:25 -08:00
parent 2290ddeb89
commit a6ff3672af
3 changed files with 2 additions and 36 deletions

View File

@ -112,7 +112,7 @@ LOCAL_LDFLAGS := -static -T src/lto_fix.lds
ifdef B_CRT0
LOCAL_STATIC_LIBRARIES += crt0
LOCAL_CFLAGS += -DUSE_MUSL_PRINTF
LOCAL_LDFLAGS := -lm -Wl,--wrap=qsort
LOCAL_LDFLAGS := -lm
endif
include $(BUILD_EXECUTABLE)

View File

@ -290,37 +290,3 @@ const char *rust::Utf8CStr::data() const {
size_t rust::Utf8CStr::length() const {
return cxx$utf8str$len(this);
}
#define elm(i) (p + (i * size))
// An alternative qsort implementation. Only used when linking with crt0
extern "C"
void __wrap_qsort(void *ptr, size_t count, size_t size, int (*comp)(const void*, const void*)) {
// Create the index array
uint8_t *p = (uint8_t *) ptr;
vector<int> v(count);
std::iota(v.begin(), v.end(), 0);
// Sort the index array
std::sort(v.begin(), v.end(), [=](int a, int b) {
return comp(elm(a), elm(b)) < 0;
});
// Reorganize the array with index array
void *t = malloc(size);
for (int i = 0; i < count; ++i) {
if (v[i] != i) {
memcpy(t, elm(i), size);
int j = i;
int k;
while (i != (k = v[j])) {
memcpy(elm(j), elm(k), size);
v[j] = j;
j = k;
}
memcpy(elm(j), t, size);
v[j] = j;
}
}
free(t);
}

@ -1 +1 @@
Subproject commit 7a03e7b0ec410d9f5e927d816261b9aff1c57fa8
Subproject commit 6ec46be760069d4645204b09b96e8dd414c3ac2e