0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Goの実行ファイルがどの OS/アーキテクチャ 向けにビルドされたか判別する

Last updated at Posted at 2019-08-19

ちゃんとテストしてませんが、だいたいこれで行けると思います。

strings $(BIN_FILE_PATH) | grep -oP '(?<=rt0_).+(?=\.s)'

解説

Goの実行ファイルにはビルド時に使用したソースファイルへのパスが含まれており、さらに Go をビルドする際には必ず GOOSGOARCH に対応した runtime/rt0_XXX.s が使用されるため、この方法が使えます。

補足

Windows 環境には stringsgrep もデフォルトでは入っていないので、busybox を使いましょう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?