View Issue Details

IDProjectCategoryView StatusLast Update
0036105FPCPatchpublic2019-10-02 17:43
ReporterAnton KavalenkaAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0036105: dl: Small improvement that make possible GetModuleFileName implementation for UN*X
DescriptionPatch inspired by https://www.boost.org/doc/libs/1_71_0/boost/dll/detail/posix/path_from_handle.hpp
For getting DLL file name by handle.
TagsNo tags attached.
Fixed in Revision43097
FPCOldBugId
FPCTarget4.0.0
Attached Files
  • dl.diff (1,600 bytes)
    Index: dl.pp
    ===================================================================
    --- dl.pp	(revision 43061)
    +++ dl.pp	(working copy)
    @@ -66,6 +66,8 @@
       RTLD_NEXT         = pointer(-1);
       {$ifdef LINUX}
       RTLD_DEFAULT      = nil;
    +  RTLD_NOLOAD = $00004; // GLIBC 2.2 and above
    +  RTLD_DI_LINKMAP = 2;
       {$endif}
       {$ifdef BSD}
       RTLD_DEFAULT      = pointer(-2);
    @@ -90,11 +92,30 @@
     {$endif}
     function dlclose(Lib : Pointer) : Longint; cdecl; external libdl;
     function dlerror() : Pchar; cdecl; external libdl;
    +
     { overloaded for compatibility with hmodule }
     function dlsym(Lib : PtrInt; Name : Pchar) : Pointer; cdecl; external Libdl;
     function dlclose(Lib : PtrInt) : Longint; cdecl; external libdl;
     function dladdr(Lib: pointer; info: Pdl_info): Longint; cdecl; {$if not defined(aix) and not defined(android)} external; {$endif}
     
    +type
    +  plink_map = ^link_map;
    +  link_map = record
    +    l_addr:pointer;  { Difference between the address in the ELF file and the address in memory }
    +    l_name:Pchar;  { Absolute pathname where object was found }
    +    l_ld:pointer;    { Dynamic section of the shared object }
    +    l_next, l_prev:^link_map; { Chain of loaded objects }
    +    {Plus additional fields private to the implementation }
    +  end;
    +
    +{$if defined(BSD) or defined(LINUX)}
    +function dlinfo(Lib:pointer;request:longint;info:pointer):longint;cdecl;external Libdl;
    +{$else}
    +{ Fortunately investigating the sources of open source projects brought the understanding, that
    +  `handle` is just a `struct link_map*` that contains full library name.}
    +{$endif}
    +
    +
     implementation
     
     uses
    
    dl.diff (1,600 bytes)

Activities

Anton Kavalenka

2019-09-25 15:02

reporter  

dl.diff (1,600 bytes)
Index: dl.pp
===================================================================
--- dl.pp	(revision 43061)
+++ dl.pp	(working copy)
@@ -66,6 +66,8 @@
   RTLD_NEXT         = pointer(-1);
   {$ifdef LINUX}
   RTLD_DEFAULT      = nil;
+  RTLD_NOLOAD = $00004; // GLIBC 2.2 and above
+  RTLD_DI_LINKMAP = 2;
   {$endif}
   {$ifdef BSD}
   RTLD_DEFAULT      = pointer(-2);
@@ -90,11 +92,30 @@
 {$endif}
 function dlclose(Lib : Pointer) : Longint; cdecl; external libdl;
 function dlerror() : Pchar; cdecl; external libdl;
+
 { overloaded for compatibility with hmodule }
 function dlsym(Lib : PtrInt; Name : Pchar) : Pointer; cdecl; external Libdl;
 function dlclose(Lib : PtrInt) : Longint; cdecl; external libdl;
 function dladdr(Lib: pointer; info: Pdl_info): Longint; cdecl; {$if not defined(aix) and not defined(android)} external; {$endif}
 
+type
+  plink_map = ^link_map;
+  link_map = record
+    l_addr:pointer;  { Difference between the address in the ELF file and the address in memory }
+    l_name:Pchar;  { Absolute pathname where object was found }
+    l_ld:pointer;    { Dynamic section of the shared object }
+    l_next, l_prev:^link_map; { Chain of loaded objects }
+    {Plus additional fields private to the implementation }
+  end;
+
+{$if defined(BSD) or defined(LINUX)}
+function dlinfo(Lib:pointer;request:longint;info:pointer):longint;cdecl;external Libdl;
+{$else}
+{ Fortunately investigating the sources of open source projects brought the understanding, that
+  `handle` is just a `struct link_map*` that contains full library name.}
+{$endif}
+
+
 implementation
 
 uses
dl.diff (1,600 bytes)

Michael Van Canneyt

2019-09-30 00:31

administrator   ~0118196

Applied, thanks for the patch !

Issue History

Date Modified Username Field Change
2019-09-25 15:02 Anton Kavalenka New Issue
2019-09-25 15:02 Anton Kavalenka File Added: dl.diff
2019-09-30 00:31 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-09-30 00:31 Michael Van Canneyt Status new => resolved
2019-09-30 00:31 Michael Van Canneyt Resolution open => fixed
2019-09-30 00:31 Michael Van Canneyt Fixed in Version => 3.3.1
2019-09-30 00:31 Michael Van Canneyt Fixed in Revision => 43097
2019-09-30 00:31 Michael Van Canneyt FPCTarget => 4.0.0
2019-09-30 00:31 Michael Van Canneyt Note Added: 0118196
2019-10-02 17:43 Anton Kavalenka Status resolved => closed