Skip to content

Commit de7fe6a

Browse files
zhuoweimodocache
authored andcommitted
android: load conformance tables in main executable properly; fixes swiftlang#5
1 parent ff7dd08 commit de7fe6a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Diff for: stdlib/public/runtime/ProtocolConformance.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ static void _addImageProtocolConformances(const mach_header *mh,
312312
#include <climits>
313313
#include <cstdio>
314314
#include <unordered_set>
315+
#include <unistd.h>
315316

316-
static void _addImageProtocolConformances(std::string const& name) {
317-
// FIXME: Android: special case the current executable?
318-
void *handle = dlopen(name.c_str(), RTLD_LAZY);
317+
static void _addImageProtocolConformances(const char *name) {
318+
void *handle = dlopen(name, RTLD_LAZY);
319319
if (!handle)
320320
return; // not a shared library
321321
auto conformances = reinterpret_cast<const uint8_t*>(
@@ -336,11 +336,17 @@ static void _addImageProtocolConformances(std::string const& name) {
336336
dlclose(handle);
337337
}
338338

339-
static void android_iterate_libs(void (*callback)(std::string const&)) {
339+
static void android_iterate_libs(void (*callback)(const char*)) {
340340
std::unordered_set<std::string> already;
341341
FILE* f = fopen("/proc/self/maps", "r");
342342
if (!f)
343343
return;
344+
char ownname[PATH_MAX + 1];
345+
if (readlink("/proc/self/exe", ownname, sizeof(ownname)) == -1) {
346+
fprintf(stderr, "swift: can't find path of executable\n");
347+
ownname[0] = '\0';
348+
}
349+
344350
char name[PATH_MAX + 1];
345351
char perms[4 + 1];
346352
while (fscanf(f, " %*s %4c %*s %*s %*s%*[ ]%[^\n]", perms, name) > 0) {
@@ -352,7 +358,12 @@ static void android_iterate_libs(void (*callback)(std::string const&)) {
352358
if (already.count(name_str) != 0)
353359
continue;
354360
already.insert(name_str);
355-
callback(name_str);
361+
const char* libname = name_str.c_str();
362+
if (strcmp(libname, ownname) == 0) {
363+
// need to pass null if opening main executable
364+
libname = nullptr;
365+
}
366+
callback(libname);
356367
}
357368
fclose(f);
358369
}

Diff for: utils/build-script-impl

-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ CMAKE_JOBS="${BUILD_JOBS}"
11101110
if [[ "${DISTCC}" ]] ; then
11111111
CMAKE_JOBS="$(distcc -j)"
11121112
fi
1113-
BUILD_ARGS="${BUILD_ARGS} -j2"
11141113

11151114
case "${CMAKE_GENERATOR}" in
11161115
Ninja)

0 commit comments

Comments
 (0)