Repository navigation
internal/fakecgo: reserve threadentry's result slot on arm - #569
Merged
Merged
Conversation
Contributor
Author
|
@hajimehoshi please review |
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.
What issue is this addressing?
@hajimehoshi hey,
this is the arm follow-up from #568:
threadentry_trampolinesaves the C caller'sR4inthreadentry's result slot, so libc getsR4 = 0back after every thread exit.What type of issue is this addressing?
updates #571.
What this PR does | solves
Cause.
threadentryis called as ABI0 on arm, so its argument is at4(R13)and its result at8(R13)of the trampoline's frame. The trampoline savesR4, callee-saved under AAPCS, at8(R13), andreturn niloverwrites it. This happens in every build, not only with-N.It is latent with glibc:
start_threaddoesn't useR4after the start routine returns (glibc 2.41 armhf), andTestThreadEntryReturnpasses with or without the fix. The new test is what shows it.Fix. The saved registers move past the result slot:
R4-R11to12..40(R13),F8-F15to48..104(R13), frame$108. The argument stays at4(R13)and the result slot at8(R13)is left tothreadentry, the same layout astrampolines_386.s. With$108the doubles are also 8-byte aligned. Moving onlyR4, to104(R13), would be a three-line change, but it leavesR4apart from the other saves; I can switch to it if you prefer.Test.
TestThreadEntryTrampolinePreservesR4, the arm counterpart of #568's test:threadentry_callfor a probe that returns nil likethreadentry, and forwards any other call to the realthreadentry. Likethreadentry, it is nosplit and norace.callThreadEntryTrampoline, that puts a known value inR4and returnsR4afterwards. Its Go declaration is inthreadentry_arm.go, next to the asm, as in internal/fakecgo: reserve threadentry's spill slot on amd64 #568.DT_NEEDEDonly for a_ _import (cmd/link/internal/ld/elf.go), sopthread_attr_initis unresolved. That's whythreadentry_test.goskips arm. The test file adds//go:cgo_import_dynamic _ _ "libc.so.6", which fixes it for this binary.CI. The qemu jobs build only the root package, so the arm step gets two lines per float ABI to build and run the fakecgo test binary (hard-float and GOARM=5). Without them the test doesn't run in CI.
Testing. linux/arm under qemu-user 10.0.13 (Docker, Debian 13, glibc 2.41), Go 1.27.3 and 1.25.0:
-gcflags=all=-N -l(R4 = 0x0). With it, it passes 20 times in each.CCset to the cross compiler), passes for GOARM=7 and GOARM=5.go vetfor linux/arm and gofmt are clean.Notes.
TestThreadEntryReturnalso passes on linux/arm under qemu, so its!armexclusion could be lifted later.freebsdis intrampolines_arm.s's build tag, but fakecgo doesn't build for freebsd/arm onmain(go_freebsd.gois amd64 and arm64 only), so the test is Linux only.