Skip to content

fix: Deduce textstart from runtime.text symbol or moduledata for Go 1.26#1146

Merged
christos68k merged 6 commits into
open-telemetry:mainfrom
DataDog:nsavoire/fix_textstart
Feb 5, 2026
Merged

fix: Deduce textstart from runtime.text symbol or moduledata for Go 1.26#1146
christos68k merged 6 commits into
open-telemetry:mainfrom
DataDog:nsavoire/fix_textstart

Conversation

@nsavoire
Copy link
Copy Markdown
Contributor

@nsavoire nsavoire commented Feb 2, 2026

Fixes #1145

Starting from Go 1.26, textStart address in pclntab is always set to 0, currently address of .text section is used when textStart is 0, but that is not always correct (for example with cgo binaries or when built with -linkmode=external).
The proposed change is to deduce textStart from either runtime.text symbol or moduledata.text if there are not symbols.

@nsavoire nsavoire requested review from a team as code owners February 2, 2026 14:18
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21d6647152

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +619 to +624
const textStartOff = 22 * 8
if textStartOff+8 > len(moduleData) {
return 0, fmt.Errorf("invalid text start offset: %v", textStartOff)
}
textStart = *(*uintptr)(unsafe.Pointer(&moduleData[textStartOff]))
return textStart, nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply relocations when reading moduledata.text

For stripped Go 1.26 PIE/external-linked binaries (no runtime.text symbol), this falls back to reading moduledata.text directly from the .go.module section bytes. Those pointer fields are relocated at load time for ET_DYN/PIE, and Section.Data returns the raw on-disk contents without applying relocations, so the value is often 0 or otherwise unrelocated. That means textStart can remain wrong specifically for stripped PIE binaries, regressing unwinding compared to the old .text-section fallback. Consider resolving relocations for .go.module (or falling back to .text if the unrelocated value is 0) before using it.

Useful? React with 👍 / 👎.

Comment thread nativeunwind/elfunwindinfo/elfgopclntab.go Outdated
Comment thread nativeunwind/elfunwindinfo/elfgopclntab.go Outdated
Comment thread nativeunwind/elfunwindinfo/elfgopclntab.go Outdated
Comment thread nativeunwind/elfunwindinfo/elfgopclntab_test.go Outdated
@nsavoire nsavoire force-pushed the nsavoire/fix_textstart branch from 36e5dc9 to f59dc48 Compare February 3, 2026 10:53
Comment thread nativeunwind/elfunwindinfo/elfgopclntab.go Outdated
Comment thread nativeunwind/elfunwindinfo/elfgopclntab.go Outdated
return 0, fmt.Errorf("could not read .go.module section at offset %v: %w", textOffset, err)
}

return *(*uintptr)(unsafe.Pointer(&textBytes[0])), nil
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.

For easier maintainability we could use the following instead.

Suggested change
return *(*uintptr)(unsafe.Pointer(&textBytes[0])), nil
return uintptr(binary.LittleEndian.Uint64(textBytes[:])), nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was hesitating to use binary since the rest of the file was using unsafe casts.

@christos68k christos68k merged commit 188cf50 into open-telemetry:main Feb 5, 2026
31 checks passed
florianl added a commit to florianl/opentelemetry-ebpf-profiler that referenced this pull request Feb 6, 2026
open-telemetry#1146 added new executables in testdata.

Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
marcsanmi pushed a commit to grafana/opentelemetry-ebpf-profiler that referenced this pull request Feb 18, 2026
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.

textStart does not always match address of .text section

5 participants