「nix-shell」環境のセキュリティ強化オプションを無効にする

「nix-shell」環境のセキュリティ強化オプションを無効にする

NixOS(16.09)でGCC(6.3)をビルドしようとすると、nix-shell次のような結果が表示されます。

make[1]: Entering directory '<my-build-path>/coreboot/util/crossgcc/build-i386-elf-GCC/build-x86_64-pc-linux-gnu/libcpp'
test -f config.h || (rm -f stamp-h1 && make stamp-h1)
g++  -I../../../gcc-6.3.0/libcpp -I. -I../../../gcc-6.3.0/libcpp/../include -I../../../gcc-6.3.0/libcpp/include  -O2  -fomit-frame-pointer -m64 -W -Wall -Wno-narrowing -Wwrite-strings -Wmissing-format-attribute -pedantic -Wno-long-long  -fno-exceptions -fno-rtti -I../../../gcc-6.3.0/libcpp -I. -I../../../gcc-6.3.0/libcpp/../include -I../../../gcc-6.3.0/libcpp/include   -c -o expr.o -MT expr.o -MMD -MP -MF .deps/expr.Tpo ../../../gcc-6.3.0/libcpp/expr.c
../../../gcc-6.3.0/libcpp/expr.c: In function 'unsigned int cpp_classify_number(cpp_reader*, const cpp_token*, const char**, source_location)':
../../../gcc-6.3.0/libcpp/expr.c:686:18: error: format not a string literal and no format arguments [-Werror=format-security]
        0, message);
                  ^
../../../gcc-6.3.0/libcpp/expr.c:689:39: error: format not a string literal and no format arguments [-Werror=format-security]
           virtual_location, 0, message);
                                       ^
cc1plus: some warnings being treated as errors
make[1]: *** [Makefile:224: expr.o] Error 1
make[1]: Leaving directory '<my-build-path>/coreboot/util/crossgcc/build-i386-elf-GCC/build-x86_64-pc-linux-gnu/libcpp'
make: *** [Makefile:2730: all-build-libcpp] Error 2
sh ../gcc-6.3.0/mkinstalldirs <my-build-path>/coreboot/util/crossgcc/xgcc <my-build-path>/coreboot/util/crossgcc/xgcc
sh: line 3: cd: i386-elf/libgcc: No such file or directory
make: *** [Makefile:10462: install-target-libgcc] Error 1

失敗の原因はどこに-Werror=format-securityあるようです(コマンドにこの正確なオプションは表示されませんが)。しかし、<nixpkgs>/pkgs/development/compilers/gcc/6/default.nix私はこれを見つけました:

hardeningDisable = [ "format" ];

NixOS のセキュリティ強化措置によってエラーが発生する可能性があると推測され、その一部が持つGCCコンパイルを無効にします(GCC開発者がこれらの機能で何をしているのかを知っているとします)。 GCC 6.2と5.4でテストされています。同じです。

したがって、問題は環境formatの強化オプションを(具体的に)無効にする方法ですnix-shell。それとも、「偽と見なされる警告」はどこから来たのでしょうか?

オプションの説明:


この回答によると

nix-shellNix式とは関係ありませんが...フラグをmake使用して呼び出すとNIX_DEBUG

env NIX_DEBUG=' ' make crossgcc-i386

<nixpkgs>/pkgs/build-support/cc-wrapper/add-hardening.shたとえば、私が推論HARDENING: enabling formatできる限り;makenix-shell


たぶんCollisionを介して何かを渡す必要があるかもしれませんが、nixos-option正確にどのようなオプションが必要ですか?私はこのようにすることはできませんgrep...(dconf dump /または類似語なしgsettings list-recursively

ベストアンサー1

format-security警告持つ次の理由で無効になっているか、少なくとも-Werror無効になっていません。

強化オプションはコンパイララッパーによって適用されるため、ログには表示されません。

明らかに、hardeningDisableこれがラッパーに影響を与える唯一の方法です。

1つの可能な解決策は、一緒に使用するダミーNix式を作成することですnix-shell -A。例:別の場所()に
コピーして書き込み可能にし、埋め込みを追加します。~/.nix-defexpr/channels_root/nixos/<nixpkgs'>
<nixpkgs'>/pkgs/tools/misc/coreboot/default.nix

{ stdenv, gcc6, flex, bison, ncurses, iasl, doxygen, zlib, isl, python }:

stdenv.mkDerivation {
  name = "coreboot";

  buildInputs = [ gcc6 flex bison ncurses iasl doxygen zlib isl python ];

  hardeningDisable = [ "format" ];  # to build the cross-compiler
}

<nixpkgs'>/top-level/all-packages.nix通常どおり登録し、
最後に必要nix-shell <nixpkgs'> -A corebootな環境生成を呼び出します。

しかし、(に適用する方が)より簡単になると思いますnix-shell -p

おすすめ記事