
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
。それとも、「偽と見なされる警告」はどこから来たのでしょうか?
オプションの説明:
- https://nixos.org/nixpkgs/manual/#sec-hardening-in-nixpkgs
- https://blog.mayflower.de/5800-Hardening-Compiler-Flags-for-NixOS.html
この回答によると
nix-shell
Nix式とは関係ありませんが...フラグをmake
使用して呼び出すとNIX_DEBUG
env NIX_DEBUG=' ' make crossgcc-i386
<nixpkgs>/pkgs/build-support/cc-wrapper/add-hardening.sh
たとえば、私が推論HARDENING: enabling format
できる限り;make
nix-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
。
答え2
nix-shellでgcc強化フラグを無効にする
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
mkShell {
# disable all hardening flags
NIX_HARDENING_ENABLE = "";
# enable default hardening flags
#NIX_HARDENING_ENABLE = "pie pic format stackprotector fortify strictoverflow";
buildInputs = [
#gnumake
#python3
# ...
];
}
確認する
$ NIX_DEBUG=1 gcc -v 2>&1 | grep ^HARDENING
HARDENING: disabled flags: pie pic format stackprotector fortify strictoverflow
に基づいて
$ which gcc
/nix/store/l0fvy72hpfdpjjs3dk4112f57x7r3dlm-gcc-wrapper-12.2.0/bin/gcc
$ grep add-hardening.sh /nix/store/l0fvy72hpfdpjjs3dk4112f57x7r3dlm-gcc-wrapper-12.2.0/bin/gcc
source /nix/store/l0fvy72hpfdpjjs3dk4112f57x7r3dlm-gcc-wrapper-12.2.0/nix-support/add-hardening.sh
また見なさい:Nixpkgsの支援グループnixpkgs マニュアルから