Search code examples
gccgdbapple-siliconapple-clang

Why can't I suppress warnings while compiling GDB for Apple Silicon?


I have a new Apple M2 MacBook Pro issued by my new job on which our toolchain requires the use of GDB. Since GDB is not pre compiled for Apple Silicon, I have attempted to compile the GDB as a Cross-debugger for a new ARM® Cortex®-M33-based SoC. I have followed a few examples from other users who have successfully compiled on there M1 CPUs; however, I cannot get past compiler warnings that are flagging as errors, even when applying "-Wno-..." flags to disable them. I have started editing my local copy of the GDB repo to work through the errors, but some of them have no easy answer, such as this:

/Applications/gdb-12.1/sim/arm/../common/sim-utils.c:157:24: error: format string is not a string literal [-Werror,-Wformat-nonliteral] sim_io_evprintf (sd, fmt, ap); ^~~

Currently using build in gcc: Apple clang version 14.0.0 (clang-1400.0.29.202) Target: arm64-apple-darwin21.6.0 Thread model: posix

I am attempting to build gdb-12.1

Is there a different compiler, or specific options, that I can try instead?

Started with a simple, manual compilation per the README: Opened the terminal:

  • "./configure arm-none-eabi"
  • "make"

I did expect some errors there. After finding forums from others who had done this, I tried the following:

  • "CFLAGS=-Wno-format-nonliteral"
  • "./configure arm-none-eabi"
  • "make"

I was expecting the compiler to ignore the warning with that, but that failed.


Solution

  • First, it's a bad idea to compile GDB in your source tree. Here's how I'd setup a build environment:

    mkdir project-dir
    cd project-dir
    git clone GIT-REPO src
    mkdir build
    cd build
    ../src/configure ...options here...
    

    Now, if all you want to do is build GDB for a arm-none-eabi target, then you probably don't need the simulator built at all? If so then I would recommend configuring and building like this:

    ../src/configure --target=arm-none-eabi --disable-sim
    make all-gdb
    

    This will completely avoid building anything from the sim/ sub-directory.

    If you do want to build the sim/ directory then I think you can add the --disable-werror configure option.

    Finally, there has been some work done recently (which should be in the upcoming GDB 13) to address compiler warnings generated by Clang when building the sim/ tree, so some of these issues should be addressed in the next release.