-
Notifications
You must be signed in to change notification settings - Fork 11
Add libstatic configuration support for reading symbols from static libraries #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
6a83de3
0e95f6a
3d094ed
f04b76b
72448b2
bc80a8d
e47e679
4aad484
09012ef
f9844c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,7 +165,7 @@ func TestGenDylibPaths(t *testing.T) { | |
| } | ||
|
|
||
| if err != nil { | ||
| t.Fatalf("expected no error, got %w", err) | ||
| t.Fatalf("expected no error, got %v", err) | ||
| } | ||
|
|
||
| if !reflect.DeepEqual(notFounds, tc.wantNotFound) { | ||
|
|
@@ -188,3 +188,85 @@ func TestGenDylibPaths(t *testing.T) { | |
|
|
||
| } | ||
| } | ||
|
|
||
| func TestLibModeConfiguration(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| libName string | ||
| mode symbol.Mode | ||
| expected string // expected file extension | ||
| }{ | ||
| { | ||
| name: "Dynamic library mode", | ||
| libName: "test", | ||
| mode: symbol.ModeDynamic, | ||
| expected: getExpectedDynamicExt(), | ||
| }, | ||
|
||
| { | ||
| name: "Static library mode", | ||
| libName: "test", | ||
| mode: symbol.ModeStatic, | ||
| expected: ".a", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| tempDir, err := os.MkdirTemp("", "libmode_test") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer os.RemoveAll(tempDir) | ||
|
|
||
| // Create the expected library file | ||
| expectedFileName := fmt.Sprintf("lib%s%s", tc.libName, tc.expected) | ||
| expectedPath := filepath.Join(tempDir, expectedFileName) | ||
|
|
||
| file, err := os.Create(expectedPath) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create test file %s: %v", expectedPath, err) | ||
| } | ||
| file.Close() | ||
|
|
||
| // Test that the library can be found with the correct mode | ||
| foundPath, err := symbol.FindLibFile(tempDir, tc.libName, tc.mode) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if foundPath != expectedPath { | ||
| t.Errorf("Expected path %s, got %s", expectedPath, foundPath) | ||
| } | ||
|
|
||
| // Test that the Libs.Files method respects the mode | ||
| libs := &symg.Libs{ | ||
| Paths: []string{tempDir}, | ||
| Names: []string{tc.libName}, | ||
| } | ||
|
|
||
| foundPaths, notFound, err := libs.Files([]string{}, tc.mode) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if len(notFound) > 0 { | ||
| t.Errorf("Expected no missing libraries, but found: %v", notFound) | ||
| } | ||
|
|
||
| if len(foundPaths) != 1 { | ||
| t.Errorf("Expected 1 library path, got %d", len(foundPaths)) | ||
| } | ||
|
|
||
| if foundPaths[0] != expectedPath { | ||
| t.Errorf("Expected path %s, got %s", expectedPath, foundPaths[0]) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func getExpectedDynamicExt() string { | ||
| if runtime.GOOS == "linux" { | ||
| return ".so" | ||
| } | ||
| return ".dylib" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # 1 "/home/runner/work/llcppg/llcppg/parser/testdata/func/hfile/forwarddecl.h" | ||
| # 1 "<built-in>" 1 | ||
| # 1 "<built-in>" 3 | ||
| # 453 "<built-in>" 3 | ||
| # 1 "<command line>" 1 | ||
| # 1 "<built-in>" 2 | ||
| # 1 "/home/runner/work/llcppg/llcppg/parser/testdata/func/hfile/forwarddecl.h" 2 | ||
| void foo0(); | ||
| void foo1(int a); | ||
| void foo2(int a,...); | ||
luoliwoshang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fail in
llgo test ./...at ci. https://github.com/goplus/llcppg/actions/runs/15917214614/job/44897037881. you can runllgo test .in these package to check the actuall error. because this component (llcppsymg) is compile by llgoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need install llgo from source code, you can see https://github.com/goplus/llgo?tab=readme-ov-file#how-to-install,and this project is current with the main branch of llgo, so you need install from source code , and pay attention,the llvm version is need fit the llgo nessaray,and you can also know the install method from the ci's yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot