Firefox NSSをWindows上でBuildする(1)

ソフトウェア開発

先日、FirefoxのNSS(Network Security Services)を使ったちょっとしたコードを書いたのですが、一部の関数で時々エラーが発生して困っています。呼び出し元のコードの問題もありそうなのですが、NSSが返してくるエラーの内容もよくわからないため、デバッガーで調べようとしています。

そこでFirefoxのNSSをWindows上でBuildしはじめたのですがWindows上での開発経験があまりなく、はまりまくってしまいました。

最初の参考にしたのは下記のサイトで、ソースもその中から最新の3.87のNSPR付のTarball(筆者 Windows11上のFirefoxにbundleされているnss3.dllは3.86)をもってきました。

Building NSS — Firefox Source Docs documentation (mozilla.org)

NSS 3.87 release notes — Firefox Source Docs documentation (mozilla.org)

Buildの準備

まず、前提としてWindows上でBuildするためにはまず以下の環境を入れておく必要があります。

それに加えてMoziillaのBuild用として

上記のコマンドのPATHをWindowsの環境変数で設定しておきます。なお、Visual Studio関係のPATHはbuild scriptの中で設定されるので設定しなくても構わません。参考までに筆者の設定をのせておきます。

なお、Build作業にはVisual Studio Code上でGit Bash Terminalを開いて,nssのsourceを展開したTop Directory(D://Project/nss-3.87)でコマンドを実行しています。

Buildの手順

NSSには2通りのBuild方法が用意されています。

  • GYPおよびNINJAを使ったBuild (nss/build.sh)
  • LegacyなMakeを使ったBuild (make -C nss nss_build_all USE_64=1)

残念ながらどちらもきちんとBuildができなかったため、いろいろコードの修正が必要になってしまいました。

nss/build.sh

内部でArchitectureのチェックをしているのですがuname -sの表示形式がUpdateされておりWindowsだという判断がされていませんでした(msvc=1にならない)。下記の修正を行うことで正しく認識されるようになりました。

# Assume that MSVC is wanted if this is running on windows.
platform=$(uname -s)
# platform format is updated eg) MINGW64_NT-10.0-22621
# "${platform%-*}" ==> "${platform%-*-*}"
if [ "${platform%-*-*}" = "MINGW32_NT" -o "${platform%-*-*}" = "MINGW64_NT" ]; then
    msvc=1
fi

nss/coreconf/msvc.sh

MSVCのLinkerであるlinkが使われるべきところ、Bashと同じPATHに入っているLinux系のlinkコマンドが使われてしまいエラーになってしまいました。MSVCのPATHがBASHのPATHよりも前にくるようにする必要があります。BASHからコマンドを起動している関係で、WINDOWSの環境変数の順番設定では解決ができないのでmsvc.shを修正することにしました。

    # link is conflict with /usr/bin/link , so VC path should be earlier in PATH
    if [ "$m" == "x86" ]; then
        PATH="${VCINSTALLDIR}/Tools/MSVC/${VCVER}/bin/Hostx64/x64:${PATH}"
        PATH="${VCINSTALLDIR}/Tools/MSVC/${VCVER}/bin/Hostx64/x86:${PATH}"
    fi
    # link is conflict with /usr/bin/link , so VC path should be earlier in PATH
    PATH="${VCINSTALLDIR}/Tools/MSVC/${VCVER}/bin/Host${m}/${m}:${PATH}"

build 結果

nss/build.sh

問題がわかるように-v optionをつけてBuildしたところ下記の場所でエラーが出てしまいとまってしまいました。

$ nss/build.sh -v
NSPR [1/5] configure ...
../configure --prefix=/d/Project/nss-3.87/dist/Debug --enable-64bit
.... (略)
make[3]: ディレクトリ `D:/Project/nss-3.87/nspr/Debug/pr/include/md' に入ります
nsinstall -D /d/Project/nss-3.87/dist/Debug/include/nspr/md
nsinstall -t -m 644 ../../../../pr/include/md/_aix32.cfg ../../../../pr/include/md/_aix64.cfg ../../../../pr/include/md/_bsdi.cfg ../../../../pr/include/md/_darwin.cfg ../../../../pr/include/md/_freebsd.cfg ../../../../pr/include/md/_hpux32.cfg ../../../../pr/include/md/_hpux64.cfg ../../../../pr/include/md/_linux.cfg ../../../../pr/include/md/_netbsd.cfg ../../../../pr/include/md/_nto.cfg ../../../../pr/include/md/_openbsd.cfg ../../../../pr/include/md/_os2.cfg ../../../../pr/include/md/_qnx.cfg ../../../../pr/include/md/_riscos.cfg ../../../../pr/include/md/_scoos.cfg ../../../../pr/include/md/_solaris.cfg ../../../../pr/include/md/_unixware.cfg ../../../../pr/include/md/_unixware7.cfg ../../../../pr/include/md/_win95.cfg ../../../../pr/include/md/_winnt.cfg /d/Project/nss-3.87/dist/Debug/include/nspr/md
nsinstall -t -m 644 ../../../../pr/include/md/_winnt.cfg /d/Project/nss-3.87/dist/Debug/include/nspr
mv -f /d/Project/nss-3.87/dist/Debug/include/nspr/_winnt.cfg /d/Project/nss-3.87/dist/Debug/include/nspr/prcpucfg.h
mv: cannot stat '/d/Project/nss-3.87/dist/Debug/include/nspr/_winnt.cfg': No such file or directory
make[3]: *** [install] エラー 1
make[3]: ディレクトリ `D:/Project/nss-3.87/nspr/Debug/pr/include/md' から出ます

再度、手でMakeをかけなおしてみたところ通ってしまったので深追いはせずに先に進むことにしました。(アクションアイテム1)

$ make -C nspr/Debug
...
D:/GnuWin32/bin/make -C md expor
make[3]: ディレクトリ `D:/Project/nss-3.87/nspr/Debug/pr/include/md' に入ります
nsinstall -m 444 ../../../../pr/include/md/_aix32.cfg ../../../../pr/include/md/_aix64.cfg ../../../../pr/include/md/_bsdi.cfg ../../../../pr/include/md/_darwin.cfg ../../../../pr/include/md/_freebsd.cfg ../../../../pr/include/md/_hpux32.cfg ../../../../pr/include/md/_hpux64.cfg ../../../../pr/include/md/_linux.cfg ../../../../pr/include/md/_netbsd.cfg ../../../../pr/include/md/_nto.cfg ../../../../pr/include/md/_openbsd.cfg ../../../../pr/include/md/_os2.cfg ../../../../pr/include/md/_qnx.cfg ../../../../pr/include/md/_riscos.cfg ../../../../pr/include/md/_scoos.cfg ../../../../pr/include/md/_solaris.cfg ../../../../pr/include/md/_unixware.cfg ../../../../pr/include/md/_unixware7.cfg ../../../../pr/include/md/_win95.cfg ../../../../pr/include/md/_winnt.cfg ../../../dist/include/nspr/md
nsinstall -m 444 ../../../../pr/include/md/_winnt.cfg ../../../dist/include/nspr
mv -f ../../../dist/include/nspr/_winnt.cfg ../../../dist/include/nspr/prcpucfg.h
make[3]: ディレクトリ `D:/Project/nss-3.87/nspr/Debug/pr/include/md' から出ます
....

nss/build.shをみるとNSPRのBuildは以下のようになっており、再度build.shを実行してしまうと元の木阿弥になってしまうようです。従って、まずはNSPRのBuildをおわらせて NSSのBuildに進むことにしました。

# NSPR.
if [[ "$rebuild_nspr" = 1 && "$no_local_nspr" = 0 ]]; then
    nspr_clean
    nspr_build
    mv -f "$nspr_config.new" "$nspr_config"
fi

その場合、以下のようにnspr_configのMoveのステップを手動で行う必要があります。これがのちにどういう影響があるかわかりませんがとりあえずわからないので安全のために。

$ find . -name "nspr_config*"
./nss/out/Debug/nspr_config.new
$ mv ./nss/out/Debug/nspr_config.new ./nss/out/Debug/nspr_config

ここからは再度nss/build.shを使ってNSSをBuildをしますがNSPRはすでにBuildできているので、できあがったファイルを使ってBuildをしてみます。-gは–with-nsprを指定する場合には必ず必要なgypのrebuildで、-j 3は平行Build(3つ同時並行)のためのOptionです。

$ nss/build.sh -v -j 3 -g --with-nspr=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr:/d/Project/nss-3.87/nspr/Debug/dist/lib | tee -a build.log
run_scanbuild gyp -f ninja --depth=/d/Project/nss-3.87/nss --generator-output=. -Dnspr_include_dir=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr -Dnspr_lib_dir=/d/Project/nss-3.87/nspr/Debug/dist/lib -Dtarget_arch=x64 -Denable_sslkeylogfile=1 -Dnss_dist_dir=/d/Project/nss-3.87/dist -Dnss_dist_obj_dir=/d/Project/nss-3.87/dist/Debug /d/Project/nss-3.87/nss/nss.gyp
ninja: Entering directory `D:/Project/nss-3.87/nss/out/Debug'

....


[3/865] D:\mozilla-build\python3\python3.exe gyp-win-tool link-with-manifests environment.x64 True D:/Project/nss-3.87/dist/Debug/bin\util_gtest.exe "D:\mozilla-build\python3\python3.exe gyp-win-tool link-wrapper environment.x64 False link.exe /nologo /OUT:D:/Project/nss-3.87/dist/Debug/bin\util_gtest.exe @D:/Project/nss-3.87/dist/Debug/bin\util_gtest.exe.rsp" 1 mt.exe rc.exe "obj\gtests\util_gtest\util_gtest.util_gtest.exe.intermediate.manifest" obj\gtests\util_gtest\util_gtest.util_gtest.exe.generated.manifest
FAILED: D:/Project/nss-3.87/dist/Debug/bin/util_gtest.exe D:/Project/nss-3.87/dist/Debug/bin/util_gtest.exe.pdb
    sys.exit(main(sys.argv[1:]))
  File "D:\Project\nss-3.87\nss\out\Debug\gyp-win-tool", line 31, in main
    exit_code = executor.Dispatch(args)
  File "D:\Project\nss-3.87\nss\out\Debug\gyp-win-tool", line 73, in Dispatch
    return getattr(self, method)(*args[1:])
  File "D:\Project\nss-3.87\nss\out\Debug\gyp-win-tool", line 202, in ExecLinkWithManifests
    our_data = re.sub(r'\s+', '', our_f.read())
UnicodeDecodeError: 'cp932' codec can't decode byte 0xef in position 0: illegal multibyte sequence
ninja: build stopped: subcommand failed.

エラーが出ているgyp-win-toolというのはNSSの持ち物ではなくgyp内のModuleのようです。

$ find /d/Project/gyp -name "*win*tool*"
/d/Project/gyp/build/lib/gyp/win_tool.py
/d/Project/gyp/pylib/gyp/win_tool.py
/d/Project/gyp/test/win/win-tool
/d/Project/gyp/test/win/win-tool/gyptest-win-tool-handles-readonly-files.py

下記のようにエラーがでている箇所にEncoding=”utf-8″を加えてあげることでエラーはでなくなりますが、あまり好ましい修正ではないですね。

      # Load and normalize the manifests. mt.exe sometimes removes whitespace,
      # and sometimes doesn't unfortunately.
      with open(our_manifest, 'r', encoding="utf-8") as our_f:
        with open(assert_manifest, 'r', encoding="utf-8") as assert_f:
          our_data = re.sub(r'\s+', '', our_f.read())
          assert_data = re.sub(r'\s+', '', assert_f.read())

再度Buildをかけると次なるエラーが出てきてしまいました。

$ nss/build.sh -v -j 3 -g --with-nspr=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr:/d/Project/nss-3.87/nspr/Debug/dist/lib | tee -a build.log
run_scanbuild gyp -f ninja --depth=/d/Project/nss-3.87/nss --generator-output=. -Dnspr_include_dir=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr -Dnspr_lib_dir=/d/Project/nss-3.87/nspr/Debug/dist/lib -Dtarget_arch=x64 -Denable_sslkeylogfile=1 -Dnss_dist_dir=/d/Project/nss-3.87/dist -Dnss_dist_obj_dir=/d/Project/nss-3.87/dist/Debug /d/Project/nss-3.87/nss/nss.gyp
ninja: Entering directory `D:/Project/nss-3.87/nss/out/Debug'

....

[537/865] ninja -t msvc -e environment.x64 -- "D:\MicrosoftVisualStudio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo /showIncludes /FC @obj\gtests\pkcs11testmodule\pkcs11testmodule.pkcs11testmodule.obj.rsp /c ..\..\gtests\pkcs11testmodule\pkcs11testmodule.cpp /Foobj\gtests\pkcs11testmodule\pkcs11testmodule.pkcs11testmodule.obj /Fdobj\gtests\pkcs11testmodule\pkcs11testmodule.cc.pdb 
FAILED: obj/gtests/pkcs11testmodule/pkcs11testmodule.pkcs11testmodule.obj 
ninja -t msvc -e environment.x64 -- "D:\MicrosoftVisualStudio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\cl.exe" /nologo /showIncludes /FC @obj\gtests\pkcs11testmodule\pkcs11testmodule.pkcs11testmodule.obj.rsp /c ..\..\gtests\pkcs11testmodule\pkcs11testmodule.cpp /Foobj\gtests\pkcs11testmodule\pkcs11testmodule.pkcs11testmodule.obj /Fdobj\gtests\pkcs11testmodule\pkcs11testmodule.cc.pdb 
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを Unicode 形式で保存してください。

....

D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(188): error C2001: 定数が 2 行目に続いています。
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(189): error C2144: 構文エラー: 'const char' は ';' によって先行されなければなりません。
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(189): error C4430: 型指定子がありません - int と仮定しました。メモ: C++ は int を既定値としてサポートしていません
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(189): error C2440: '初期化中': 'const char [18]' から 'int []' に変換できません。
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(189): note: この変換が可能なコンテキストはありません。
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(208): error C2672: 'CopyString': 一致するオーバーロードされた関数が見つかりませんでした。
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(56): note: 'void CopyString(unsigned char (&)[DestSize],const char (&)[SrcSize])' の可能性があります
D:\Project\nss-3.87\nss\gtests\pkcs11testmodule\pkcs11testmodule.cpp(208): note: 'void CopyString(unsigned char (&)[DestSize],const char (&)[SrcSize])': 'const char (&)[SrcSize]' の テンプレート 引数を 'int []' から推測できませんでした
[538/865] D:\mozilla-build\python3\python3.exe gyp-win-tool stamp obj\gtests\pk11_gtest\pk11_gtest.compile_depends.stamp
[539/865] D:\mozilla-build\python3\python3.exe gyp-win-tool link-with-manifests environment.x64 True D:/Project/nss-3.87/dist/Debug/bin\softoken_gtest.exe "D:\mozilla-build\python3\python3.exe gyp-win-tool link-wrapper environment.x64 False link.exe /nologo /OUT:D:/Project/nss-3.87/dist/Debug/bin\softoken_gtest.exe @D:/Project/nss-3.87/dist/Debug/bin\softoken_gtest.exe.rsp" 1 mt.exe rc.exe "obj\gtests\softoken_gtest\softoken_gtest.softoken_gtest.exe.intermediate.manifest" obj\gtests\softoken_gtest\softoken_gtest.softoken_gtest.exe.generated.manifest
ninja: build stopped: subcommand failed.

該当箇所をみると、日本語?らしきものが。。

static const char TestSlotDescription[] = "Test PKCS11 Slot";
static const char TestSlot2Description[] = "Test PKCS11 Slot ";
static const char TestSlot3Description[] = "Empty PKCS11 Slot";
static const char TestSlot4Description[] = "Test PKCS11 Public Certs Slot";

ちょっと正解がなになのかわからいのと、これはテストコードなので、テストを飛ばすOption (–disable-tests)をつけて続行しました。

$  nss/build.sh -v -j 3 -g --disable-tests --with-nspr=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr:/d/Project/nss-3.87/nspr/Debug/dist/lib | tee -a build.log
run_scanbuild gyp -f ninja --depth=/d/Project/nss-3.87/nss --generator-output=. -Ddisable_tests=1 -Dnspr_include_dir=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr -Dnspr_lib_dir=/d/Project/nss-3.87/nspr/Debug/dist/lib -Dtarget_arch=x64 -Denable_sslkeylogfile=1 -Dnss_dist_dir=/d/Project/nss-3.87/dist -Dnss_dist_obj_dir=/d/Project/nss-3.87/dist/Debug /d/Project/nss-3.87/nss/nss.gyp
...
[75/92] D:\mozilla-build\python3\python3.exe gyp-win-tool action-wrapper environment.x64 nss_sign_shared_libs_target_shlibsign_29fc8a445570a0d3fc8010cc12fca598..rsp ..\..\
FAILED: D:/Project/nss-3.87/dist/Debug/lib/freebl3.chk D:/Project/nss-3.87/dist/Debug/lib/softokn3.chk 
D:\mozilla-build\python3\python3.exe gyp-win-tool action-wrapper environment.x64 nss_sign_shared_libs_target_shlibsign_29fc8a445570a0d3fc8010cc12fca598..rsp ..\..\
Traceback (most recent call last):
  File "D:\Project\nss-3.87\nss\coreconf\shlibsign.py", line 30, in <module>
    main()
  File "D:\Project\nss-3.87\nss\coreconf\shlibsign.py", line 14, in main
    sign(lib_file)
  File "D:\Project\nss-3.87\nss\coreconf\shlibsign.py", line 27, in sign
    subprocess.check_call([os.path.join(bin_path, 'shlibsign'), '-v', '-i', lib_file], env=env, stdout=dev_null, stderr=dev_null)
  File "D:\mozilla-build\python3\lib\subprocess.py", line 373, in check_call

    raise CalledProcessError(retcode, cmd)

一難さってまた一難、今度はDLLのSIGN?だと思われるコマンドがエラーを起こしている。ちょっとデバッグする気力もなくなってきたため、これもSKIPできるOptionがありそうだったので それで逃げることにしました。

$ nss/build.sh -v -j 3 -g --mozpkix-only --with-nspr=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr:/d/Project/nss-3.87/nspr/Debug/dist/lib | tee -a build.log
run_scanbuild gyp -f ninja --depth=/d/Project/nss-3.87/nss --generator-output=. -Dmozpkix_only=1 -Ddisable_tests=1 -Dsign_libs=0 -Dnspr_include_dir=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr -Dnspr_lib_dir=/d/Project/nss-3.87/nspr/Debug/dist/lib -Dtarget_arch=x64 -Denable_sslkeylogfile=1 -Dnss_dist_dir=/d/Project/nss-3.87/dist -Dnss_dist_obj_dir=/d/Project/nss-3.87/dist/Debug /d/Project/nss-3.87/nss/nss.gyp
ninja: Entering directory `D:/Project/nss-3.87/nss/out/Debug'
[1/1] D:\mozilla-build\python3\python3.exe gyp-win-tool stamp obj\nss_mozpkix_libs.actions_depends.stamp
$

DLLができていたので大丈夫だと思いましたが、–mozpkix-onlyの内容を見ると全部ちゃんとできているのか怪しいです。まずはmakeの方をちゃんとしてから再度トライしてみることにしました。

--mozpkix-only   build only static mozpkix and mozpkix-test libraries
                 support for this build option is limited

make -C nss nss_build_all USE_64=1

こちらはMSVCのPATHを環境変数で設定していないため、このままではコンパイラーが見つからないというエラーが出てしまいます。nss/build.shの中で使われているnss/coreconf/msvc.shを使えば設定はできそうなので下記のような手順でBuildをしてみました。

$ target_arch=$(${python:-python} nss/coreconf/detect_host_arch.py)
$ source nss/coreconf/msvc.sh
$ make -C nss nss_build_all USE_64=1

ところが途中でやっぱりnss/build.shと同じようなエラーが出てきました。

cl -FoWIN954.0_x86_64_64_DBG.OBJ/certvfy.obj -c  -Zi -FdWIN954.0_x86_64_64_DBG.OBJ/ -Od -MD -w44267 -w44244 -w44018 -w44312 -FS -W3 -nologo -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -WX -DXP_PC -DDEBUG -UNDEBUG -DWIN64 -D_AMD64_ -D_WINDOWS -DWIN95 -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -I../../../dist/WIN954.0_x86_64_64_DBG.OBJ/include -I../../../dist/public/nss -I../../../dist/private/nss  'D:/Project/nss-3.87/nss/lib/certhigh/certvfy.c'certvfy.c
D:/Project/nss-3.87/nss/lib/certhigh/certvfy.c(1): error C2220: 次の警告はエラーとして処理されます
D:/Project/nss-3.87/nss/lib/certhigh/certvfy.c(1): warning C4819: ファイルは、現在のコード ページ (932) で表示できない文字を含んでいます。データの損失を防ぐために、ファイルを Unicode 形式で 保存してください。make[4]: *** [WIN954.0_x86_64_64_DBG.OBJ/certvfy.obj] エラー 2
make[4]: ディレクトリ `D:/Project/nss-3.87/nss/lib/certhigh' から出ます

どうやらソースコードの中に日本語(SHIFT-JIS)では表示できない文字が入っているようです。。なんでデフォルトのコードページが今時SHIFT JIS(CP932)になっているのかわからないのですが、どうやらBOM付のUTF-8のエンコードにしてあげれば大丈夫なそうなのでエラーが出たファイルのエンコードをUTF-8からBOM付のUTF-8に変換してあげることにしました。なんだかなあ。。

それにより該当ファイルのエラーは出なくなりましたが、、、次々と同じようなエラーが出てきてしまい結局以下のファイルについてエンコードを変更するはめになりました。

  • nss/lib/certhigh/certvfy.c
    BOM付のUTF-8に変更
  • nss/lib/freebl/ecl/ecp_secp384r1.c
    BOM付のUTF-8に変更
  • nss/lib/freebl/ecl/ecp_secp521r1.c
    BOM付のUTF-8に変更
  • nss/cmd/bltest/blapitest.c
    BOM付のUTF-8に変更
  • nss/gtests/certdb_gtest/alg1485_unittest.cc
    このファイルについてはBOM付のUTF-8にしてもエラーが出てしまいました。
cl -FoWIN954.0_x86_64_64_DBG.OBJ/alg1485_unittest.obj -c  -Zi -FdWIN954.0_x86_64_64_DBG.OBJ/ -Od -MD -w44267 -w44244 -w44018 -w44312 -FS -EHsc -nologo -DNOMINMAX -W3 -nologo -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -WX -DXP_PC -DDEBUG -UNDEBUG -DWIN64 -D_AMD64_ -D_WINDOWS -DWIN95 -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -I../../gtests/google_test/gtest/include -I../../gtests/common -I../../cpputil -I../../../dist/WIN954.0_x86_64_64_DBG.OBJ/include -I../../../dist/public/nss -I../../../dist/private/nss -I../../../dist/public/nspr -I../../../dist/public/nss -I../../../dist/public/libdbm -I../../../dist/public/gtest   'D:/Project/nss-3.87/nss/gtests/certdb_gtest/alg1485_unittest.cc'
alg1485_unittest.cc
D:/Project/nss-3.87/nss/gtests/certdb_gtest/alg1485_unittest.cc(48): error C2220: 次の警告はエラーとして処理されます
D:/Project/nss-3.87/nss/gtests/certdb_gtest/alg1485_unittest.cc(48): warning C4566: ユニバーサル文字名 '\U0001F611' によって表示されている文字は、現在のコード ページ (932) で表示できません  
D:/Project/nss-3.87/nss/gtests/certdb_gtest/alg1485_unittest.cc(49): warning C4566: ユニバーサル文字名 '\U0001F611' によって表示されている文字は、現在のコード ページ (932) で表示できません  
D:/Project/nss-3.87/nss/gtests/certdb_gtest/alg1485_unittest.cc(50): warning C4566: ユニバーサル文字名 '\U0001F611' によって表示されている文字は、現在のコード ページ (932) で表示できません  
make[4]: *** [WIN954.0_x86_64_64_DBG.OBJ/alg1485_unittest.obj] エラー 2

中を見ると変なシンボルが。。。これはもはやエンコード云々では解決できそうになく、テストケースのようなのでコメントアウトすることにしました。

    {"CN=Somebody,L=Set,O=Up,C=US,1=The,2=Bomb", true},
    {"OID.2.5.4.6=😑", true},
    {"2.5.4.6=😑", true},
    {"OID.moocow=😑", false},      // OIDs must be numeric
    {"3.2=bad", false},           // OIDs cannot be overly large; 3 is too big
    {"256.257=bad", false},       // Still too big
    {"YO=LO", false},             // Unknown Tag, 'YO'
    {"CN=Tester,ZZ=Top", false},  // Unknown tag, 'ZZ'
    // These tests are disabled pending Bug 1363416
    // { "01.02.03=Nope", false }, // Numbers not in minimal form
    // { "000001.0000000001=👌", false },
    // { "CN=Somebody,L=Set,O=Up,C=US,01=The,02=Bomb", false },
  • nss/gtests/pkcs11testmodule/pkcs11testmodule.cpp

BOM付のUTF-8に変更しましたが、同じファイルの別の個所でエラーが出てしまいました。

cl -FoWIN954.0_x86_64_64_DBG.OBJ/pkcs11testmodule.obj -c  -Zi -FdWIN954.0_x86_64_64_DBG.OBJ/ -Od -MD -w44267 -w44244 -w44018 -w44312 -FS -W3 -nologo -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -WX -DXP_PC -DDEBUG -UNDEBUG -DWIN64 -D_AMD64_ -D_WINDOWS -DWIN95 -DNSS_NO_INIT_SUPPORT -DUSE_UTIL_DIRECTLY -DNO_NSPR_10_SUPPORT -DSSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -I../../cpputil -I../../../dist/WIN954.0_x86_64_64_DBG.OBJ/include -I../../../dist/public/nss -I../../../dist/private/nss -I../../../dist/public/cpputil   'D:/Project/nss-3.87/nss/gtests/pkcs11testmodule/pkcs11testmodule.cpp'
pkcs11testmodule.cpp
pkcs11testmodule.cpp
D:/Project/nss-3.87/nss/gtests/pkcs11testmodule/pkcs11testmodule.cpp(228): error C2220: 次の警告はエラーとして処理されますD:/Project/nss-3.87/nss/gtests/pkcs11testmodule/pkcs11testmodule.cpp(228): warning C4566: ユニバーサル文字名 '\u00F1' によって表示されている文字は 、現在のコード ページ (932) で表示できませんD:/Project/nss-3.87/nss/gtests/pkcs11testmodule/pkcs11testmodule.cpp(229): warning C4566: ユニバーサル文字名 '\u00F1' によって表示されている文字は 、現在のコード ページ (932) で表示できません
make[4]: *** [WIN954.0_x86_64_64_DBG.OBJ/pkcs11testmodule.obj] エラー 2

nの上に~がついている文字のようだがUTF-8で大丈夫なはず。。だが確かに文字コードはUnicodeになっているようです。解決策を思いつかず、該当コードをコメントアウトしようかとも思いましたが、手っ取り早く該当文字をnにおきかえてしまうことにしました。

// Deliberately include énye to ensure we're handling encoding correctly.
// The PKCS #11 base specification v2.20 specifies that strings be encoded
// as UTF-8.
static const char TestTokenLabel[] = "Test PKCS11 Tokeñ Label";
static const char TestToken2Label[] = "Test PKCS11 Tokeñ 2 Label";
static const char TestToken4Label[] = "Test PKCS11 Public Certs Token";
static const char TestTokenModel[] = "Test Model";
  • nss/gtests/pk11_gtest/pk11_key_unittest.cc
    BOM付のUTF-8に変更
  • nss/gtests/pk11_gtest/pk11_module_unittest.cc

BOM付のUTF-8に変更したがエラーが発生。こちらもnの上に~がついた文字がありました。。のでnに置き換えました。

TEST_F(Pkcs11ModuleTest, PublicCertificatesToken) {
  const std::string kRegularToken = "Test PKCS11 Tokeñ 2 Label";
  const std::string kPublicCertificatesToken = "Test PKCS11 Public Certs Token";

  ScopedPK11SlotInfo slot1(PK11_FindSlotByName(kRegularToken.c_str()));
  ASSERT_NE(nullptr, slot1);
  EXPECT_FALSE(PK11_IsFriendly(slot1.get()));

  ScopedPK11SlotInfo slot2(
      PK11_FindSlotByName(kPublicCertificatesToken.c_str()));
  ASSERT_NE(nullptr, slot2);
  EXPECT_TRUE(PK11_IsFriendly(slot2.get()));
}

これで最終的にBuildが通りました。(^^)

$ find dist/WIN954.0_x86_64_64_DBG.OBJ/ -name "*.dll"
dist/WIN954.0_x86_64_64_DBG.OBJ/bin/nspr4.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/bin/plc4.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/bin/plds4.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/freebl3.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/nspr4.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/nss3.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/nssckbi-testlib.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/nssckbi.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/nssdbm3.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/nssutil3.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/pkcs11testmodule.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/plc4.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/plds4.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/smime3.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/softokn3.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/sqlite3.dll
dist/WIN954.0_x86_64_64_DBG.OBJ/lib/ssl3.dll

nss/build.sh

いったん、nns/build.sh -ccでCleanしてからあらためてnss/build.shでBuildしてみました。

やはりNSPRのInstallの部分で同様のエラーが出ました。

$ nss/build.sh -j 3 --disable-tests --nspr --nspr-only 
NSPR [1/5] configure ...
...
NSPR [2/5] make ...
...
NSPR [3/5] NOT building tests
NSPR [4/5] NOT running tests
NSPR [5/5] install ...
...
make[3]: ディレクトリ `D:/Project/nss-3.87/nspr/Debug/pr/include/md' に入ります
nsinstall -D /d/Project/nss-3.87/dist/Debug/include/nspr/md
nsinstall -t -m 644 ../../../../pr/include/md/_aix32.cfg ../../../../pr/include/md/_aix64.cfg ../../../../pr/include/md/_bsdi.cfg ../../../../pr/include/md/_darwin.cfg ../../../../pr/include/md/_freebsd.cfg ../../../../pr/include/md/_hpux32.cfg ../../../../pr/include/md/_hpux64.cfg ../../../../pr/include/md/_linux.cfg ../../../../pr/include/md/_netbsd.cfg ../../../../pr/include/md/_nto.cfg ../../../../pr/include/md/_openbsd.cfg ../../../../pr/include/md/_os2.cfg ../../../../pr/include/md/_qnx.cfg ../../../../pr/include/md/_riscos.cfg ../../../../pr/include/md/_scoos.cfg ../../../../pr/include/md/_solaris.cfg ../../../../pr/include/md/_unixware.cfg ../../../../pr/include/md/_unixware7.cfg ../../../../pr/include/md/_win95.cfg ../../../../pr/include/md/_winnt.cfg /d/Project/nss-3.87/dist/Debug/include/nspr/md
nsinstall -t -m 644 ../../../../pr/include/md/_winnt.cfg /d/Project/nss-3.87/dist/Debug/include/nspr
mv -f /d/Project/nss-3.87/dist/Debug/include/nspr/_winnt.cfg /d/Project/nss-3.87/dist/Debug/include/nspr/prcpucfg.h
mv: cannot stat '/d/Project/nss-3.87/dist/Debug/include/nspr/_winnt.cfg': No such file or directory

/dの下にもうひとつ/dができてしまっておりinstallのどこかで意図しない箇所にInstallしてしまっていそうです。

$ ls /d/d/Project/nss-3.87/
dist/

ちょっと時間がかかりそうなので前回と同じステップでNSPRのBuildを終わらせます。

$ make -C nspr/Debug
...
D:/GnuWin32/bin/make -C md expor
make[3]: ディレクトリ `D:/Project/nss-3.87/nspr/Debug/pr/include/md' に入ります
nsinstall -m 444 ../../../../pr/include/md/_aix32.cfg ../../../../pr/include/md/_aix64.cfg ../../../../pr/include/md/_bsdi.cfg ../../../../pr/include/md/_darwin.cfg ../../../../pr/include/md/_freebsd.cfg ../../../../pr/include/md/_hpux32.cfg ../../../../pr/include/md/_hpux64.cfg ../../../../pr/include/md/_linux.cfg ../../../../pr/include/md/_netbsd.cfg ../../../../pr/include/md/_nto.cfg ../../../../pr/include/md/_openbsd.cfg ../../../../pr/include/md/_os2.cfg ../../../../pr/include/md/_qnx.cfg ../../../../pr/include/md/_riscos.cfg ../../../../pr/include/md/_scoos.cfg ../../../../pr/include/md/_solaris.cfg ../../../../pr/include/md/_unixware.cfg ../../../../pr/include/md/_unixware7.cfg ../../../../pr/include/md/_win95.cfg ../../../../pr/include/md/_winnt.cfg ../../../dist/include/nspr/md
nsinstall -m 444 ../../../../pr/include/md/_winnt.cfg ../../../dist/include/nspr
mv -f ../../../dist/include/nspr/_winnt.cfg ../../../dist/include/nspr/prcpucfg.h
make[3]: ディレクトリ `D:/Project/nss-3.87/nspr/Debug/pr/include/md' から出ます
....
$ mv ./nss/out/Debug/nspr_config.new ./nss/out/Debug/nspr_config

引き続きnssの方のBuildです。testは飛ばさずにやってみました。

$ nss/build.sh -v -j 3 -g --with-nspr=/d/Project/nss-3.87/nspr/Debug/dist/include/nspr:/d/Project/nss-3.87/nspr/Debug/dist/lib 
...
[1070/1247] D:\mozilla-build\python3\python3.exe gyp-win-tool action-wrapper environment.x64 nss_sign_shared_libs_target_shlibsign_29fc8a445570a0d3fc8010cc12fca598..rsp ..\..\
FAILED: D:/Project/nss-3.87/dist/Debug/lib/freebl3.chk D:/Project/nss-3.87/dist/Debug/lib/softokn3.chk
D:\mozilla-build\python3\python3.exe gyp-win-tool action-wrapper environment.x64 nss_sign_shared_libs_target_shlibsign_29fc8a445570a0d3fc8010cc12fca598..rsp ..\..\
Traceback (most recent call last):
  File "D:\Project\nss-3.87\nss\coreconf\shlibsign.py", line 30, in <module>
    main()
  File "D:\Project\nss-3.87\nss\coreconf\shlibsign.py", line 14, in main
    sign(lib_file)
  File "D:\Project\nss-3.87\nss\coreconf\shlibsign.py", line 27, in sign
    subprocess.check_call([os.path.join(bin_path, 'shlibsign'), '-v', '-i', lib_file], env=env, stdout=dev_null, stderr=dev_null)
  File "D:\mozilla-build\python3\lib\subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['D:\\Project\\nss-3.87\\dist\\Debug\\bin\\shlibsign', '-v', '-i', 'D:\\Project\\nss-3.87\\dist\\Debug\\lib\\freebl3.dll']' returned non-zero exit status 3221225781.

やっぱりshlibsignがFailしてしまいました。この時点でできているDLLを調べるとMakeの時にはできていたDLLが3つほどないようです。(アクションアイテム2)

  • dist/WIN954.0_x86_64_64_DBG.OBJ/lib/nssdbm3.dll
  • dist/WIN954.0_x86_64_64_DBG.OBJ/lib/plc4.dll
  • dist/WIN954.0_x86_64_64_DBG.OBJ/lib/plds4.dll
$ find dist/ -name  "*.dll"
dist/Debug/lib/freebl3.dll
dist/Debug/lib/nss3.dll
dist/Debug/lib/nssckbi-testlib.dll
dist/Debug/lib/nssckbi.dll
dist/Debug/lib/nssutil3.dll
dist/Debug/lib/pkcs11testmodule.dll
dist/Debug/lib/smime3.dll
dist/Debug/lib/softokn3.dll
dist/Debug/lib/sqlite3.dll
dist/Debug/lib/ssl3.dll

念のため前回と同じく–mozpkix-onlyをつけてBuildしなおして変化があるか見てみましたが特にありませんでした。実は何もされていないのかもしれません。

今回のまとめ

nss/build.shの方は完璧とまではいきませんでしたが肝心のnss3.dllはBuildできました、Makeに関しては一部のテスト内容は?ですが一通りBuildができたのではないかと思います。

nss/build.shに関して残っている主な問題としては

  1. nsprのinstallでエラーになる
  2. nssのbuildでshlibsignがエラーになる

の2件になります。これらは次回の宿題とし、nss/build.sh一発でBuildが通るのを目指したいと思います。

コメント

タイトルとURLをコピーしました