Improve g TLS offset retrieval for binaries built with buildmode=pie#730
Merged
fabled merged 4 commits intoopen-telemetry:mainfrom Sep 4, 2025
Merged
Conversation
florianl
added a commit
that referenced
this pull request
Aug 26, 2025
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Member
|
We need to land #728 first, as the CI fails here as symbols can't be found. |
Member
|
As #728 got merged, can you rebase this change onto most recent |
Go binaries built with -buildmode=pie have slightly different assembly code. On arm64, the runtime.load_g symbol has 2 mov (movz and movk) instructions instead of 1 mov: 0x00000000000c2290 <+0>: adrp x27, 0x2ca000 <runtime.itabTableInit+3072> 0x00000000000c2294 <+4>: ldrsb x0, [x27, #1766] 0x00000000000c2298 <+8>: cbz x0, 0xc22ac <runtime.load_g+28> 0x00000000000c229c <+12>: mrs x0, tpidr_el0 0x00000000000c22a0 <+16>: movz x27, #0x0, lsl #16 0x00000000000c22a4 <+20>: movk x27, #0x10 0x00000000000c22a8 <+24>: ldr x28, [x0, x27] 0x00000000000c22ac <+28>: ret And on amd64, the runtime.stackcheck symbol has also 2 mov instructions instead of 1: 0x00000000007ec320 <+0>: mov $0xfffffffffffffff8,%rcx 0x00000000007ec327 <+7>: mov %fs:(%rcx),%rax This commit fixes the TLS offset retrieval for both architectures. On amd64, it uses amd.Interpreter to find the mov instruction with fs segment and then determine the offset into the segment when displacement is a register. On arm64, it looks for mov or movk instructions (ignoring movz instruction since it seems to always be 0).
c67d71f to
670d11e
Compare
Contributor
Author
Done ! |
florianl
reviewed
Sep 1, 2025
fabled
reviewed
Sep 3, 2025
florianl
approved these changes
Sep 3, 2025
f1aa1a1 to
e793b25
Compare
gnurizen
pushed a commit
to parca-dev/opentelemetry-ebpf-profiler
that referenced
this pull request
Nov 4, 2025
gnurizen
pushed a commit
to parca-dev/opentelemetry-ebpf-profiler
that referenced
this pull request
Nov 9, 2025
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.
Go binaries built with -buildmode=pie have slightly different assembly code. On arm64, the runtime.load_g symbol has 2 mov (movz and movk) instructions instead of 1 mov:
0x00000000000c2290 <+0>: adrp x27, 0x2ca000 <runtime.itabTableInit+3072>
0x00000000000c2294 <+4>: ldrsb x0, [x27, #1766]
0x00000000000c2298 <+8>: cbz x0, 0xc22ac <runtime.load_g+28>
0x00000000000c229c <+12>: mrs x0, tpidr_el0
0x00000000000c22a0 <+16>: movz x27, #0x0, lsl #16
0x00000000000c22a4 <+20>: movk x27, #0x10
0x00000000000c22a8 <+24>: ldr x28, [x0, x27]
0x00000000000c22ac <+28>: ret
And on amd64, the runtime.stackcheck symbol has also 2 mov instructions instead of 1:
0x00000000007ec320 <+0>: mov $0xfffffffffffffff8,%rcx
0x00000000007ec327 <+7>: mov %fs:(%rcx),%rax
This commit fixes the TLS offset retrieval for both architectures. On amd64, it uses amd.Interpreter to find the mov instruction with fs segment and then determine the offset into the segment when displacement is a register. On arm64, it looks for mov or movk instructions (ignoring movz instruction since it seems to always be 0).