Skip to content

Commit d659364

Browse files
authored
[Support][Cygwin] Fix handling of Process symbol lookup. (#143072)
In Unix/DynamicLibrary.inc, it was already known that Cygwin required use of `RTLD_DEFAULT` as the `Handle` parameter to `DLSym` to search all modules for a symbol. Unfortunately, RTLD_DEFAULT is defined as NULL, so the existing checks of the `Process` handle meant `DLSym` would never be called on Cygwin. Use the existing `&Invalid` sentinel instead of `nullptr` for the `Process` handle.
1 parent e7739eb commit d659364

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

llvm/lib/Support/DynamicLibrary.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace llvm::sys;
2525
class DynamicLibrary::HandleSet {
2626
typedef std::vector<void *> HandleList;
2727
HandleList Handles;
28-
void *Process = nullptr;
28+
void *Process = &Invalid;
2929

3030
public:
3131
static void *DLOpen(const char *Filename, std::string *Err);
@@ -58,7 +58,7 @@ class DynamicLibrary::HandleSet {
5858
Handles.push_back(Handle);
5959
} else {
6060
#ifndef _WIN32
61-
if (Process) {
61+
if (Process != &Invalid) {
6262
if (CanClose)
6363
DLClose(Process);
6464
if (Process == Handle)
@@ -97,11 +97,11 @@ class DynamicLibrary::HandleSet {
9797
assert(!((Order & SO_LoadedFirst) && (Order & SO_LoadedLast)) &&
9898
"Invalid Ordering");
9999

100-
if (!Process || (Order & SO_LoadedFirst)) {
100+
if (Process == &Invalid || (Order & SO_LoadedFirst)) {
101101
if (void *Ptr = LibLookup(Symbol, Order))
102102
return Ptr;
103103
}
104-
if (Process) {
104+
if (Process != &Invalid) {
105105
// Use OS facilities to search the current binary and all loaded libs.
106106
if (void *Ptr = DLSym(Process, Symbol))
107107
return Ptr;

llvm/lib/Support/Unix/DynamicLibrary.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ DynamicLibrary::HandleSet::~HandleSet() {
1717
// Close the libraries in reverse order.
1818
for (void *Handle : llvm::reverse(Handles))
1919
::dlclose(Handle);
20-
if (Process)
20+
if (Process != &Invalid)
2121
::dlclose(Process);
2222

2323
// llvm_shutdown called, Return to default

llvm/lib/Support/Windows/DynamicLibrary.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ DynamicLibrary::HandleSet::~HandleSet() {
2626
FreeLibrary(HMODULE(Handle));
2727

2828
// 'Process' should not be released on Windows.
29-
assert((!Process || Process == this) && "Bad Handle");
29+
assert((Process == &Invalid || Process == this) && "Bad Handle");
3030
// llvm_shutdown called, Return to default
3131
DynamicLibrary::SearchOrder = DynamicLibrary::SO_Linker;
3232
}
@@ -60,7 +60,7 @@ static DynamicLibrary::HandleSet *IsOpenedHandlesInstance(void *Handle) {
6060

6161
void DynamicLibrary::HandleSet::DLClose(void *Handle) {
6262
if (HandleSet *HS = IsOpenedHandlesInstance(Handle))
63-
HS->Process = nullptr; // Just drop the *Process* handle.
63+
HS->Process = &Invalid; // Just drop the *Process* handle.
6464
else
6565
FreeLibrary((HMODULE)Handle);
6666
}
@@ -89,7 +89,7 @@ void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) {
8989
return (void *)uintptr_t(GetProcAddress((HMODULE)Handle, Symbol));
9090

9191
// Could have done a dlclose on the *Process* handle
92-
if (!HS->Process)
92+
if (HS->Process == &Invalid)
9393
return nullptr;
9494

9595
// Trials indicate EnumProcessModulesEx is consistantly faster than using

0 commit comments

Comments
 (0)