※当サイトの記事には、広告・プロモーションが含まれます。

fatal error - cygheap base mismatch detected - 0x180330400/0x1802FF408. って言われてもね...

f:id:ts0818:20191116192441j:plain

まことの心を知るは 森の精 もののけ達だけ もののけ達だけ

もののけ姫 - Wikipedia

⇧  屋久島と言えば、アニメ「もののけ姫」の舞台ですね、そして、1000年杉でも有名ですかね。 

 

www.itmedia.co.jp

⇧  1000年って...壮大ですな。

Windows環境とUnix環境の互換性の問題に、今日も絶望しています、どうもボクです。

ログに騙されて、くそ泥沼にハマったやないか~い!というわけで、レッツトライ~。

 

cygwin1.dllって何よ?

事の発端は、git bash で、wget コマンドを使おうとしたら、

f:id:ts0818:20191116120430p:plain

⇧  「互換性のないバージョンのcygwin DLLを使用していることが原因」ってあって、「cygwin1.dll」を消してしまえってあるんだけど、そもそも、「cygwin1.dll」って何よ?

www.cygwin.com

 Cygwin is:
  • a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
  • a DLL (cygwin1.dll) which provides substantial POSIX API functionality.

Cygwin

⇧  出た、 Cygwin を実現するDLLってことらしい。

Cygwin is not:

  • a way to run native Linux apps on Windows. You must rebuild your application from source if you want it to run on Windows.
  • a way to magically make native Windows apps aware of UNIX® functionality like signals, ptys, etc. Again, you need to build your apps from source if you want to take advantage of Cygwin functionality.

Cygwin

⇧  注意事項とか?

 

DLL(Dynamic Link Library)って?

Wikipediaさ~ん!

ダイナミックリンクライブラリ (Dynamic Link Library: DLL、動的リンクライブラリ) は、ソフトウェアバイナリ形態の一種。動的リンクを使ったライブラリのこと。あるいは、Windowsで使用されるファイル形式を特に意図して、この語が用いられる場合もある。

ダイナミックリンクライブラリ - Wikipedia

⇧  Windowsでの使用が多いらしい。

複数のプログラムから共通に利用できるように種々の機能をプログラムとは分離させた、シェアードライブラリ(共有ライブラリ)でもあることが多い。

ダイナミックリンクライブラリ - Wikipedia

Cygwin はこっちのイメージですかね?

 

Windowsにおけるダイナミックリンクライブラリのモジュールは、拡張子が「.dll」のファイルである。ActiveXコントロールCOMコンポーネントの一種)に関しては、慣例的に「.ocx」という拡張子が付けられることもある(他にも、LightWaveプラグインファイルには慣例的に「.p」の拡張子が付けられるが、Windows版におけるファイルの中身自体はWin32 DLLそのものである)。

ダイナミックリンクライブラリ - Wikipedia

⇧ ややこしいな...

DLLは本体ソフトウェアつまり実行プログラム(「.exe」拡張子を持つモジュール)によって実行時にロードされる。

ダイナミックリンクライブラリ - Wikipedia

Win32 APIが格納されたDLLのように高い汎用性を持つC言語形式の関数がエクスポートされたDLLのほか、Microsoft Visual C++環境専用のMFC拡張DLL、Microsoft Visual Basicなどの他言語からの利用にも対応したCOMコンポーネント、および.NET Framework環境向けのマネージコードが格納されたアセンブリなど、ひとえにDLLといってもそのモジュールの実装形態や、モジュールを利用できるプログラムには差異がある。

ダイナミックリンクライブラリ - Wikipedia

⇧ ややこしいな...

 Unix系OSでは /usr/lib や /lib などの下に通常置かれる、拡張子が「.so」のファイルである。バージョンによる差異の吸収を目的として、拡張子が「.so.バージョン番号」というファイルを実体として作成し、バージョン共通名の「.so」をその実体へのシンボリックリンクとすることが多い。macOSでは拡張子として「.dylib」が使われる。

ダイナミックリンクライブラリ - Wikipedia

⇧  UnixMacでの、共有ライブラリの呼び名は、「.so」「.dylib」ってことですかね。

 

一般には、ダイナミックリンクライブラリでも、シンボル(関数シンボル)は実行プログラムファイルの生成時(コンパイル後のリンク&ビルド処理時)に解決する(アーリーバインド)。これに対し、エンドユーザーが後からモジュールを追加できるプラグインなどでは、実行時にシンボルを解決するものもある(ディレイロード)。多くの処理系では実装上両者は同じものだが、例えばDarwinでは明確に区別されている。

ダイナミックリンクライブラリ - Wikipedia

⇧  「アーリーバインド」「ディレイロード」って?

おそらく、DLLのプログラムに関することかな?ということで、

itdoc.hitachi.co.jp

home.a00.itscom.net

⇧  上記サイト様が詳しいです。

 

Git for Windowsのgitは、Cygwin と相性悪い?

で、今回、Git for Windows の git bash を使って起きた現象ということで、そもそも、 

の関係性ってのは、どうなってるのよ?って。

codeday.me

stackoverflow.com

Disclaimer: I am an MSYS2 developer

While MSYS isn't dead, I would say it's not looking very healthy either. It is a project started by the mingw team many years ago as a fork of Cygwin that never kept up with Cygwin.

msysgit is a fork of a slightly older version of MSYS with some custom patches, old versions of bash and perl and a native port of git.

MSYS2 is a project started by Alexey Pavlov of the mingw-builds team (who are the official packagers for MinGW-w64 toolchains) as a recent fork of Cygwin which tracks the latest Cygwin closely so that it doesn't end up out of date. Alexey forward ported the old MSYS patches and added some of his own.

How are msys, msys2, and msysgit related to each other? - Stack Overflow

⇧  上記サイト様によりますと、

まず、Cygwin が存在し、CygwinのフォークとしてMsysがmingwチームの元、開発が続けられてたけど、イケてないってことで、最新のCygwinのフォークを元にMsys2の開発が始まったと。

そんじゃあ、Git for Windowsは?

For a long time, Git for Windows lagged behind Git's 2.x releases because the Git for Windows developers wanted to let that big jump coincide with a well-needed jump away from MSys to MSys2.

To understand why this is such a big issueit needs to be noted that many parts of Git are not written in portable C, but instead Git relies on a POSIX shell and Perl to be available.

To support the scripts, Git for Windows has to ship a minimal POSIX emulation layer with Bash and Perl thrown in, and when the Git for Windows effort started in August 2007, this developer settled on using MSys, a stripped down version of Cygwin.
Consequently, the original name of the project was "msysGit" (which, sadly, caused a lot of confusion because few Windows users know about MSys, and even less care).

How are msys, msys2, and msysgit related to each other? - Stack Overflow

⇧ 「2007年8月にGit for Windowsの取り組みが開始されたとき、この開発者はCygwinの簡易バージョンであるMsysを使用することに決めました。」ってあるので、

  1. Cygwin → Msys
  2. Cygwin → Msys2
  3. Cygwin → Msys → Git for Windows

って感じになるのかな。Msys2のMinGWの中のGit for Windowsっていう意見もありよく分からんが。

あれ?「Git for Windows」にしろ「Msys2」にしろ、「Cygwin」がフォークの大元になってるなら、相性良いんじゃないの?

ちなみに、

i.loveruby.net

CygwinとMsysについては、上記サイト様が詳しいです。

 

Msys2の見解だと、

github.com

Cygwin tries to bring a POSIX-compatible environment to Windows so that most software that runs on unices will build and run on Cygwin without any significant modifications. Cygwin provides a large collection of packages containing such software, and libraries for their development.

How are msys, msys2, and msysgit related to each other? - Stack Overflow 

Cygwin は、Unix環境で動いてた状態のソフトにほとんど変更を加えないで済むように、POSIXエミュレータという環境を導入することで、POSIX互換を実現しようとし、

MSYS2 tries to provide an environment for building native Windows software. MSYS2 provides a large collection of packages containing such software, and libraries for their development. As a large portion of the software uses GNU build tools which are tightly coupled to the unix world, this environment is also POSIX-compatible, and is in fact based on Cygwin.

How are msys, msys2, and msysgit related to each other? - Stack Overflow 

⇧  Msys2 は、Windows 環境で動くようにUnixソフトの方をWindowsのネイティブな仕様に合わせようということかと。

MSYS2 provides a minimal shell required to run autotools and other build systems which get the source for software from the Internet from different repositories, configure them and build them. The shell and core tools exist mainly to allow porting Unix programs to run natively on Windows (i.e. without requiring a POSIX emulation layer). MSYS2 doesn't try to duplicate Cygwin's efforts more than necessary, so the number of provided POSIX-emulated software is very small.

How are msys, msys2, and msysgit related to each other? - Stack Overflow 

⇧  ただ、Msys2 は、Cygwinの影響を極力なくそうとすんだけど、結局はPOSIXエミュレータは使ってると。 

 

方向性が違うということで、

Cygwin provides a runtime library called cygwin1.dll that provides the POSIX compatibility layer where necessary. The MSYS2 variant of this library is called msys-2.0.dll and includes the following changes to support using native Windows programs:

How are msys, msys2, and msysgit related to each other? - Stack Overflow 

⇧  Runtimeも異なり、

  • Cygwin ← cygwin1.dll
  • Msys2 ← msys-2.0.dll

 ってことらしい。

 

よく分からんけど、バッティングするらしい

まぁ、明確な理由が分からんのだけれど、Git for Windows の git bashが、cygwin1.dll を参照しに行ってしまうらしい?、ダメやん...。(Git for Windowsのログが誤っていて、cygwin1.dll の問題でなくて、Msys2とGit for Windowsのバッティングだったらしい?って思ったら...真の原因は別でした...後半へ続く)

んで、「fatal error - cygheap base mismatch detected - 0x180330400/0x1802FF408.」ってあるように、cygheap なるもののバージョンが合わないってことっすかね?

Cygwin の影響からは逃れられないってことですかね。

で、自分の場合は、Windowsの検索をかけたところ、

  • Mobexterm
  • xampp

の2つのソフトウェアで、cygwin1.dll が使われてたという。

っていうか、xampp の中のcygwin1.dll がバッティング っていうのがな~、どうにも解せないけど。

解せないけど、ネットにある解決策が、cygwin1.dll を削除しろなもんで、根こそぎアンインストールしてやりましたよ(涙)。

さよなら、「Mobexterm」「xampp」、また逢う日まで

f:id:ts0818:20191116154204p:plain

f:id:ts0818:20191116154130p:plain

f:id:ts0818:20191116154420p:plain

「cygwin1.dll」が全部いなくなったら、PC再起動で。

 で、変わらんのだけれど...bashのキャッシュも無いしな~

f:id:ts0818:20191116162556p:plain

 

hydrocul.github.io

⇧  上記サイト様を参考に、「find」で検索したら、むっちゃ時間かかるけど、いた...

find /c/ -name "cygwin1.dll" -perm -u=r 2>/dev/null

f:id:ts0818:20191116172919p:plain

というわけで、残りの「cygwin1.dll」も消去で...って「ConEmu」にもcygwin1.dllあったんすか...

っていうか、どうも、cygwin1.dllの問題じゃない気もしなくもないですが、Git for Windowsのgit bashのログを信じて、一旦は、アンインストールするしかないっすかね...

で、駄目でした...

いや、意味が分からんし、「cygwin1.dll」残ってないし。

って思ってたら、

私の場合にはGitBash関係のパスをMsys2のパスよりも先に登録してあると、Msys2の側を使ったときに cygheap base mismatch detected が出まくりました。続く

https://twitter.com/genkuroki/status/906195352784535552

最初は cygheap base mismatch detected というエラーメッセージを見て素直にCygwinの問題だと思ったのですが、環境変数PATHの中のパスの並び方を変えたら、このエラーが出なくなりました。

https://twitter.com/genkuroki/status/906195352784535552

よくわからないのですが、mingwの環境を複数インストールしてあると、PATHの設定によっては、まるでCygwinの問題であるかのようなエラーメッセージが出るということなのでしょうか?30分くらい真剣に悩みました。

https://twitter.com/genkuroki/status/906195352784535552

まじっすか...無駄に終わったアンインストールたち(涙)

そういえば、chocolatey で、Git for Windows をインストールしたことで、環境変数の順序が変わった?のがマズかったのか... 

というわけで、Git for Windowsをアンインストールして、Msys2のgitを使ったところ、

f:id:ts0818:20191116191223p:plain

無事、動いたと(涙)

本当に、Windows環境とUnix環境の関係、何とかならんもんかね...

今日も貴重な一日が終わってしまったという...アンインストールしてしまった、ConEmuは、時間ある時に再インストールしますかね。

Git for Windowsか、Msys2のGitを使うか、どっちかにしないといかんということですかね...Git for Windowsのログの適当っぷりに疲れた...オープンソースだから文句は言えないけどね...。

結論

ログを見るのは大事だけど、必ずしも真実を言っているとは限らない。

まったく、何を信じたら良いんですかね...

今回はこのへんで。

 

2019年11月16日(土)22:20 追記 ↓ ここから

Git for Windows、Msys2の順番でインストーラーを使ってインストールしたところ、いまのところエラーは出ずに使えるようになりました。

やっぱり、環境変数の順番なんすかね、謎過ぎる...。

2019年11月16日(土)22:20 追記 ↑ ここまで

2019年11月17日(日)10:00 追記 ↓ ここから

翌日、パソコン再起動したら、また、Git for Windowsのgit bashで、同じ現象が...

f:id:ts0818:20191117100247p:plain

「fatal error - cygheap base mismatch detected - 0x180331408/0x180330408.」

なんか、Windowsの更新とか影響してるんじゃないかって気がするんだけど...って思ったら、

superuser.com

There are several possible reasons for this error.

For example, you could indeed have a clashing version of the DLL.

However, recent versions of Windows 10 have a set of additional protection features built in that were originally part of Microsoft EMET.

Most notably, the ASLR (Address Space Layout Randomization) security feature is not compatible with the UNIX-like executables included with the Git for Windows installation.

In order to fix this issue, open the Exploit Protection settings, switch to the Program Settings tab and add the executable names listed in the errors (you may have quite a number).

In the example given, you can enter just basename.exe or the full path if you are a little more paranoid.

For each executable, turn off the ASLR protection.

For further reference, please see the following GitHub issue:

How can I fix the error "fatal error - cygheap base mismatch detected" when using git on Windows 10? - Super User

⇧  Microsoft~!、テメェ~、この野郎、また、お前か...

んで、「Windows 10 の Exploit Protectionの設定」で、何とかなるらしいんだけど、

github.com

Removing github Desktop completely and reinstalling had no effect.

As TotallyInformation said, I had to add the exploit protection overrides for every file in the Cygwin package used by Github. With these exploit protection overrides, Github Desktop now works for me again.

Attached is the XML file I exported from the Windows 10 Exploit Protection setup.
Github_exploit_settings.txt

Chris Shaker

Desktop barfs with cygheap base mismatch detected · Issue #3096 · desktop/desktop · GitHub

⇧  上記サイト様によりますと、使いたいコマンドの数だけ設定しないといけないらしい...嘘でしょ...

設定する場合は、「アプリとブラウザーコントロール」の、

f:id:ts0818:20191117103517p:plain

Windows セキュリティ」が開いたら、 下の方にスクロールして、

f:id:ts0818:20191117103634p:plain

「Exploit protection の設定」をクリック。

f:id:ts0818:20191117103809p:plain

「プログラム設定」のほうで、「プログラムを追加してカスタマイズ」をクリックで、

f:id:ts0818:20191117111429p:plain

1つ1つ、追加したい「.exe」ファイルを設定してあげないといけないらしい...マジか...言葉も無いわ...。

ちなみに、

kotaeta.com

⇧  「Git for Windows」と「GitHub Desktop」別物らしく、
Desktop barfs with cygheap base mismatch detected · Issue #3096 · desktop/desktop · GitHub」の見本の「Github_exploit_settings.txt」は、「GitHub Desktop」用の設定になってるっぽいです。

Git for Windows を使ってる場合でインストール先がデフォルトであるのならば、git bashで利用できるUnix系のコマンドのある binディレクトリまでのパスは、

C:\Program Files\Git\usr\bin    

になるかと。

ということで、やっぱり、Windowsのせいでした。

Microsoftさん、もっと自分たちの仕事に責任をもって、どんな影響が及ぶのかっていう情報を展開してくれんもんかね...

影響調査とかやんなくて良いなんて、楽な仕事ですよね...

2019年11月17日(日)10:00 追記 ↑ ここまで