Skip to content

Commit 3b34d63

Browse files
committed
Turn off gsframe option if GCC supports it
Recent versions of GCC apparently introduced a new format (SFrame) for fast stack unwinding by default or when certain flags are present. The SFrame implementation seems to have a limitation in that it only supports a subset of x86_64 registers for the Canonical Frame Address (CFA):. qsim makes heavy use of AVX/AVX2/AVX512 instructions. When GCC optimizes this code, it often uses additional registers to calculate the stack frame. Since SFrame doesn't support these registers, the assembler warns that it cannot emit SFrame data for those sections. These warnings are harmless for qsim because it does not rely on SFrame for its functionality. However, compilation produces _a lot_ of warning messages, which is alarming and confusing. This change adds the option `-Wa,--gsframe=no` to GCC if it supports the option. This silences the warnings.
1 parent a78d121 commit 3b34d63

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ CXXFLAGS := $(BASE_CXXFLAGS) $(CXXFLAGS)
4646
NVCCFLAGS := $(BASE_NVCCFLAGS) $(NVCCFLAGS)
4747
HIPCCFLAGS := $(BASE_HIPCCFLAGS) $(HIPCCFLAGS)
4848

49+
# GCC 15 and Binutils 2.45+ generate SFrame stack unwinding info. The current
50+
# SFrame only supports a subset of x86_64 registers. When GCC optimizes AVX*
51+
# instructions, it uses additional registers, and that causes the assembler to
52+
# produce (many) warnings. They are harmless for qsim because it does not rely
53+
# on SFrame. Silence those warnings if the assembler supports it.
54+
SUPPORTS_GSFRAME := $(shell as --help 2>&1 | grep -isq "\-\-gsframe" && echo "true")
55+
ifeq ($(SUPPORTS_GSFRAME),true)
56+
CXXFLAGS += -Wa,--gsframe=no
57+
endif
58+
4959
LTO_FLAGS := -flto=auto
5060
USING_CLANG := $(shell $(CXX) --version | grep -isq clang && echo "true")
5161
ifeq ($(USING_CLANG),true)
@@ -241,7 +251,7 @@ clean:
241251
-$(MAKE) -C pybind_interface/ clean
242252

243253
LOCAL_VARS = TARGETS TESTS PYTESTS PYTESTFLAGS CXX CXXFLAGS NVCC NVCCFLAGS $\
244-
HIPCC HIPCCFLAGS CUDA_PATH CUQUANTUM_ROOT CUSTATEVECFLAGS
254+
HIPCC HIPCCFLAGS CUDA_PATH CUQUANTUM_ROOT CUSTATEVECFLAGS SUPPORTS_GSFRAME
245255

246256
.PHONY: print-vars
247257
print-vars: ; @$(foreach n,$(sort $(LOCAL_VARS)),echo $n=$($n);)

0 commit comments

Comments
 (0)