View Issue Details

IDProjectCategoryView StatusLast Update
0034550FPCRTLpublic2018-11-26 10:06
ReporterCCRDude Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformDarwinOSmacOS 
Product Version3.3.1 
Summary0034550: GetProcAddress for loaded .dylib returns nil for existing function with Cocoa (works with Carbon and on other platforms)
DescriptionIf I have a valid library (*.dylib), I can successfully use LoadLibrary to get a handle, but GetProcAddress returns nil, while GetLastOSError returns success.

The same test file works on other OS, and according to one forum user, even with Carbon on macOS, just not with Cocoa.
Steps To Reproduce1. Get test example from here: https://github.com/CCRDude/laz-darwin-dylib-test
2. Compile both, run test executable. Fails from 3.0.4 to todays trunk.
3. Compile for Carbon instead of Cocoa, it should work now.
4. Compile for Windows, it works.

See comments here (reproduced by others as well):
https://forum.lazarus.freepascal.org/index.php/topic,43192.msg301977.html#msg301977
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Michael Van Canneyt

2018-11-13 23:28

administrator   ~0111960

2 remarks:

1. GetLastOSError is meaningless for GetProcedureAddress functions. use GetLoadErrorStr to get errors.
If you do that, you'll get a "invalid handle passed to dlsym()" error.

2. And Cocoa/Carbon is not relevant for pure FPC programs

CCRDude

2018-11-14 07:32

reporter   ~0111962

My apologies!

Re 1. I had found GetLoadErrorStr here:
https://www.freepascal.org/docs-html/rtl/dynlibs/getloaderrorstr.html
"GetLoadErrorStr returns a textual description of the last library loading or unloading error. "
Since "GetProcedureAddress" is not a library loading or unloading action, I checked if its documentation would list an equivalent message, but found none. I recommend to update the manuals to better reflect the real behavior :)

Re 2. that was feedback I received on the forum. Just mentioned as an indicator to track differences.

Michael Van Canneyt

2018-11-14 09:11

administrator   ~0111963

The documentation is indeed somewhat misleading. I corrected it in rev. 1518.

Jonas Maebe

2018-11-18 11:23

manager   ~0112035

As documented at https://www.freepascal.org/docs-html/rtl/dynlibs/loadlibrary.html, the result of LoadLibrary is TLibHandle, not THandle. If you turn on range checking, you will also get an error about the truncation of the library handle at run time.

Issue History

Date Modified Username Field Change
2018-11-13 21:18 CCRDude New Issue
2018-11-13 23:28 Michael Van Canneyt Note Added: 0111960
2018-11-14 07:32 CCRDude Note Added: 0111962
2018-11-14 09:11 Michael Van Canneyt Note Added: 0111963
2018-11-18 11:23 Jonas Maebe Note Added: 0112035
2018-11-18 11:23 Jonas Maebe Status new => resolved
2018-11-18 11:23 Jonas Maebe Resolution open => no change required
2018-11-18 11:23 Jonas Maebe Assigned To => Jonas Maebe