golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.99k stars 17.67k forks source link

cmd/asm: arm64 assembler generates code that is not execute-only compatible #59615

Open 4a6f656c opened 1 year ago

4a6f656c commented 1 year ago

The Go assembler for arm64 generates code that is not execute-only compatible, since it stores constants in the text section rather than in rodata, which it then reads during execution.

OpenBSD 7.3 has enabled xonly by default on OpenBSD/arm64 - this means that externally linked Go binaries segfault on execution. This can be worked around in the interim by disabling execute-only when the external linker is invoked.

Longer term, the assembler should store constants in rodata and/or load them via instructions, such that the text section can be marked as execute-only.

dr2chase commented 1 year ago

@golang/compiler

gopherbot commented 1 year ago

Change https://go.dev/cl/484555 mentions this issue: cmd/link/internal/ld: disable execute-only for external linking on openbsd/arm64

randall77 commented 1 year ago

I know of one place where we read instruction memory, to print instruction bytes after a SIGILL:

https://cs.opensource.google/go/go/+/refs/tags/go1.20.3:src/runtime/signal_unix.go;l=747

Not super critical, but if we're running in execute-only mode it would be good to disable that code.

erifan commented 1 year ago

since it stores constants in the text section rather than in rodata, which it then reads during execution.

Do you mean literal pool ?

4a6f656c commented 1 year ago

since it stores constants in the text section rather than in rodata, which it then reads during execution.

Do you mean literal pool ?

Yes.

gopherbot commented 1 year ago

Change https://go.dev/cl/512538 mentions this issue: cmd/internal/obj/arm64: improve classification of loads and stores

gopherbot commented 1 year ago

Change https://go.dev/cl/512540 mentions this issue: cmd/internal/obj/arm64: improve splitting of 24 bit unsigned scaled immediates

gopherbot commented 1 year ago

Change https://go.dev/cl/512539 mentions this issue: cmd/internal/obj/arm64: avoid unnecessary literal pool usage for moves

gopherbot commented 1 year ago

Change https://go.dev/cl/515617 mentions this issue: cmd/internal/obj/arm64: load large constants into vector registers from rodata

gopherbot commented 1 year ago

Change https://go.dev/cl/515615 mentions this issue: cmd/internal/obj/arm64: avoid unnecessary pool literal usage for load/store pairs