Skip to content

Commit e39f82f

Browse files
antonmesGreg Parker
authored andcommitted
[FreeBSD] Fix a crash of produced executable
1 parent 18da29d commit e39f82f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

stdlib/public/runtime/ImageInspectionELF.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <link.h>
2828
#include <string.h>
2929

30-
#if defined(__ANDROID__)
30+
#if defined(__ANDROID__) || defined(__FreeBSD__)
3131
#include "llvm/ADT/StringRef.h"
3232
#endif
3333

@@ -72,9 +72,14 @@ static SectionInfo getSectionInfo(const char *imageName,
7272
SectionInfo sectionInfo = { 0, nullptr };
7373
void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD);
7474
if (!handle) {
75-
#ifdef __ANDROID__
75+
#if defined(__ANDROID__) || defined(__FreeBSD__)
76+
#if defined(__ANDROID__)
77+
const char *systemPath = "/system/lib";
78+
#elif defined(__FreeBSD__)
79+
const char *systemPath = "/libexec";
80+
#endif
7681
llvm::StringRef imagePath = llvm::StringRef(imageName);
77-
if (imagePath.startswith("/system/lib") ||
82+
if (imagePath.startswith(systemPath) ||
7883
(imageName && !imagePath.endswith(".so"))) {
7984
return sectionInfo;
8085
}

0 commit comments

Comments
 (0)