|
19 | 19 | #if defined(__ELF__) || defined(__ANDROID__)
|
20 | 20 |
|
21 | 21 | #include "ImageInspection.h"
|
| 22 | +#include "swift/Runtime/Debug.h" |
22 | 23 | #include <dlfcn.h>
|
23 | 24 | #include <elf.h>
|
24 | 25 | #include <link.h>
|
@@ -63,17 +64,19 @@ static InspectArgs TypeMetadataRecordArgs = {
|
63 | 64 | static SectionInfo getSectionInfo(const char *imageName,
|
64 | 65 | const char *sectionName) {
|
65 | 66 | SectionInfo sectionInfo = { 0, nullptr };
|
66 |
| - void *handle = dlopen(imageName, RTLD_LAZY); |
67 |
| - if (handle) { |
68 |
| - void *symbol = dlsym(handle, sectionName); |
69 |
| - if (symbol) { |
70 |
| - // Extract the size of the section data from the head of the section. |
71 |
| - const char *section = reinterpret_cast<const char *>(symbol); |
72 |
| - memcpy(§ionInfo.size, section, sizeof(uint64_t)); |
73 |
| - sectionInfo.data = section + sizeof(uint64_t); |
74 |
| - } |
75 |
| - dlclose(handle); |
| 67 | + void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD); |
| 68 | + if (!handle) { |
| 69 | + fatalError(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName, |
| 70 | + dlerror()); |
| 71 | + } |
| 72 | + void *symbol = dlsym(handle, sectionName); |
| 73 | + if (symbol) { |
| 74 | + // Extract the size of the section data from the head of the section. |
| 75 | + const char *section = reinterpret_cast<const char *>(symbol); |
| 76 | + memcpy(§ionInfo.size, section, sizeof(uint64_t)); |
| 77 | + sectionInfo.data = section + sizeof(uint64_t); |
76 | 78 | }
|
| 79 | + dlclose(handle); |
77 | 80 | return sectionInfo;
|
78 | 81 | }
|
79 | 82 |
|
|
0 commit comments