Search code examples
dockergdbm4sve

GDB Error: Unable to Fetch SVE/SSVE Vector Length ("Invalid Argument") on Docker - Ubuntu - Apple M4


I recently transitioned from Apple Silicon M1 Pro to Apple Silicon M4 Max and encountered an issue while debugging a C++ project using GDB. The error message is as follows:

Unable to fetch SVE/SSVE vector length: Invalid argument.

Context:

  1. Environment: Docker container running Ubuntu (multiple versions tested) on Apple Silicon M4 Max.

  2. Behavior: The same setup (Docker + GDB) worked flawlessly on Apple Silicon M1 Pro.

  3. Issue: While the project builds and runs successfully, I cannot debug due to the above error:

    root@ubuntu-dev:/tmp/dev/test# gdb hello-world
    GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
    Copyright (C) 2024 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "aarch64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <https://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from main...
    (gdb) r
    Starting program: /tmp/dev/test/hello-world
    Unable to fetch SVE/SSVE vector length: Invalid argument.
    

Dockerfile:

FROM ubuntu:24.04

# Disable frontend interaction
ARG DEBIAN_FRONTEND=noninteractive

# Set environment variables
ENV VCPKG_FORCE_SYSTEM_BINARIES=1

# Set user
USER root 

# Define timezone
ENV TZ=Europe/Rome

# Install other necessary packages
RUN apt-get update \
  && apt-get install -y \
      cmake \
      git \
      gcc \
      g++ \
      curl \
      gdb \
      clang \
      make \
      lcov \
      gcovr \
      ninja-build \
      autoconf \
      autoconf-archive \
      automake \
      libtool \
      valgrind \
      locales-all \
      dos2unix \
      rsync \
      zip \
      unzip \
      tar \
      python3 \
      python3-dev \
      pkg-config \
      tzdata \
      nodejs \
      npm \                        
      file \
      libssl-dev \
  && apt-get clean

Steps to reproduce:

  1. Build the Docker container using the provided Dockerfile and run it.

  2. Create a simple main.c:

    #include <stdio.h>
    
    int main() 
    {
        printf("Hello World\n");
        return 0;
    }
    
  3. Compile gcc -o main main.c

  4. Open debugger gdb main

  5. Run application run and get result:

    root@ubuntu-dev:/tmp/dev# gdb main
    GNU gdb (Ubuntu 15.0.50.20240403-0ubuntu1) 15.0.50.20240403-git
    Copyright (C) 2024 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "aarch64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <https://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
        <http://www.gnu.org/software/gdb/documentation/>.
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from main...
    (No debugging symbols found in main)
    (gdb) run
    Starting program: /tmp/dev/main
    Unable to fetch SVE/SSVE vector length: Invalid argument.
    

Additional info:

  • Same example work on M1

  • I tried to export/import Docker from/to M1/M4 but result are equal (work on M1 and don't work on M4)

  • I tried also with Alpine Linux and last version of GCC/GDB and nothing change: M1 ok, M4 same issue

M4 Max CPU Docker info:

root@ubuntu-dev:/tmp/dev# uname -a 
Linux ubuntu-dev 6.10.14-linuxkit #1 SMP Fri Nov 29 17:22:03 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux 
root@ubuntu-dev:/tmp/dev# zcat /proc/config.gz | grep -i sve 
CONFIG_ARM64_SVE=y 
root@ubuntu-dev:/tmp/dev# cat /proc/cpuinfo
processor   : 0
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 1
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 2
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 3
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 4
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 5
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 6
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 7
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 8
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 9
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 10
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 11
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 12
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 13
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 14
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

processor   : 15
BogoMIPS    : 48.00
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 flagm2 frint svei8mm svebf16 bf16 afp sme
CPU implementer : 0x61
CPU architecture: 8
CPU variant : 0x0
CPU part    : 0x000
CPU revision    : 0

From these info, it looks M4 MAX manage sve2

Request for Help:

Has anyone encountered this issue or found a workaround?
Any advice or guidance would be appreciated!


Solution

  • After several weeks of troubleshooting, I discovered that the issue was related to Docker Desktop. While I couldn't pinpoint the exact cause, my research indicated that it might be linked to how Docker Desktop handles certain CPU features, specifically SVE (Scalable Vector Extension) and SSVE.

    Here's a brief overview of what I tried:

    1. Testing Different Environments:

      • Compiled various versions of GCC and GDB across different Docker distributions such as Arch, Debian Sid, and Alpine.
      • Attempted using LLDB instead of GDB.
      • Compiled the latest version of GDB to investigate issues related to SVE and SSVE management.
    2. Solution with Rancher Desktop:

      • Switched to Rancher Desktop, configuring it to use VZ as an emulator with Rosetta support for x64 Docker containers.
      • Utilized VirtioFS as the Volume Manager, which resolved the issues.

    This setup allowed everything to function smoothly. Additionally, I was able to import all my images from Docker Desktop into Rancher Desktop without any problems.

    Until Docker Desktop addresses this issue, using Rancher Desktop has been a successful workaround for me.