-
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
Draft
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/fix-307
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+171
−4
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a83de3
Initial plan
Copilot 0e95f6a
Initial plan for adding libstatic support
Copilot 3d094ed
Implement libstatic configuration support for static library symbol r…
Copilot f04b76b
Remove unnecessary intermediate file and update .gitignore
Copilot 72448b2
Remove unnecessary .gitignore entry for *.h.i files
Copilot bc80a8d
Remove problematic TestLibModeConfiguration test to fix llgo compatib…
Copilot e47e679
Remove unexpected empty lines and add zlib-static demo for libstatic …
Copilot 4aad484
Fix symbol extraction for static libraries by removing -D flag
Copilot 09012ef
Fix zlib-static demo package name to be valid Go identifier
Copilot f9844c6
Rename zlib-static folder to zlibstatic to match package name
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "name": "zlibstatic", | ||
| "cflags": "$(pkg-config --cflags zlib)", | ||
| "libs": "$(pkg-config --libs zlib)", | ||
| "include": [ | ||
| "zconf.h", | ||
| "zlib.h" | ||
| ], | ||
| "trimPrefixes": ["Z_"], | ||
| "cplusplus": false, | ||
| "mix":true, | ||
| "deps":["c/os"], | ||
| "symMap":{ | ||
| "compress":"Compress", | ||
| "compress2":"Compress2", | ||
| "uncompress":"Uncompress", | ||
| "uncompress2":"Uncompress2", | ||
| "compressBound":"CompressBound" | ||
| }, | ||
| "libstatic": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "unsafe" | ||
| "zlibstatic" | ||
| ) | ||
|
|
||
| func main() { | ||
| ul := zlibstatic.ULong(0) | ||
| data := "Hello world" | ||
| res := ul.Crc32Z( | ||
| (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.StringData(data))), | ||
| zlibstatic.ZSizeT(uintptr(len(data))), | ||
| ) | ||
| fmt.Printf("%08x\n", res) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "unsafe" | ||
| "zlibstatic" | ||
|
|
||
| "github.com/goplus/lib/c" | ||
| ) | ||
|
|
||
| func main() { | ||
| txt := []byte("zlib is a software library used for data compression. It was created by Jean-loup Gailly and Mark Adler and first released in 1995. zlib is designed to be a free, legally unencumbered—that is, not covered by any patents—alternative to the proprietary DEFLATE compression algorithm, which is often used in software applications for data compression.The library provides functions to compress and decompress data using the DEFLATE algorithm, which is a combination of the LZ77 algorithm and Huffman coding. zlib is notable for its versatility; it can be used in a wide range of applications, from web servers and web clients compressing HTTP data, to the compression of data for storage or transmission in various file formats, such as PNG, ZIP, and GZIP.") | ||
| txtLen := zlibstatic.ULong(len(txt)) | ||
|
|
||
| for level := 0; level <= 9; level++ { | ||
| cmpSize := zlibstatic.ULongf(zlibstatic.CompressBound(txtLen)) | ||
| cmpData := make([]byte, int(cmpSize)) | ||
| data := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) | ||
| source := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) | ||
| res := zlibstatic.Compress2(data, &cmpSize, source, txtLen, c.Int(level)) | ||
| if res != zlibstatic.OK { | ||
| c.Printf(c.Str("\nCompression failed at level %d: %d\n"), level, res) | ||
| continue | ||
| } | ||
|
|
||
| c.Printf(c.Str("Compression level %d: Text length = %d, Compressed size = %d\n"), level, txtLen, cmpSize) | ||
|
|
||
| ucmpSize := zlibstatic.ULongf(txtLen) | ||
| ucmp := make([]byte, int(ucmpSize)) | ||
| ucmpData := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) | ||
| cmpSource := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) | ||
|
|
||
| unRes := zlibstatic.Uncompress(ucmpData, &ucmpSize, cmpSource, zlibstatic.ULong(cmpSize)) | ||
| if unRes != zlibstatic.OK { | ||
| c.Printf(c.Str("\nDecompression failed at level %d: %d\n"), level, unRes) | ||
| continue | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "unsafe" | ||
| "zlibstatic" | ||
|
|
||
| "github.com/goplus/lib/c" | ||
| ) | ||
|
|
||
| func main() { | ||
| txt := []byte("zlib is a software library used for data compression. It was created by Jean-loup Gailly and Mark Adler and first released in 1995. zlib is designed to be a free, legally unencumbered—that is, not covered by any patents—alternative to the proprietary DEFLATE compression algorithm, which is often used in software applications for data compression.The library provides functions to compress and decompress data using the DEFLATE algorithm, which is a combination of the LZ77 algorithm and Huffman coding. zlib is notable for its versatility; it can be used in a wide range of applications, from web servers and web clients compressing HTTP data, to the compression of data for storage or transmission in various file formats, such as PNG, ZIP, and GZIP.") | ||
| txtLen := zlibstatic.ULong(len(txt)) | ||
|
|
||
| cmpSize := zlibstatic.ULongf(zlibstatic.CompressBound(txtLen)) | ||
| cmpData := make([]byte, int(cmpSize)) | ||
| data := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(cmpData))) | ||
| txtData := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(txt))) | ||
|
|
||
| res := zlibstatic.Compress(data, &cmpSize, txtData, txtLen) | ||
| if res != zlibstatic.OK { | ||
| c.Printf(c.Str("\nCompression failed: %d\n"), res) | ||
| return | ||
| } | ||
|
|
||
| c.Printf(c.Str("Text length = %d, Compressed size = %d\n"), txtLen, cmpSize) | ||
|
|
||
| ucmpSize := zlibstatic.ULongf(txtLen) | ||
| ucmp := make([]byte, int(ucmpSize)) | ||
| ucmpPtr := (*zlibstatic.Bytef)(unsafe.Pointer(unsafe.SliceData(ucmp))) | ||
|
|
||
| unRes := zlibstatic.Uncompress(ucmpPtr, &ucmpSize, data, zlibstatic.ULong(cmpSize)) | ||
| c.Printf(c.Str("Decompression result = %d, Decompressed size %d\n"), unRes, ucmpSize) | ||
|
|
||
| if unRes != zlibstatic.OK { | ||
| c.Printf(c.Str("\nDecompression failed: %d\n"), unRes) | ||
| return | ||
| } | ||
|
|
||
| c.Printf(c.Str("Decompressed data: \n")) | ||
| for i := 0; i < int(ucmpSize); i++ { | ||
| c.Printf(c.Str("%c"), ucmp[i]) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "zlibstatic", | ||
| "cflags": "$(pkg-config --cflags zlib)", | ||
| "libs": "$(pkg-config --libs zlib)", | ||
| "include": [ | ||
| "zconf.h", | ||
| "zlib.h" | ||
| ], | ||
| "trimPrefixes": ["Z_"], | ||
| "cplusplus": false, | ||
| "deps":["c/os"], | ||
| "symMap":{ | ||
| "compress":"Compress", | ||
| "compress2":"Compress2", | ||
| "uncompress":"Uncompress", | ||
| "uncompress2":"Uncompress2", | ||
| "compressBound":"CompressBound" | ||
| }, | ||
| "libstatic": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
i think copy the demo and create lot's of same test code is reduant. and with the static lib mode it's just the
libstaticfield different. so i think we maybe can use a llcppgtest 's flag to determine add thelibstaticfield to fetch static symbol in llcppgtest . what about your view? @MeteorsLiuThere 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.
LGTM
Uh oh!
There was an error while loading. Please reload this page.
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.
Related issue: #477