Skip to content

Commit 55c1b60

Browse files
committed
android: load conformance tables in main executable properly; fixes swiftlang#5
1 parent 615f007 commit 55c1b60

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

stdlib/public/runtime/Casting.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -2401,10 +2401,10 @@ static void _addImageProtocolConformances(const mach_header *mh,
24012401
#include <climits>
24022402
#include <cstdio>
24032403
#include <unordered_set>
2404+
#include <unistd.h>
24042405

2405-
static void _addImageProtocolConformances(std::string const& name) {
2406-
// FIXME: Android: special case the current executable?
2407-
void *handle = dlopen(name.c_str(), RTLD_LAZY);
2406+
static void _addImageProtocolConformances(const char* name) {
2407+
void *handle = dlopen(name, RTLD_LAZY);
24082408
if (!handle)
24092409
return; // not a shared library
24102410
auto conformances = reinterpret_cast<const uint8_t*>(
@@ -2425,11 +2425,17 @@ static void _addImageProtocolConformances(std::string const& name) {
24252425
dlclose(handle);
24262426
}
24272427

2428-
static void android_iterate_libs(void (*callback)(std::string const&)) {
2428+
static void android_iterate_libs(void (*callback)(const char*)) {
24292429
std::unordered_set<std::string> already;
24302430
FILE* f = fopen("/proc/self/maps", "r");
24312431
if (!f)
24322432
return;
2433+
char ownname[PATH_MAX + 1];
2434+
if (readlink("/proc/self/exe", ownname, sizeof(ownname)) == -1) {
2435+
fprintf(stderr, "swift: can't find path of executable\n");
2436+
ownname[0] = '\0';
2437+
}
2438+
24332439
char name[PATH_MAX + 1];
24342440
char perms[4 + 1];
24352441
while (fscanf(f, " %*s %4c %*s %*s %*s%*[ ]%[^\n]", perms, name) > 0) {
@@ -2441,7 +2447,12 @@ static void android_iterate_libs(void (*callback)(std::string const&)) {
24412447
if (already.count(name_str) != 0)
24422448
continue;
24432449
already.insert(name_str);
2444-
callback(name_str);
2450+
const char* libname = name_str.c_str();
2451+
if (strcmp(libname, ownname) == 0) {
2452+
// need to pass null if opening main executable
2453+
libname = nullptr;
2454+
}
2455+
callback(libname);
24452456
}
24462457
fclose(f);
24472458
}

utils/build-script-impl

-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ fi
10831083
if [[ "$DISTCC" ]] ; then
10841084
BUILD_ARGS="${BUILD_ARGS} -j $(distcc -j)"
10851085
fi
1086-
BUILD_ARGS="${BUILD_ARGS} -j2"
10871086

10881087
case "${CMAKE_GENERATOR}" in
10891088
Ninja)

0 commit comments

Comments
 (0)