Skip to content

Commit 11e5942

Browse files
authored
Turn off gsframe option if GCC supports it (#1037)
Recent versions of GCC (15.2.0, possibly slightly earlier too) 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. The warnings are harmless for qsim because it does not rely on SFrame for its functionality. However, compilation produces _a lot_ of these warning messages, which is alarming, confusing, and annoying. This change adds the option `-Wa,--gsframe=no` to GCC if it supports the option. This silences the warnings.
1 parent d908952 commit 11e5942

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ 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 $(CXX) -Wa,--gsframe=no -c -x c++ /dev/null \
55+
-o /dev/null 2>/dev/null && echo "true")
56+
ifeq ($(SUPPORTS_GSFRAME),true)
57+
CXXFLAGS += -Wa,--gsframe=no
58+
NVCCFLAGS += -Xcompiler -Wa,--gsframe=no
59+
HIPCCFLAGS += -Wa,--gsframe=no
60+
endif
61+
4962
LTO_FLAGS := -flto=auto
5063
USING_CLANG := $(shell $(CXX) --version | grep -isq clang && echo "true")
5164
ifeq ($(USING_CLANG),true)
@@ -126,7 +139,7 @@ ifneq (,$(strip $(CUQUANTUM_ROOT)))
126139
endif
127140
endif
128141

129-
# Export all variables to subprocesses without having to export them individually.
142+
# Export all vars to subprocesses without having to export them individually.
130143
.EXPORT_ALL_VARIABLES:
131144

132145
# The rest is build rules and make targets.
@@ -214,7 +227,7 @@ run-tests tests: $(TESTS)
214227
.PHONY: check-cuquantum-root-set
215228
check-cuquantum-root-set:
216229
@if test -z "$(CUQUANTUM_ROOT)"; then \
217-
echo Error: '$$CUQUANTUM_ROOT must be set in order to use cuStateVec.'; \
230+
echo Error: 'Must set $$CUQUANTUM_ROOT to use cuStateVec.'; \
218231
exit 1; \
219232
fi
220233

@@ -241,7 +254,7 @@ clean:
241254
-$(MAKE) -C pybind_interface/ clean
242255

243256
LOCAL_VARS = TARGETS TESTS PYTESTS PYTESTFLAGS CXX CXXFLAGS NVCC NVCCFLAGS $\
244-
HIPCC HIPCCFLAGS CUDA_PATH CUQUANTUM_ROOT CUSTATEVECFLAGS
257+
HIPCC HIPCCFLAGS CUDA_PATH CUQUANTUM_ROOT CUSTATEVECFLAGS SUPPORTS_GSFRAME
245258

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

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ endif
4040

4141
CXX_FILES := $(BASIC_FILES) $(SSE_FILES) $(AVX2_FILES) $(AVX512_FILES)
4242
CXX_TARGETS := $(CXX_FILES:%.cc=%.x)
43-
CXXFLAGS := $(CXXFLAGS) $(SSE_FLAGS) $(AVX2_FLAGS) $(AVX512_FLAGS) $(BMI2_FLAGS)
43+
CXXFLAGS += $(SSE_FLAGS) $(AVX2_FLAGS) $(AVX512_FLAGS) $(BMI2_FLAGS)
4444

4545
CUDA_FILES := $(wildcard *cuda_test.cu)
4646
CUDA_TARGETS := $(CUDA_FILES:%cuda_test.cu=%cuda_test.x)

0 commit comments

Comments
 (0)