dlfcn: add RTLD_DEFAULT macro value (#135)
Closes #134 --------- Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
- commit
- ee8dcecc618f5b729ba8f987cfb385e23c5d8568
- author
- Eliott Bouhana · · 2023-05-19 10:30 UTC
- committer
- GitHub · · 2023-05-19 10:30 UTC
- parent
- d888bce
- signature
- GPG Unverified
4AEE18F83AFDEB23The key is unknown
3 files · +16 -8
M dlfcn_darwin.go +5 -4
| @@ -6,10 +6,11 @@ package purego | |||
| 6 | 6 | // Source for constants: https://opensource.apple.com/source/dyld/dyld-360.14/include/dlfcn.h.auto.html | |
| 7 | 7 | ||
| 8 | 8 | const ( | |
| 9 | - | RTLD_LAZY = 0x1 // Relocations are performed at an implementation-dependent time. | |
| 10 | - | RTLD_NOW = 0x2 // Relocations are performed when the object is loaded. | |
| 11 | - | RTLD_LOCAL = 0x4 // All symbols are not made available for relocation processing by other modules. | |
| 12 | - | RTLD_GLOBAL = 0x8 // All symbols are available for relocation processing of other modules. | |
| 9 | + | RTLD_DEFAULT = ^uintptr(0) - 1 // Pseudo-handle for dlsym so search for any loaded symbol | |
| 10 | + | RTLD_LAZY = 0x1 // Relocations are performed at an implementation-dependent time. | |
| 11 | + | RTLD_NOW = 0x2 // Relocations are performed when the object is loaded. | |
| 12 | + | RTLD_LOCAL = 0x4 // All symbols are not made available for relocation processing by other modules. | |
| 13 | + | RTLD_GLOBAL = 0x8 // All symbols are available for relocation processing of other modules. | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| 15 | 16 | //go:cgo_import_dynamic purego_dlopen dlopen "/usr/lib/libSystem.B.dylib" | |
| @@ -6,10 +6,11 @@ package purego | |||||
| 6 | // Source for constants: https://opensource.apple.com/source/dyld/dyld-360.14/include/dlfcn.h.auto.html | 6 | // Source for constants: https://opensource.apple.com/source/dyld/dyld-360.14/include/dlfcn.h.auto.html | ||
| 7 | 7 | ||||
| 8 | const ( | 8 | const ( | ||
| 9 | - | RTLD_LAZY = 0x1 // Relocations are performed at an implementation-dependent time. | 9 | + | RTLD_DEFAULT = ^uintptr(0) - 1 // Pseudo-handle for dlsym so search for any loaded symbol |
| 10 | - | RTLD_NOW = 0x2 // Relocations are performed when the object is loaded. | 10 | + | RTLD_LAZY = 0x1 // Relocations are performed at an implementation-dependent time. |
| 11 | - | RTLD_LOCAL = 0x4 // All symbols are not made available for relocation processing by other modules. | 11 | + | RTLD_NOW = 0x2 // Relocations are performed when the object is loaded. |
| 12 | - | RTLD_GLOBAL = 0x8 // All symbols are available for relocation processing of other modules. | 12 | + | RTLD_LOCAL = 0x4 // All symbols are not made available for relocation processing by other modules. |
| 13 | + | RTLD_GLOBAL = 0x8 // All symbols are available for relocation processing of other modules. | |||
| 13 | ) | 14 | ) | ||
| 14 | 15 | ||||
| 15 | //go:cgo_import_dynamic purego_dlopen dlopen "/usr/lib/libSystem.B.dylib" | 16 | //go:cgo_import_dynamic purego_dlopen dlopen "/usr/lib/libSystem.B.dylib" | ||
M dlfcn_linux.go +5 -4
| @@ -6,8 +6,9 @@ package purego | |||
| 6 | 6 | // Source for constants: https://codebrowser.dev/glibc/glibc/bits/dlfcn.h.html | |
| 7 | 7 | ||
| 8 | 8 | const ( | |
| 9 | - | RTLD_LAZY = 0x00001 // Relocations are performed at an implementation-dependent time. | |
| 10 | - | RTLD_NOW = 0x00002 // Relocations are performed when the object is loaded. | |
| 11 | - | RTLD_LOCAL = 0x00000 // All symbols are not made available for relocation processing by other modules. | |
| 12 | - | RTLD_GLOBAL = 0x00100 // All symbols are available for relocation processing of other modules. | |
| 9 | + | RTLD_DEFAULT = 0x00000 // Pseudo-handle for dlsym so search for any loaded symbol | |
| 10 | + | RTLD_LAZY = 0x00001 // Relocations are performed at an implementation-dependent time. | |
| 11 | + | RTLD_NOW = 0x00002 // Relocations are performed when the object is loaded. | |
| 12 | + | RTLD_LOCAL = 0x00000 // All symbols are not made available for relocation processing by other modules. | |
| 13 | + | RTLD_GLOBAL = 0x00100 // All symbols are available for relocation processing of other modules. | |
| 13 | 14 | ) | |
| @@ -6,8 +6,9 @@ package purego | |||||
| 6 | // Source for constants: https://codebrowser.dev/glibc/glibc/bits/dlfcn.h.html | 6 | // Source for constants: https://codebrowser.dev/glibc/glibc/bits/dlfcn.h.html | ||
| 7 | 7 | ||||
| 8 | const ( | 8 | const ( | ||
| 9 | - | RTLD_LAZY = 0x00001 // Relocations are performed at an implementation-dependent time. | 9 | + | RTLD_DEFAULT = 0x00000 // Pseudo-handle for dlsym so search for any loaded symbol |
| 10 | - | RTLD_NOW = 0x00002 // Relocations are performed when the object is loaded. | 10 | + | RTLD_LAZY = 0x00001 // Relocations are performed at an implementation-dependent time. |
| 11 | - | RTLD_LOCAL = 0x00000 // All symbols are not made available for relocation processing by other modules. | 11 | + | RTLD_NOW = 0x00002 // Relocations are performed when the object is loaded. |
| 12 | - | RTLD_GLOBAL = 0x00100 // All symbols are available for relocation processing of other modules. | 12 | + | RTLD_LOCAL = 0x00000 // All symbols are not made available for relocation processing by other modules. |
| 13 | + | RTLD_GLOBAL = 0x00100 // All symbols are available for relocation processing of other modules. | |||
| 13 | ) | 14 | ) | ||
M dlfcn_test.go +6 -0
| @@ -18,6 +18,12 @@ import ( | |||
| 18 | 18 | "github.com/ebitengine/purego" | |
| 19 | 19 | ) | |
| 20 | 20 | ||
| 21 | + | func TestSimpleDlsym(t *testing.T) { | |
| 22 | + | if _, err := purego.Dlsym(purego.RTLD_DEFAULT, "dlsym"); err != nil { | |
| 23 | + | t.Errorf("Dlsym with RTLD_DEFAULT failed: %v", err) | |
| 24 | + | } | |
| 25 | + | } | |
| 26 | + | ||
| 21 | 27 | func TestNestedDlopenCall(t *testing.T) { | |
| 22 | 28 | libFileName := filepath.Join(t.TempDir(), "libdlnested.so") | |
| 23 | 29 | t.Logf("Build %v", libFileName) | |
| @@ -18,6 +18,12 @@ import ( | |||||
| 18 | "github.com/ebitengine/purego" | 18 | "github.com/ebitengine/purego" | ||
| 19 | ) | 19 | ) | ||
| 20 | 20 | ||||
| 21 | + | func TestSimpleDlsym(t *testing.T) { | |||
| 22 | + | if _, err := purego.Dlsym(purego.RTLD_DEFAULT, "dlsym"); err != nil { | |||
| 23 | + | t.Errorf("Dlsym with RTLD_DEFAULT failed: %v", err) | |||
| 24 | + | } | |||
| 25 | + | } | |||
| 26 | + | ||||
| 21 | func TestNestedDlopenCall(t *testing.T) { | 27 | func TestNestedDlopenCall(t *testing.T) { | ||
| 22 | libFileName := filepath.Join(t.TempDir(), "libdlnested.so") | 28 | libFileName := filepath.Join(t.TempDir(), "libdlnested.so") | ||
| 23 | t.Logf("Build %v", libFileName) | 29 | t.Logf("Build %v", libFileName) | ||