pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] PR #997: Drop -march=native on aarch64 GCC to avoid pac-ret miscompile
3+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] PR #997: Drop -march=native on aarch64 GCC to avoid pac-ret miscompile
@ 2026-07-07 21:17 "dbroudy (@dbroudy)" <noreply+dbroudy@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: dbroudy (@dbroudy) @ 2026-07-07 21:17 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

GCC on aarch64 miscompiles the pac-ret return sequence when -march=native enables the pauth feature and the server is built with -mbranch-protection (as PostgreSQL 19 is on Debian). The function epilogue authenticates the return address twice ("autiasp" then "retaa"); the second authentication fails and poisons the program counter, so the backend segfaults on module load (LOAD 'vector' / CREATE EXTENSION vector), before any SQL object is created.

Drop -march=native when the compiler is GCC, the server uses -mbranch-protection=standard|pac-ret, and native enables pauth. This keeps pointer-authentication hardening intact and only forgoes native micro-tuning on affected GCC builds; clang and other compilers are unaffected.

inline patch 1: Makefile (+19/-1 lines) download inline-1.patchdiff --git a/Makefile b/Makefile index 86d01d9c4..6b172c4cd 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,25 @@ ifeq ($(shell uname -m), riscv64) OPTFLAGS = endif +PG_CONFIG ?= pg_config + +# GCC on aarch64 miscompiles the pac-ret return sequence when -march=native +# enables the pauth feature and the server is built with -mbranch-protection: +# the epilogue authenticates the return address twice ("autiasp" then "retaa"), +# which faults and crashes the backend on module load. Observed on GCC 14 and +# applied to any GCC whose native target enables pauth (detecting which versions +# are fixed is not worth the cost); clang and other compilers keep -march=native. +ifneq ($(filter aarch64 arm64, $(shell uname -m)), ) + PG_CC := $(shell $(PG_CONFIG) --cc) + ifneq ($(shell $(PG_CC) --version 2>/dev/null | grep -ic 'free software foundation'), 0) + ifneq ($(shell $(PG_CONFIG) --cflags | grep -Ec -- '-mbranch-protection=(standard|pac-ret)'), 0) + ifneq ($(shell $(PG_CC) -march=native -v -E - </dev/null 2>&1 | grep -c pauth), 0) + OPTFLAGS = + endif + endif + endif +endif + # For auto-vectorization: # - GCC (needs -ftree-vectorize OR -O3) - https://gcc.gnu.org/projects/tree-ssa/vectorization.html # - Clang (could use pragma instead) - https://llvm.org/docs/Vectorizers.html @@ -48,7 +67,6 @@ all: sql/$(EXTENSION)--$(EXTVERSION).sql sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql cp $< $@ -PG_CONFIG ?= pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS)
^ permalink raw [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] PR #997: Drop -march=native on aarch64 GCC to avoid pac-ret miscompile
@ 2026-07-08 03:12 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2026-07-08 03:12 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @dbroudy, thanks for the PR. I think it'd be better to get this fixed in GCC (or use a patched version if it already is) rather than try to detect it in pgvector, but happy to revisit this if it becomes a common issue in the future.

Also, I wasn't able to reproduce it (as `-march=native` didn't enable `pauth` on the three machines I tried).

^ permalink  raw  [nested|flat] 3+ messages in thread

* Re: [pgvector/pgvector] PR #997: Drop -march=native on aarch64 GCC to avoid pac-ret miscompile
@ 2026-07-08 03:12 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2026-07-08 03:12 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-07-08 03:12 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-07 21:17 [pgvector/pgvector] PR #997: Drop -march=native on aarch64 GCC to avoid pac-ret miscompile "dbroudy (@dbroudy)" <noreply+dbroudy@github.com>
2026-07-08 03:12 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-07-08 03:12 ` "ankane (@ankane)" <noreply+ankane@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox