由于 libcpp 中的警告,gcc 构建失败

gcc build fails due a warning in libcpp

提问人:vincenzopalazzo 提问时间:10/7/2023 更新时间:10/7/2023 访问量:50

问:

我正在尝试使用 GCC 版本 >= 12 编译 gcc 编译器,当我运行时出现以下错误make

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

我有一种感觉,我错过了一些东西,因为这段代码 自 2012 年以来就没有被触及过(感谢 git 责备) 所以我很确定我错过了什么,但不确定是什么。

我也在 nix-shell 中构建它,所以我的依赖项是

{
  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
          ];
        };
      }
    );
}
GCC GCC-警告

评论

0赞 vincenzopalazzo 10/7/2023
嗨,我知道并且我正在 src 之外构建它,我想我也启用了所有依赖项,但它正在发生一些奇怪的事情。我的弓形机器能够建造它。顺便说一句,我的构建机器运行在 NixOS 上

答:

1赞 vincenzopalazzo 10/7/2023 #1

问题在于 nix/NixOS 如何构建软件包!有关此问题的更多信息 https://github.com/NixOS/nixpkgs/issues/18995

这花了一段时间,但我在以下方面发现了一个问题 一些海湾合作委员会大师。

默认情况下,nix 会启用某些编译器标志,这可能会导致 对于从事低级工作的人来说,这是一段艰难的时光。

但是,解决方案非常简单。所有 Nix 用户都需要指定 .hardeningDisable

就我而言,我只是禁用了片状文件hardeningDisable = [ "all" ];

完整的解决方案


{
  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
          ];
        };
      }
    );
}