Gitpod环境下GCC -m32选项执行报错:Bad system call求助
在Gitpod环境运行32位Hello World程序时出现「Bad system call (core dumped)」错误的排查解决
问题背景
在Gitpod环境中使用GCC -m32选项编译32位Hello World程序,已安装gcc-multilib依赖,但执行生成的a.out时触发「Bad system call (core dumped)」错误。
程序代码(test.c)
#include<stdio.h> int main() { printf("hello world!\n"); return 0; }
操作步骤
- 安装依赖:
sudo apt-get install gcc-multilib - 编译程序:
gcc -m32 test.c - 执行程序报错:
gitpod /workspace/csapp-labs/test (main) $ ./a.out Bad system call (core dumped)
环境信息
GCC版本信息
gitpod /workspace/csapp-labs/test (main) $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:hsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
system.conf相关配置片段
... #CapabilityBoundingSet= #NoNewPrivileges=no #SystemCallArchitectures= #TimerSlackNSec= #StatusUnitFormat=description #DefaultTimerAccuracySec=1min ...
排查与解决方法
问题根源
Gitpod的容器环境默认启用了seccomp安全过滤,默认的seccomp profile未允许32位x86架构的系统调用(x86_32 syscall号),导致32位程序执行时触发系统调用拦截,抛出「Bad system call」错误。
解决步骤
补充完整32位运行时依赖
先确保安装了所有必要的32位库,避免因库缺失导致的间接错误:sudo apt-get install libc6-i386 lib32gcc1 lib32stdc++6绕过seccomp限制运行程序
在Gitpod中,可以使用unshare工具创建一个不受默认seccomp限制的环境来运行32位程序:unshare --map-root-user --user ./a.out修改Gitpod workspace配置(持久化解决)
在项目根目录创建.gitpod.yml文件,添加以下配置,确保每次启动workspace时自动配置允许32位系统调用:tasks: - init: | sudo apt-get update sudo apt-get install -y gcc-multilib libc6-i386 lib32gcc1 lib32stdc++6 command: sudo sysctl -w kernel.unprivileged_userns_clone=1之后运行程序时仍可使用
unshare命令,或者配置自定义的seccomp profile(较复杂,不推荐快速场景)。验证被拦截的系统调用(可选)
使用strace追踪程序执行过程,确认具体是哪个系统调用被拦截:strace -o trace.log ./a.out查看
trace.log的最后几行,即可找到触发错误的系统调用,进一步验证问题根源。
内容的提问来源于stack exchange,提问作者minchurl
相关产品推荐
相关产品推荐

