You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GCC Sanitizers疑似存在Bug?极简C程序触发随机SEGV

GCC+AddressSanitizer随机触发SEGV问题求助

我日常用GCC编译程序时,会添加以下编译选项:

gcc -g -Wall -Wextra -std=c2x -fsanitize=address,undefined

近期发现AddressSanitizer会随机检测到程序触发SEGV。我将代码简化为仅返回EXIT_SUCCESS的极简main.c,移除undefined sanitizer后问题仍存在;改用Clang编译则无此问题(本地测试10000次未触发)。


相关编译配置

Makefile

gcc: main.c
        gcc main.c -g -Wall -Wextra -std=c2x -fsanitize=address

clang: main.c
        clang main.c -g -Wall -Wextra -std=c2x -fsanitize=address

main.c

#include <stdio.h>
#include <stdlib.h>

int main(void) { return EXIT_SUCCESS; }

测试脚本test.sh

#!/bin/bash

for i in {1..1000}; do
    echo $i
    ./a.out 2>> log.log
done

触发的错误信息

AddressSanitizer:DEADLYSIGNAL
=================================================================
==26035==ERROR: AddressSanitizer: SEGV on unknown address 0x62f205f20e78 (pc 0x7d61693e138f bp 0x000000000000 sp 0x7ffc6f41b390 T0)
==26035==The signal is caused by a READ memory access.
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer: nested bug in the same thread, aborting.

编译器版本

$ clang --version
clang version 16.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ gcc --version
gcc (GCC) 13.2.1 20230801
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

更新1

在另一台同OS(Arch Linux)、同GCC/Clang版本但内核不同的机器上,问题仍可复现:

  • 原机器内核:6.7.1-arch1-1
  • 第二台机器内核:6.7.0-arch3-1

求助

有没有人能复现该问题?或指出我代码/配置中的错误?

内容的提问来源于stack exchange,提问作者ben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 06:26:32