Skip to content

Commit fc5d600

Browse files
committed
Fixed CORE-5474 on Darwin
1 parent 48a55c1 commit fc5d600

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/jrd/os/darwin/mod_loader.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "../jrd/os/mod_loader.h"
3131
#include "../../common.h"
32+
#include "../jrd/os/path_utils.h"
3233
#include <unistd.h>
3334
#include <sys/types.h>
3435
#include <sys/stat.h>
@@ -40,14 +41,16 @@
4041
class DlfcnModule : public ModuleLoader::Module
4142
{
4243
public:
43-
DlfcnModule(void* m)
44-
: module(m)
44+
DlfcnModule(MemoryPool& pool, const Firebird::PathName& aFileName, void* m)
45+
: fileName(pool, aFileName),
46+
module(m)
4547
{}
4648

4749
~DlfcnModule();
48-
void *findSymbol (const Firebird::string&);
50+
void *findSymbol(const Firebird::string&);
4951

5052
private:
53+
Firebird::PathName fileName;
5154
void *module;
5255
};
5356

@@ -72,9 +75,9 @@ void ModuleLoader::doctorModuleExtention(Firebird::PathName& name)
7275
}
7376

7477
#ifdef DEV_BUILD
75-
#define FB_RTLD_MODE RTLD_NOW
78+
#define FB_RTLD_MODE RTLD_NOW // make sure nothing left unresolved
7679
#else
77-
#define FB_RTLD_MODE RTLD_LAZY
80+
#define FB_RTLD_MODE RTLD_LAZY // save time when loading library
7881
#endif
7982

8083
ModuleLoader::Module* ModuleLoader::loadModule(const Firebird::PathName& modPath)
@@ -83,21 +86,19 @@ ModuleLoader::Module* ModuleLoader::loadModule(const Firebird::PathName& modPath
8386
if (module == NULL)
8487
{
8588
#ifdef DEBUG_LOADER
86-
fprintf(stderr, "load error: %s: %s\n", modPath.c_str(), dlerror());
89+
fprintf(stderr, "load error: %s: %s\n", modPath.c_str(), dlerror());
8790
#endif // DEBUG_LOADER
88-
return 0;
91+
return 0;
8992
}
90-
91-
return FB_NEW(*getDefaultMemoryPool()) DlfcnModule(module);
93+
94+
return FB_NEW(*getDefaultMemoryPool()) DlfcnModule(*getDefaultMemoryPool(), modPath, module);
9295
}
9396

9497

9598
DlfcnModule::~DlfcnModule()
9699
{
97100
if (module)
98-
{
99101
dlclose(module);
100-
}
101102
}
102103

103104
void* DlfcnModule::findSymbol(const Firebird::string& symName)
@@ -108,8 +109,17 @@ void* DlfcnModule::findSymbol(const Firebird::string& symName)
108109
Firebird::string newSym = '_' + symName;
109110
result = dlsym(module, newSym.c_str());
110111
}
111-
return result;
112112

113+
if (!PathUtils::isRelative(fileName))
114+
{
115+
Dl_info info;
116+
if (!dladdr(result, &info))
117+
return NULL;
118+
if (fileName != info.dli_fname)
119+
return NULL;
120+
}
121+
122+
return result;
113123
}
114124

115125

0 commit comments

Comments
 (0)