Search code examples
gccgcc-warning

gcc build fails due a warning in libcpp


I am trying to compile the gcc compiler with GCC version >= 12 and when I ran make I got the following error

tti -I../../../../gittea/gcc/libcpp -I.
-I../../../../gittea/gcc/libcpp/../include
-I../../../../gittea/gcc/libcpp/include    -c -o expr.o -MT expr.o
-MMD -MP -MF .deps/expr.Tpo ../../../../gittea/gcc/libcpp/expr.cc
../../../../gittea/gcc/libcpp/expr.cc: In function ‘unsigned int
cpp_classify_number(cpp_reader*, const cpp_token*, const char**,
location_t)’:
../../../../gittea/gcc/libcpp/expr.cc:842:35: error: format not a
string literal and no format arguments [-Werror=format-security]
  842 |             cpp_warning_with_line (pfile, CPP_W_LONG_LONG,
virtual_location,
      |
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  843 |                                    0, message);
      |                                    ~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:845:38: error: format not a
string literal and no format arguments [-Werror=format-security]
  845 |             cpp_pedwarning_with_line (pfile, CPP_W_LONG_LONG,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
  846 |                                       virtual_location, 0, message);
      |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:855:33: error: format not a
string literal and no format arguments [-Werror=format-security]
  855 |           cpp_warning_with_line (pfile, CPP_W_SIZE_T_LITERALS,
      |           ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  856 |                                  virtual_location, 0, message);
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:867:42: error: format not a
string literal and no format arguments [-Werror=format-security]
  867 |                 cpp_pedwarning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  868 |                                           virtual_location, 0, message);
      |                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:870:39: error: format not a
string literal and no format arguments [-Werror=format-security]
  870 |                 cpp_warning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
      |                 ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  871 |                                        virtual_location, 0, message);
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:877:35: error: format not a
string literal and no format arguments [-Werror=format-security]
  877 |               cpp_error_with_line (pfile, CPP_DL_PEDWARN,
virtual_location, 0,
      |
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  878 |                                    message);
      |                                    ~~~~~~~~
cc1plus: some warnings are being treated as errors

I have the feeling that I am missing something because this code has not been touched since 2012 (thank git blame) so I am pretty sure that I am missing something, but not sure what.

I am also building this within a nix-shell, so my dependencies are

{
  description = "gcc compiler";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system};
      in {
        packages = {
          default = pkgs.gnumake;
        };
        formatter = pkgs.nixpkgs-fmt;

        devShell = pkgs.mkShell {
          buildInputs = [
            pkgs.gnumake
            pkgs.gcc13

            pkgs.libgcc
            pkgs.glibc

            pkgs.gmp
            pkgs.libmpc
            pkgs.mpfr
            pkgs.flex
            pkgs.bison

            pkgs.isl
            pkgs.pkg-config
            pkgs.autoconf-archive
            pkgs.autoconf
            pkgs.automake
          ];
        };
      }
    );
}

Solution

  • The problem is how nix/NixOS build the package! More information on this issue https://github.com/NixOS/nixpkgs/issues/18995

    This took me a while but I found a problem with the help of Some GCC guru.

    Some compiler flags are enabled by default with nix, which can cause hard time for people who work with low-level stuff.

    However, the solution is pretty simple. All Nix users need to specify hardeningDisable.

    In my case, I just disabled the flake file hardeningDisable = [ "all" ];

    Full solution


    {
      description = "gcc compiler";
    
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs";
        flake-utils.url = "github:numtide/flake-utils";
      };
    
      outputs = { self, nixpkgs, flake-utils }:
        flake-utils.lib.eachDefaultSystem (system:
          let pkgs = nixpkgs.legacyPackages.${system};
          in {
            packages = {
              default = pkgs.gnumake;
            };
            formatter = pkgs.nixpkgs-fmt;
    
            devShell = pkgs.mkShell {
                hardeningDisable = [ "all" ]; # Disable all hardening flags
    
                buildInputs = [
                pkgs.gnumake
                pkgs.gcc13
    
                pkgs.gmp
                pkgs.libmpc
                pkgs.mpfr
                pkgs.flex
                pkgs.bison
    
                pkgs.isl
                pkgs.pkg-config
                pkgs.autoconf-archive
                pkgs.autoconf
                pkgs.automake
              ];
            };
          }
        );
    }