Closed19

FFmpeg Build Battle

四ツ山伊吹四ツ山伊吹

ルール

FFmpegの実行可能プログラム ffmpeg を、静的に、かつ最も小さいファイルサイズでビルドできた人が優勝🏆

現在の結果

1,964,032 bytes

$ ldd ffmpeg
	not a dynamic executable
$ stat --printf ' File: %n\n'' Size: %s\n''Birth: %w\n' ffmpeg
 File: ffmpeg
 Size: 1964032
Birth: 2023-07-15 14:51:21.075823600 +0000
$ ./ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Ubuntu 12.2.0-17ubuntu1)
configuration: --disable-everything --disable-swresample --disable-swscale --enable-ffmpeg --disable-ffplay --disable-ffprobe --disable-doc --disable-iconv --disable-autodetect --cpu=native --enable-small --enable-lto --extra-ldflags=-static
libavutil      58.  2.100 / 58.  2.100
libavcodec     60.  3.100 / 60.  3.100
libavformat    60.  3.100 / 60.  3.100
libavdevice    60.  1.100 / 60.  1.100
libavfilter     9.  3.100 /  9.  3.100
四ツ山伊吹四ツ山伊吹

[WIP] ことのはじまり

なんかいい感じのFFmpegのバイナリ」が欲しいと思ったことがある人は、きっとたくさんいるだろう。実は、それは「ぼくのかんがえたさいきょうのFFmpeg」とも言えるのではないかと思ったりする。

いわゆる「全部入り」とされる、リンク可能な外部ライブラリをすべて含めたFFmpegをビルドするという有志の試みは以前からあった。こうした試みの方向とは逆に、〝vanilla〟なFFmpeg、つまり外部ライブラリひとつも依存しないFFmpegをつくろうというのがこの記事の狙いのひとつだ。

以下は筆者の要求である:

  1. 再頒布が許諾されたバイナリであること
  2. 〝static build〟であること
  3. ファイルサイズが小さいこと

そしてできればこれらをMakefileのレシピとして記録しておきたいし、Dockerfileとして環境問わず利用できるようにしておきたい。

四ツ山伊吹四ツ山伊吹

オプションを一切つけずにふつうにビルド

$ ./configure
$ make

結果

$ ./ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Ubuntu 12.2.0-17ubuntu1)
configuration: 
libavutil      58.  2.100 / 58.  2.100
libavcodec     60.  3.100 / 60.  3.100
libavformat    60.  3.100 / 60.  3.100
libavdevice    60.  1.100 / 60.  1.100
libavfilter     9.  3.100 /  9.  3.100
libswscale      7.  1.100 /  7.  1.100
libswresample   4. 10.100 /  4. 10.100

$ stat -c '%s' ffmpeg
22055904
License LGPL version 2.1 or later
static yes
shared no
External libraries iconv
Libraries avcodec, avdevice, avfilter, avformat, avutil, swresample, swscale
Programs ffmpeg, ffprobe
Enabled decoders いっぱい
Enabled encoders いっぱい
Enabled parsers いっぱい
Enabled demuxers いっぱい
Enabled muxers いっぱい
Enabled protocols いっぱい
Enabled filters いっぱい
Enabled bsfs いっぱい
Enabled indevs fbdev, lavfi, oss, v4l2
Enabled outdevs fbdev, oss, v4l2
四ツ山伊吹四ツ山伊吹
./configure
install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             yasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes
AVX-512 enabled           yes
AVX-512ICL enabled        yes
XOP enabled               yes
FMA3 enabled              yes
FMA4 enabled              yes
i686 features enabled     yes
CMOV is fast              yes
EBX available             yes
EBP available             yes
debug symbols             yes
strip symbols             yes
optimize for size         no
optimizations             yes
static                    yes
shared                    no
postprocessing support    no
network support           yes
threading support         pthreads
safe bitstream reader     yes
texi2html enabled         no
perl enabled              yes
pod2man enabled           yes
makeinfo enabled          no
makeinfo supports HTML    no
xmllint enabled           no

External libraries:
iconv

External libraries providing hardware acceleration:
v4l2_m2m

Libraries:
avcodec                 avfilter                avutil                  swscale
avdevice                avformat                swresample

Programs:
ffmpeg                  ffprobe

Enabled decoders:
[中略]

Enabled encoders:
[中略]

Enabled hwaccels:

Enabled parsers:
[中略]

Enabled demuxers:
[中略]

Enabled muxers:
[中略]

Enabled protocols:
[中略]

Enabled filters:
[中略]

Enabled bsfs:
[中略]

Enabled indevs:
fbdev                   lavfi                   oss                     v4l2

Enabled outdevs:
fbdev                   oss                     v4l2

License: LGPL version 2.1 or later
四ツ山伊吹四ツ山伊吹

nonfree なライセンスになるようにビルド

$ ./configure --enable-gpl --enable-version3 --enable-nonfree
$ make

結果

オプションなしと比べて:

$ ./ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Ubuntu 12.2.0-17ubuntu1)
configuration: --enable-gpl --enable-version3 --enable-nonfree
libavutil      58.  2.100 / 58.  2.100
libavcodec     60.  3.100 / 60.  3.100
libavformat    60.  3.100 / 60.  3.100
libavdevice    60.  1.100 / 60.  1.100
libavfilter     9.  3.100 /  9.  3.100
libswscale      7.  1.100 /  7.  1.100
libswresample   4. 10.100 /  4. 10.100
libpostproc    57.  1.100 / 57.  1.100

$ stat -c '%s' ffmpeg
22424544
License nonfree and unredistributable
static yes
shared no
External libraries iconv
Libraries avcodec, avdevice, avfilter, avformat, avutil, postproc, swresample, swscale
Programs ffmpeg, ffprobe
Enabled decoders いっぱい
Enabled encoders いっぱい
Enabled parsers いっぱい
Enabled demuxers いっぱい
Enabled muxers いっぱい
Enabled protocols いっぱい
Enabled filters いっぱい
Enabled bsfs いっぱい
Enabled indevs fbdev, lavfi, oss, v4l2
Enabled outdevs fbdev, oss, v4l2
四ツ山伊吹四ツ山伊吹
./configure --enable-gpl --enable-version3 --enable-nonfree
install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             yasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes
AVX-512 enabled           yes
AVX-512ICL enabled        yes
XOP enabled               yes
FMA3 enabled              yes
FMA4 enabled              yes
i686 features enabled     yes
CMOV is fast              yes
EBX available             yes
EBP available             yes
debug symbols             yes
strip symbols             yes
optimize for size         no
optimizations             yes
static                    yes
shared                    no
postprocessing support    yes
network support           yes
threading support         pthreads
safe bitstream reader     yes
texi2html enabled         no
perl enabled              yes
pod2man enabled           yes
makeinfo enabled          no
makeinfo supports HTML    no
xmllint enabled           no

External libraries:
iconv

External libraries providing hardware acceleration:
v4l2_m2m

Libraries:
avcodec                 avfilter                avutil                  swresample
avdevice                avformat                postproc                swscale

Programs:
ffmpeg                  ffprobe

Enabled decoders:
[中略]

Enabled encoders:
[中略]

Enabled hwaccels:

Enabled parsers:
[中略]

Enabled demuxers:
[中略]

Enabled muxers:
[中略]

Enabled protocols:
[中略]

Enabled filters:
[中略]

Enabled bsfs:
[中略]

Enabled indevs:
fbdev                   lavfi                   oss                     v4l2

Enabled outdevs:
fbdev                   oss                     v4l2

License: nonfree and unredistributable
四ツ山伊吹四ツ山伊吹

ライセンスに関する補足

configure に与えるオプションでライセンスは次のように変わる。

ライセンス オプション
LGPL version 2.1 or later --disable-gpl --disable-version3 --disable-nonfree(既定)
LGPL version 3 or later --disable-gpl --enable-version3 --disable-nonfree
GPL version 2 or later --enable-gpl --disable-version3 --disable-nonfree
GPL version 3 or later --enable-gpl --enable-version3 --disable-nonfree
四ツ山伊吹四ツ山伊吹

すべてのcomponentを無効にしてビルド

ここでいうcomponentとは、decoder/encoder/parser/...などのこと。

$ ./configure --disable-everything
$ make

結果

オプションなしと比べて:

  • ファイルサイズは劇的に縮小 (22,055,904B → 1,624,336B)。もとの7%の大きさ。
  • --disable-everything したにも関わらず、一部のfilterは利用可能なままとなっている。これらはFFmpegの核心を担っているため無効化できないとか?
  • 利用可能なcodecもformatも何もないので、CLIプログラムとしてのffmpegは存在しても、事実上何もできることがない。
  • コマンドラインヘルプは利用できる。ただし、各componentのセクションは外されている。./ffmpeg -hide_banner -h full が現実的な文量になる。
./ffmpeg -hide_banner -filters
Filters:
  T.. = Timeline support
  .S. = Slice threading
  ..C = Command support
  A = Audio input/output
  V = Video input/output
  N = Dynamic number and/or type of input/output
  | = Source or sink filter
 ... aformat           A->A       Convert the input audio to one of the specified formats.
 ... anull             A->A       Pass the source unchanged to the output.
 ... atrim             A->A       Pick one continuous section from the input, drop the rest.
 ... format            V->V       Convert the input video to one of the specified pixel formats.
 TS. hflip             V->V       Horizontally flip the input video.
 ... null              V->V       Pass the source unchanged to the output.
 .S. transpose         V->V       Transpose input video.
 ... trim              V->V       Pick one continuous section from the input, drop the rest.
 T.. vflip             V->V       Flip the input video vertically.
 ... abuffer           |->A       Buffer audio frames, and make them accessible to the filterchain.
 ... buffer            |->V       Buffer video frames, and make them accessible to the filterchain.
 ... abuffersink       A->|       Buffer audio frames, and make them available to the end of the filter graph.
 ... buffersink        V->|       Buffer video frames, and make them available to the end of the filter graph.
$ ./ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Ubuntu 12.2.0-17ubuntu1)
configuration: --disable-everything
libavutil      58.  2.100 / 58.  2.100
libavcodec     60.  3.100 / 60.  3.100
libavformat    60.  3.100 / 60.  3.100
libavdevice    60.  1.100 / 60.  1.100
libavfilter     9.  3.100 /  9.  3.100
libswscale      7.  1.100 /  7.  1.100
libswresample   4. 10.100 /  4. 10.100

$ stat -c '%s' ffmpeg
1624336
License LGPL version 2.1 or later
static yes
shared no
External libraries iconv
Libraries avcodec, avdevice, avfilter, avformat, avutil, swresample, swscale
Programs ffmpeg, ffprobe
Enabled decoders なし
Enabled encoders なし
Enabled parsers なし
Enabled demuxers なし
Enabled muxers なし
Enabled protocols なし
Enabled filters aformat, format, transpose, anull, hflip, trim, atrim, null, vflip
Enabled bsfs なし
Enabled indevs なし
Enabled outdevs なし
四ツ山伊吹四ツ山伊吹
./configure --disable-everything
install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             yasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes
AVX-512 enabled           yes
AVX-512ICL enabled        yes
XOP enabled               yes
FMA3 enabled              yes
FMA4 enabled              yes
i686 features enabled     yes
CMOV is fast              yes
EBX available             yes
EBP available             yes
debug symbols             yes
strip symbols             yes
optimize for size         no
optimizations             yes
static                    yes
shared                    no
postprocessing support    no
network support           yes
threading support         pthreads
safe bitstream reader     yes
texi2html enabled         no
perl enabled              yes
pod2man enabled           yes
makeinfo enabled          no
makeinfo supports HTML    no
xmllint enabled           no

External libraries:
iconv

External libraries providing hardware acceleration:
v4l2_m2m

Libraries:
avcodec                 avfilter                avutil                  swscale
avdevice                avformat                swresample

Programs:
ffmpeg                  ffprobe

Enabled decoders:

Enabled encoders:

Enabled hwaccels:

Enabled parsers:

Enabled demuxers:

Enabled muxers:

Enabled protocols:

Enabled filters:
aformat                 format                  transpose
anull                   hflip                   trim
atrim                   null                    vflip

Enabled bsfs:

Enabled indevs:

Enabled outdevs:

License: LGPL version 2.1 or later
四ツ山伊吹四ツ山伊吹

すべてのcomponentプラス一部のライブラリを無効にしてビルド

「すべてのcomponentを無効にしてビルド」に加えて、libswresamplelibswscale、を無効化する。

$ ./configure --disable-everything --disable-swresample --disable-swscale
$ make

結果

「すべてのcomponentを無効にしてビルド」と比べて:

  • ファイルサイズはさらに減少 (1,624,336B → 1,042,704B)。
  • 残るライブラリ libav* を削ったところ、make した後にffmpegファイルが生成されなくなったので、これら libavcodec, libavformat, libavdevice, libavfilter がFFmpegにとっての必須項目らしい。
$ ./ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Ubuntu 12.2.0-17ubuntu1)
configuration: --disable-everything --disable-swresample --disable-swscale
libavutil      58.  2.100 / 58.  2.100
libavcodec     60.  3.100 / 60.  3.100
libavformat    60.  3.100 / 60.  3.100
libavdevice    60.  1.100 / 60.  1.100
libavfilter     9.  3.100 /  9.  3.100

$ stat -c '%s' ffmpeg
1042704
License LGPL version 2.1 or later
static yes
shared no
External libraries iconv
Libraries avcodec, avdevice, avfilter, avformat, avutil
Programs ffmpeg, ffprobe
Enabled decoders なし
Enabled encoders なし
Enabled parsers なし
Enabled demuxers なし
Enabled muxers なし
Enabled protocols なし
Enabled filters aformat, format, transpose, anull, hflip, trim, atrim, null, vflip
Enabled bsfs なし
Enabled indevs なし
Enabled outdevs なし
四ツ山伊吹四ツ山伊吹
./configure --disable-everything --disable-swresample --disable-swscale
install prefix            /usr/local
source path               .
C compiler                gcc
C library                 glibc
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             yasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes
AVX-512 enabled           yes
AVX-512ICL enabled        yes
XOP enabled               yes
FMA3 enabled              yes
FMA4 enabled              yes
i686 features enabled     yes
CMOV is fast              yes
EBX available             yes
EBP available             yes
debug symbols             yes
strip symbols             yes
optimize for size         no
optimizations             yes
static                    yes
shared                    no
postprocessing support    no
network support           yes
threading support         pthreads
safe bitstream reader     yes
texi2html enabled         no
perl enabled              yes
pod2man enabled           yes
makeinfo enabled          no
makeinfo supports HTML    no
xmllint enabled           no

External libraries:
iconv

External libraries providing hardware acceleration:
v4l2_m2m

Libraries:
avcodec                 avfilter                avutil
avdevice                avformat

Programs:
ffmpeg                  ffprobe

Enabled decoders:

Enabled encoders:

Enabled hwaccels:

Enabled parsers:

Enabled demuxers:

Enabled muxers:

Enabled protocols:

Enabled filters:
aformat                 format                  transpose
anull                   hflip                   trim
atrim                   null                    vflip

Enabled bsfs:

Enabled indevs:

Enabled outdevs:

License: LGPL version 2.1 or later
四ツ山伊吹四ツ山伊吹

そのほか、ビルドの生成物に関係することしないこと

以下は「すべてのcomponentプラス一部のライブラリを無効にしてビルド」に加えて検証した。

--enable-ffmpeg --disable-ffplay --disable-ffprobe

ffmpegのみビルドする。ffplayffprobeはビルドしない。ffmpegさえあれば良い時に。

--disable-doc

FFmpegのドキュメントをいずれもビルドしない。ドキュメントが不要な時に。

--disable-iconv

iconvライブラリを無効にする。ファイルサイズはごく僅か(数十bytes)に縮む。

--disable-autodetect

外部ライブラリの自動検出を無効にする。ここではhardware accelerationが無効化されることになる。ファイルサイズに変化は生じない。手動で設定するには--disable-v4l2-m2m(環境依存?)。

--disable-debug

“disable debugging symbols” とあるのだが……オプションの有無でファイルサイズに変化は生じなかった。--enable-debug としても変わりなし。

--disable-runtime-cpudetect

“disable detecting CPU capabilities at runtime (smaller binary)” とあるが、configureの中で特別何かをしている様子も無く、また出来上がったバイナリのファイルサイズもこのオプションの有無で変化は生じなかった。

四ツ山伊吹四ツ山伊吹

コンパイラの最適化オプションに関わるところ

--arch=ARCH

特にAMD64/Intel 64については、引数ARCHにはx86のほか、これの別名として (i[3-6]86*|i86pc|BePC|x86pc|x86_64|x86_32|amd64)configureに対して指定できるようだ。ただし、何れにせよファイルサイズに差異は生じない(32-bit/64-bit、あるいはAMDだろうと関係なさそう)。

GCCにおける -march におおむね対応する。

--cpu=CPU

“select the minimum required CPU” とあり、コンパイラでCPU(の命令セットアーキテクチャ)に応じた最適化が行われる。手元のPCでは --cpu=native としてビルドしたところ、ファイルサイズは僅かに(1%未満)縮んだ。

GCCにおける -mcpu に対応する?

--arch=ARCH--cpu=CPU に関する補足

https://trac.ffmpeg.org/wiki/CompilationGuide#PerformanceTips

--enable-small

“optimize for size instead of speed”。

GCCでは -Os の最適化を行う。これは -O2 からファイルサイズをより大きくするような項目を除外した最適化を行うとされる。これはコマンドラインヘルプにあるように実行速度の低下というトレードオフを伴う。

--enable-optimizations

暗黙的に既定で有効となっている。

GCCでは -O2 の最適化を行う。configureでは--enable-smallとは排他的に適用されることになる(両方指定した場合には--enable-smallが優先される)。

--enable-lto

link-time optimization(鏈接時最適化)。

GCCでは -flto オプションに対応する。詳しくは https://gcc.gnu.org/onlinedocs/ の gcc-<version>/gcc/Optimize-Options.html#index-flto

四ツ山伊吹四ツ山伊吹

静的なライブラリと共有ライブラリ

簡単なまとめ

  • 静的な実行可能プログラムにするほど、ファイルサイズは増大するが、ポータビリティは強まる。
  • 動的な実行可能プログラムにするほど、ファイルサイズは減少するが、ポータビリティは損なわれる。

補足

既定では --enable-static となっている。これは、FFmpeg本体を構成するlibavcodecをはじめとするライブラリは静的なライブラリとして生成され、それからffmpegなどの実行可能プログラムに対してはそのコンパイル時にリンクされることを意味する。

ただしこのオプションは、FFmpegの外にあるライブラリは無視する。ldd コマンドを使って依存関係を調べると、たしかに標準Cライブラリ (libc.so.6) と数学ライブラリ (libm.so.6) が ffmpeg から共有ライブラリとして依存されていることが分かる。

--enable-static
$ ldd ffmpeg
	linux-vdso.so.1 (0x00007fff7de36000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5943b86000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f59439a5000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f5943d6c000)

そういうわけで、実行可能プログラムは標準の動的リンカによって共有ライブラリと実行時にリンクされる。Linuxにおいては linux-vdsold-linux とがその役割を担っている。

そうではなく、すべてのライブラリを静的にリンクするには configure に追加のオプションを与える必要がある。vanillaなFFmpegに対しては --extra-ldflags=-static で静的な実行可能プログラムが出来上がる。

--enable-static --extra-ldflags=-static
$ ldd ffmpeg
	not a dynamic executable

その一方で、--disable-static --enable-shared とすると、上記のlibavcodecといったものは静的ライブラリの代わりに共有ライブラリとして生成される。

--disable-static --enable-shared
$ make
[中略]

$ ls libav*/libav*.so # 拡張子 `.so' の共有ライブラリが生成される。
libavcodec/libavcodec.so    libavfilter/libavfilter.so  libavutil/libavutil.so
libavdevice/libavdevice.so  libavformat/libavformat.so

$ ls libav*/libav*.a # 拡張子 `.a' の静的ライブラリは生成されない。
ls: cannot access 'libav*/libav*.a': No such file or directory

ldd コマンドを使って依存関係を調べてみると、たしかに ffmpeg の実行可能プログラムから標準Cライブラリと数学ライブラリに加え、FFmpegのライブラリも共有ライブラリとして依存されていることが分かる。

$ ldd ffmpeg
	linux-vdso.so.1 (0x00007fffe33e1000)
	libavdevice.so.60 => not found
	libavfilter.so.9 => not found
	libavformat.so.60 => not found
	libavcodec.so.60 => not found
	libavutil.so.58 => not found
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2ce37b2000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2ce35ad000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f2ce38f0000)

ところでこの出力結果から分かるように、FFmpegのライブラリが => not found となっており、これは動的リンカである /lib64/ld-linux-x86-64.so.2 が対象のライブラリを見つけられなかったことを意味する。要はこのままでは実行できないので動的リンカに共有ライブラリがどこにあるか教えてやる必要がある。環境変数 LD_LIBRARY_PATH にコロン (:) 区切りでパスを指定することで解決できる。

$ LD_LIBRARY_PATH=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil ./ffmpeg -version
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12 (Ubuntu 12.2.0-17ubuntu1)
configuration: --disable-gpl --disable-version3 --disable-nonfree --enable-static --disable-shared --disable-autodetect --enable-ffmpeg --disable-ffplay --disable-ffprobe --disable-doc --disable-everything --disable-postproc --disable-swresample --disable-swscale
libavutil      58.  2.100 / 58.  2.100
libavcodec     60.  3.100 / 60.  3.100
libavformat    60.  3.100 / 60.  3.100
libavdevice    60.  1.100 / 60.  1.100
libavfilter     9.  3.100 /  9.  3.100
四ツ山伊吹四ツ山伊吹

各種リンカのドキュメント

ld - The GNU linker (GNU Binutils)

https://sourceware.org/binutils/

https://sourceware.org/binutils/docs-2.40/ld.html

コマンドラインヘルプ
$ ld --help

source: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git

gold - The GNU ELF linker (GNU Binutils)

コマンドラインヘルプ
$ gold --help

LLD - The LLVM Linker (LLVM project)

https://lld.llvm.org/

コマンドラインヘルプ
$ ld.lld --help

source: https://github.com/llvm/llvm-project

manual page: https://github.com/llvm/llvm-project/blob/main/lld/docs/ld.lld.1

ld64 - The Darwin linker (Apple Developer Tools)

https://opensource.apple.com/source/ld64/ld64-609/doc/design/linker.html

source: https://github.com/apple-oss-distributions/ld64

manual page: https://github.com/apple-oss-distributions/ld64/blob/main/doc/man/man1/ld.1


ld.so, ld-linux.so - dynamic linker/loader (Linux)

https://man7.org/linux/man-pages/man8/ld.so.8.html

関連項目: vdso - overview of the virtual ELF dynamic shared object

コマンドラインヘルプ
# 下記のいずれか
/lib/ld-linux.so.2 --help
/lib64/ld-linux-x86-64.so.2 --help
/libx32/ld-linux-x32.so.2 --help

dyld - the dynamic linker (Apple macOS)

source: https://github.com/apple-oss-distributions/dyld

四ツ山伊吹四ツ山伊吹

コンパイラとツールチェーン

せっかくなのでLLVMプロジェクトのClangとLLDを使ってビルドしてみる。clang-15lld に環境変数 PATH が通っていることを前提として、configure オプションに --cc=clang-15--extra-ldflags=-fuse-ld=lld を加えてやれば良い。

結果は既定のツールチェーンと比べてファイルサイズは微増となった。

脚注
  1. https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/ ↩︎

このスクラップは2023/09/20にクローズされました