Skip to content

gotls: resolve Go text base for externally linked binaries - #1105

Merged
cfc4n merged 1 commit into
gojue:masterfrom
yunwei37:bugfix/gotls-external-text-base
Dec 2, 2026
Merged

cfc4n merged 1 commit into
gojue:masterfrom
yunwei37:bugfix/gotls-external-text-base

Conversation

@yunwei37

@yunwei37 yunwei37 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

For an externally linked Go 1.26 executable (cgo, -linkmode=external), .text begins with native startup code before runtime.text, and the pclntab header's textStart is zero. ReadTable then leaves gosym entries relative to zero, and the file-offset calculation treats them as relative to the start of ELF .text. Every GoTLS offset lands runtime.text - .text bytes early.

A Go 1.26.11 client built with CGO_ENABLED=1 go build -ldflags=-linkmode=external has .text at 0x402340 and runtime.text at 0x402440, so the uprobes for writeRecordLocked and writeKeyLog sit 256 bytes before those functions.

Change

When a modern pclntab header has no relocated text base, use the ELF runtime.text symbol as the base passed to gosym.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

  • An in-memory ELF/pclntab regression covers internal linking, external linking with a zero header, external linking with a relocated header, and a stripped internal file. Before the fix only the external zero-header case fails (0x8c instead of 0x18c); all four pass with it. go test -race -count=1 ./internal/probe/gotls/ passes.
  • Kernel eBPF as root, CO-RE builds (make build_core) of master 9c00018 and 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 own tls.Config.KeyLogWriter file: master writes 0 of the 4 secrets; this branch writes all 4, byte-equal under the same labels.
  • Ubuntu 24.04 on WSL2, Linux 6.18.58.1, x86-64, Go 1.26.11, clang 18.1.3. Touched Go files are formatted; production-tag golangci-lint was not run.

Use runtime.text when the pclntab header is unrelocated so native startup
code before Go text does not shift resolved function file offsets.
@dosubot

dosubot Bot commented Dec 1, 2026

Copy link
Copy Markdown

📄 Knowledge review

✏️ Suggested updates

1 page suggestion needs review.

Page Library Status
CHANGELOG /ecapture/blob/master/CHANGELOG.md ecapture ⬆️ Pushed to this PR

Leave Feedback Ask Dosu about ecapture Add Dosu to your team

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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.text symbol 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

@cfc4n cfc4n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, thanks.

@cfc4n
cfc4n merged commit 9d0ea42 into gojue:master Dec 2, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants