Skip to content

[Support][Cygwin] Fix handling of Process symbol lookup. #143072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions llvm/lib/Support/DynamicLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace llvm::sys;
class DynamicLibrary::HandleSet {
typedef std::vector<void *> HandleList;
HandleList Handles;
void *Process = nullptr;
void *Process = &Invalid;

public:
static void *DLOpen(const char *Filename, std::string *Err);
Expand Down Expand Up @@ -58,7 +58,7 @@ class DynamicLibrary::HandleSet {
Handles.push_back(Handle);
} else {
#ifndef _WIN32
if (Process) {
if (Process != &Invalid) {
if (CanClose)
DLClose(Process);
if (Process == Handle)
Expand Down Expand Up @@ -97,11 +97,11 @@ class DynamicLibrary::HandleSet {
assert(!((Order & SO_LoadedFirst) && (Order & SO_LoadedLast)) &&
"Invalid Ordering");

if (!Process || (Order & SO_LoadedFirst)) {
if (Process == &Invalid || (Order & SO_LoadedFirst)) {
if (void *Ptr = LibLookup(Symbol, Order))
return Ptr;
}
if (Process) {
if (Process != &Invalid) {
// Use OS facilities to search the current binary and all loaded libs.
if (void *Ptr = DLSym(Process, Symbol))
return Ptr;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/Unix/DynamicLibrary.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DynamicLibrary::HandleSet::~HandleSet() {
// Close the libraries in reverse order.
for (void *Handle : llvm::reverse(Handles))
::dlclose(Handle);
if (Process)
if (Process != &Invalid)
::dlclose(Process);

// llvm_shutdown called, Return to default
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Support/Windows/DynamicLibrary.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DynamicLibrary::HandleSet::~HandleSet() {
FreeLibrary(HMODULE(Handle));

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

void DynamicLibrary::HandleSet::DLClose(void *Handle) {
if (HandleSet *HS = IsOpenedHandlesInstance(Handle))
HS->Process = nullptr; // Just drop the *Process* handle.
HS->Process = &Invalid; // Just drop the *Process* handle.
else
FreeLibrary((HMODULE)Handle);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) {
return (void *)uintptr_t(GetProcAddress((HMODULE)Handle, Symbol));

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

// Trials indicate EnumProcessModulesEx is consistantly faster than using
Expand Down