Skip to content

feat(gotls): support Go binaries built with -ldflags="-s -w"#907

Merged
cfc4n merged 1 commit into
gojue:masterfrom
wocaolideTwistzz:master
Dec 26, 2025
Merged

feat(gotls): support Go binaries built with -ldflags="-s -w"#907
cfc4n merged 1 commit into
gojue:masterfrom
wocaolideTwistzz:master

Conversation

@wocaolideTwistzz
Copy link
Copy Markdown
Contributor

Summary

This PR makes gotls work with Go binaries compiled with -ldflags="-s -w" by resolving function addresses and return offsets from Go’s own symbol table when the ELF symbol table is stripped.

Fixes #848.

Background

Currently gotls relies on existing ELF information to locate tls functions.

The standard symbol table and debug info are stripped when Go binaries built with -ldflags="-s -w". The existing logic (findRetOffsets) may fail to locate the needed function and return address. It will be fatal with "symbol not found".

Changes

When parsing non-PIE Go binaries and the origin logic findRetOffsets does not work, it will try to lookup function with goSymTab and maps the funtion entry from virtual address to file offset using the .text section.

This works even when the standard ELF symbol table is stripped, because Go's own symbol table(gosym) is still available.

Testing

  • Go version: go version go1.24.6 linux/amd64
  • Linux core version: 6.8.0-90-generic
  • Test Go binaries
go build -ldflags="-s -w" -o gotls_example
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	resp, err := http.Get("https://www.example.com")
	if err != nil {
		panic(err)
	}

	data, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	resp.Body.Close()
	fmt.Printf("%s", data)
}
  • ecapture tests
sudo ./bin/ecapture gotls --elfpath=/tmp/gotls_example --hex
image

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Dec 26, 2025
@dosubot
Copy link
Copy Markdown

dosubot Bot commented Dec 26, 2025

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Copy link
Copy Markdown
Member

@cfc4n cfc4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Dec 26, 2025
@cfc4n cfc4n merged commit 68ab844 into gojue:master Dec 26, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

使用gotls提示symbol not found

2 participants