Repository navigation
gotls: resolve Go text base for externally linked binaries - #1105
Merged
Merged
Conversation
Use runtime.text when the pclntab header is unrelocated so native startup code before Go text does not shift resolved function file offsets.
8 tasks
📄 Knowledge review✏️ Suggested updates1 page suggestion needs review.
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the GoTLS function-offset resolution change.
No open issues 🎉
What changed in this PR
This PR corrects GoTLS function-offset resolution for externally linked Go binaries where native startup code precedes runtime.text and the pclntab header has no relocated text base.
Changes:
- Uses the ELF
runtime.textsymbol when a modern pclntab header’s text base is zero, preserving nonzero headers and the existing fallback when symbols are unavailable. - Adds in-memory regression tests covering internal linking, external linking with zero and nonzero headers, and stripped internal binaries.
| File | Description |
|---|---|
internal/probe/gotls/config_symbol.go |
Resolves a missing Go text base from the ELF runtime.text symbol. |
internal/probe/gotls/config_symbol_test.go |
Adds synthetic ELF/pclntab fixtures and function-offset regression tests. |
Review effort: Balanced
4 of 6 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
For an externally linked Go 1.26 executable (cgo,
-linkmode=external),.textbegins with native startup code beforeruntime.text, and the pclntab header's textStart is zero.ReadTablethen leaves gosym entries relative to zero, and the file-offset calculation treats them as relative to the start of ELF.text. Every GoTLS offset landsruntime.text - .textbytes early.A Go 1.26.11 client built with
CGO_ENABLED=1 go build -ldflags=-linkmode=externalhas.textat0x402340andruntime.textat0x402440, so the uprobes forwriteRecordLockedandwriteKeyLogsit 256 bytes before those functions.Change
When a modern pclntab header has no relocated text base, use the ELF
runtime.textsymbol as the base passed togosym.NewLineTable, as that API's documentation requires for cgo binaries. A nonzero header stays authoritative, and the existing relative-entry path remains for files without ELF symbols. A stripped, externally linked file with a zero header keeps the current limitation.The change is confined to table parsing during configuration.
Verification
0x8cinstead of0x18c); all four pass with it.go test -race -count=1 ./internal/probe/gotls/passes.make build_core) of master9c00018and this branch, against the client above talking to a local TLS 1.3 server:gotls -m text --text-source hook: master records the response and misses the request; this branch records both.gotls -m keylog, compared with the client's owntls.Config.KeyLogWriterfile: master writes 0 of the 4 secrets; this branch writes all 4, byte-equal under the same labels.