Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8dc55f7

Browse files
HeuluckaofeiMeteorsLiu
authoredJun 5, 2025
libtool/2.4.7 (#33)
* feat: add libtool/2.4.7 Release-as: libtool/v1.0.0 * feat: add trimprefixes * chore: remove conflict trim prefix * chore: upgrade llcppg * chore: fix go.mod and remove llgo/c * chore: remove prefix * chore: fix go.mod --------- Co-authored-by: Aofei Sheng <aofei@aofeisheng.com> Co-authored-by: Rick Guo <coopticks@outlook.com>
1 parent 74f013c commit 8dc55f7

File tree

11 files changed

+390
-0
lines changed

11 files changed

+390
-0
lines changed
 

‎libtool/_demo/test/test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/goplus/lib/c"
7+
"github.com/goplus/llpkg/libtool"
8+
)
9+
10+
func main() {
11+
fmt.Println("Simple libtool demonstration")
12+
13+
// Initialize libtool
14+
ret := libtool.Dlinit()
15+
if ret != 0 {
16+
fmt.Println("Failed to initialize libtool:", c.GoString(libtool.Dlerror()))
17+
return
18+
}
19+
fmt.Println("Successfully initialized libtool")
20+
21+
// Try to load a common library (libc)
22+
libName := "libc.so.6" // Linux style
23+
handle := libtool.Dlopen(c.Str(libName))
24+
if handle == nil {
25+
libName = "libc.dylib" // macOS style
26+
handle = libtool.Dlopen(c.Str(libName))
27+
}
28+
if handle == nil {
29+
libName = "c" // Generic style
30+
handle = libtool.Dlopen(c.Str(libName))
31+
}
32+
33+
if handle != nil {
34+
fmt.Printf("Successfully opened %s\n", libName)
35+
36+
// Try to find a common function (printf)
37+
symPtr := libtool.Dlsym(handle, c.Str("printf"))
38+
if symPtr != nil {
39+
fmt.Println("Found 'printf' function")
40+
} else {
41+
fmt.Println("Symbol 'printf' not found:", c.GoString(libtool.Dlerror()))
42+
}
43+
44+
// Close the library
45+
libtool.Dlclose(handle)
46+
fmt.Println("Closed library")
47+
} else {
48+
fmt.Println("Could not open any standard library:", c.GoString(libtool.Dlerror()))
49+
}
50+
51+
// Clean up libtool
52+
libtool.Dlexit()
53+
fmt.Println("Successfully cleaned up libtool")
54+
}

‎libtool/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/goplus/llpkg/libtool
2+
3+
go 1.20
4+
5+
require github.com/goplus/lib v0.2.0

‎libtool/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/goplus/lib v0.2.0 h1:AjqkN1XK5H23wZMMlpaUYAMCDAdSBQ2NMFrLtSh7W4g=
2+
github.com/goplus/lib v0.2.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=

‎libtool/libtool_autogen_link.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package libtool
2+
3+
import _ "github.com/goplus/lib/c"
4+
5+
const LLGoPackage string = "link: $(pkg-config --libs libtool);"

‎libtool/llcppg.cfg

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "libtool",
3+
"cflags": "$(pkg-config --cflags libtool)",
4+
"libs": "$(pkg-config --libs libtool)",
5+
"include": [
6+
"ltdl.h",
7+
"libltdl/lt_dlloader.h",
8+
"libltdl/lt_error.h",
9+
"libltdl/lt_system.h"
10+
],
11+
"trimPrefixes": ["lt__","lt_", "LT_"],
12+
"cplusplus": false,
13+
"deps": [],
14+
"keepUnderScore": false,
15+
"impl": [
16+
{
17+
"files": [],
18+
"cond": {
19+
"os": [],
20+
"arch": []
21+
}
22+
}
23+
],
24+
"mix": false
25+
}

‎libtool/llcppg.pub

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
lt__advise Advise
2+
lt__handle Handle
3+
lt_dladvise Dladvise
4+
lt_dlhandle Dlhandle
5+
lt_dlhandle_interface DlhandleInterface
6+
lt_dlinfo Dlinfo
7+
lt_dlinterface_id DlinterfaceId
8+
lt_dlloader Dlloader
9+
lt_dlloader_exit DlloaderExit
10+
lt_dlloader_init DlloaderInit
11+
lt_dlloader_priority DlloaderPriority
12+
lt_dlpreload_callback_func DlpreloadCallbackFunc
13+
lt_dlsymlist Dlsymlist
14+
lt_dlvtable Dlvtable
15+
lt_find_sym FindSym
16+
lt_get_vtable GetVtable
17+
lt_module Module
18+
lt_module_close ModuleClose
19+
lt_module_open ModuleOpen
20+
lt_user_data UserData

‎libtool/llpkg.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"upstream": {
3+
"package": {
4+
"name": "libtool",
5+
"version": "2.4.7"
6+
}
7+
}
8+
}

‎libtool/lt_dlloader.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package libtool
2+
3+
import (
4+
"github.com/goplus/lib/c"
5+
_ "unsafe"
6+
)
7+
8+
const DLLOADER_H = 1
9+
10+
type Dlloader c.Pointer
11+
type Module c.Pointer
12+
type UserData c.Pointer
13+
14+
type Advise struct {
15+
Unused [8]uint8
16+
}
17+
type Dladvise *Advise
18+
19+
// llgo:type C
20+
type ModuleOpen func(UserData, *c.Char, Dladvise) Module
21+
22+
// llgo:type C
23+
type ModuleClose func(UserData, Module) c.Int
24+
25+
// llgo:type C
26+
type FindSym func(UserData, Module, *c.Char) c.Pointer
27+
28+
// llgo:type C
29+
type DlloaderInit func(UserData) c.Int
30+
31+
// llgo:type C
32+
type DlloaderExit func(UserData) c.Int
33+
type DlloaderPriority c.Int
34+
35+
const (
36+
DLLOADER_PREPEND DlloaderPriority = 0
37+
DLLOADER_APPEND DlloaderPriority = 1
38+
)
39+
40+
/*
41+
This structure defines a module loader, as populated by the get_vtable
42+
43+
entry point of each loader.
44+
*/
45+
type Dlvtable struct {
46+
Name *c.Char
47+
SymPrefix *c.Char
48+
ModuleOpen *c.Pointer
49+
ModuleClose *c.Pointer
50+
FindSym *c.Pointer
51+
DlloaderInit *c.Pointer
52+
DlloaderExit *c.Pointer
53+
DlloaderData UserData
54+
Priority DlloaderPriority
55+
}
56+
57+
// llgo:link (*Dlvtable).DlloaderAdd C.lt_dlloader_add
58+
func (recv_ *Dlvtable) DlloaderAdd() c.Int {
59+
return 0
60+
}
61+
62+
//go:linkname DlloaderNext C.lt_dlloader_next
63+
func DlloaderNext(loader Dlloader) Dlloader
64+
65+
//go:linkname DlloaderRemove C.lt_dlloader_remove
66+
func DlloaderRemove(name *c.Char) *Dlvtable
67+
68+
//go:linkname DlloaderFind C.lt_dlloader_find
69+
func DlloaderFind(name *c.Char) *Dlvtable
70+
71+
//go:linkname DlloaderGet C.lt_dlloader_get
72+
func DlloaderGet(loader Dlloader) *Dlvtable
73+
74+
// llgo:type C
75+
type GetVtable func(UserData) *Dlvtable

‎libtool/lt_error.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package libtool
2+
3+
import (
4+
"github.com/goplus/lib/c"
5+
_ "unsafe"
6+
)
7+
8+
const ERROR_H = 1
9+
const (
10+
ERROR_UNKNOWN c.Int = 0
11+
ERROR_DLOPEN_NOT_SUPPORTED c.Int = 1
12+
ERROR_INVALID_LOADER c.Int = 2
13+
ERROR_INIT_LOADER c.Int = 3
14+
ERROR_REMOVE_LOADER c.Int = 4
15+
ERROR_FILE_NOT_FOUND c.Int = 5
16+
ERROR_DEPLIB_NOT_FOUND c.Int = 6
17+
ERROR_NO_SYMBOLS c.Int = 7
18+
ERROR_CANNOT_OPEN c.Int = 8
19+
ERROR_CANNOT_CLOSE c.Int = 9
20+
ERROR_SYMBOL_NOT_FOUND c.Int = 10
21+
ERROR_NO_MEMORY c.Int = 11
22+
ERROR_INVALID_HANDLE c.Int = 12
23+
ERROR_BUFFER_OVERFLOW c.Int = 13
24+
ERROR_INVALID_ERRORCODE c.Int = 14
25+
ERROR_SHUTDOWN c.Int = 15
26+
ERROR_CLOSE_RESIDENT_MODULE c.Int = 16
27+
ERROR_INVALID_MUTEX_ARGS c.Int = 17
28+
ERROR_INVALID_POSITION c.Int = 18
29+
ERROR_CONFLICTING_FLAGS c.Int = 19
30+
ERROR_MAX c.Int = 20
31+
)
32+
33+
/* These functions are only useful from inside custom module loaders. */
34+
//go:linkname Dladderror C.lt_dladderror
35+
func Dladderror(diagnostic *c.Char) c.Int
36+
37+
//go:linkname Dlseterror C.lt_dlseterror
38+
func Dlseterror(errorcode c.Int) c.Int

‎libtool/lt_system.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package libtool
2+
3+
import _ "unsafe"
4+
5+
const SYSTEM_H = 1
6+
const FILENAME_MAX = 2048
7+
const PATHSEP_CHAR = ":"
8+
const READTEXT_MODE = "r"
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.