-
Notifications
You must be signed in to change notification settings - Fork 91
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
New offset generator only uses local version of Go for stdlib offsets #271
Comments
Given the switch was to address the problem that modern versions of the Go binary do not have DWARF symbols, it might make sense to look into using package main
import (
"fmt"
"net/http"
"reflect"
)
func fieldOffsetByName(rt reflect.Type, name string) uintptr {
f, ok := rt.FieldByName(name)
if !ok {
return 0
}
return f.Offset
}
func main() {
r := &http.Request{}
rt := reflect.TypeOf(r).Elem()
fmt.Println("Request.Header offset:", fieldOffsetByName(rt, "Header"))
fmt.Println("Request.Method offset:", fieldOffsetByName(rt, "Method"))
fmt.Println("Request.RemoteAddr offset:", fieldOffsetByName(rt, "RemoteAddr"))
fmt.Println("Request.URL offset:", fieldOffsetByName(rt, "URL"))
fmt.Println("Request.ctx offset:", fieldOffsetByName(rt, "ctx"))
} $ go version
go version go1.21.0 linux/amd64
$ go run .
Request.Header offset: 56
Request.Method offset: 0
Request.RemoteAddr offset: 176
Request.URL offset: 16
Request.ctx offset: 232 |
Reflect won't work for unexported types (i.e. |
The previous approach was to download the go binaries and find the offset with elf and DWARF (using code that analyzes the binary). As I understand there are two possible solutions, both require recompiling a go application with all the different versions:
|
I have an implementation of this in #268 that generates the compatibility docs. I'm looking at the unifying the approach into the offset-tracker. |
This hasn't changed (https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/net/url/url.go;l=362), but the tooling is broke (#271).
This hasn't changed (https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/net/url/url.go;l=362), but the tooling is broke (#271).
* Use internal/pkg/inject data model for offsets * Remove offset/schema * Add GetOffset method to TrackedOffsets * Use data.GetOffset instead of getFieldOffset * Use data.GetOffset instead of searchOffset * Rename injector_test.go to data_test.go * Update offsets * Use internal for kind tests * Run go mod tidy * Expand offset tests * Manually update net/url.URL.Path offset This hasn't changed (https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/net/url/url.go;l=362), but the tooling is broke (#271). * Fix lint
Testing this issue against #273 I get the following added to the offsets_results.json: + "net/http.MaxBytesError": {
+ "Limit": [
+ {
+ "versions": {
+ "oldest": "1.19.0",
+ "newest": "1.21.1"
+ },
+ "offsets": [
+ {
+ "offset": 0,
+ "since": "1.19.0"
+ }
+ ]
+ }
+ ]
+ }, Which indicates it does indeed resolve this issue. |
Describe the bug
The recent change to the offset generator only generates offsets for the version of Go used to run the generator.
Environment
uname -s -r -v -m -p -o Linux 6.4.11-arch2-1 #1 SMP PREEMPT_DYNAMIC Sat, 19 Aug 2023 15:38:34 +0000 x86_64 unknown GNU/Linux
To Reproduce
Update code:
Using a go.mod with version other than MAJOR.MINOR only works in Go 1.21. Changing to work for all versions of Go >= 1.12.
Ensure
MaxBytesError
is included in the DWARF symbols.Get the offset for
MaxBytesError
which was added in Go 1.19.Using Go 1.21 on my local system and running:
OFFSETS_OUTPUT_FILE="../pkg/inject/offset_results.json" go run main.go
And in
../pkg/inject/offset_results.json
:Given this type and field were added in Go 1.19, this is incorrect.
By contrast, running with Go 1.18:
go install golang.org/dl/go1.18@latest go1.18 download alias go=go1.18 go version
OFFSETS_OUTPUT_FILE="../pkg/inject/offset_results.json" go run main.go
Which is expected when realized that the offset tracker is building the app with the local version of Go which cannot compile given it does not know about
MaxBytesError
.Expected behavior
Offsets should be reflective of the Go STDLIB from that version.
The text was updated successfully, but these errors were encountered: