Skip to content

Commit 208388e

Browse files
committed
Swift: hard code libc.dylib path on macOS
Also, handle the corner case where loading libc fails.
1 parent 3084eda commit 208388e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

swift/extractor/remapping/SwiftFileInterception.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include "swift/extractor/infra/file/FileHash.h"
1313

1414
#ifdef __APPLE__
15-
#define SHARED_LIBC "libc.dylib"
15+
// path is hardcoded as otherwise redirection could break when setting DYLD_FALLBACK_LIBRARY_PATH
16+
#define SHARED_LIBC "/usr/lib/libc.dylib"
1617
#define FILE_CREATION_MODE O_CREAT
1718
#else
1819
#define SHARED_LIBC "libc.so.6"
@@ -24,8 +25,16 @@ namespace fs = std::filesystem;
2425
namespace {
2526
namespace original {
2627

28+
void* openLibC() {
29+
if (auto ret = dlopen(SHARED_LIBC, RTLD_LAZY)) {
30+
return ret;
31+
}
32+
std::cerr << "Unable to dlopen " SHARED_LIBC "!\n";
33+
std::abort();
34+
}
35+
2736
void* libc() {
28-
static auto ret = dlopen(SHARED_LIBC, RTLD_LAZY);
37+
static auto ret = openLibC();
2938
return ret;
3039
}
3140

0 commit comments

Comments
 (0)