FreeBSD で root は gcc_s を拾え uyota は失敗2017年07月01日 11時35分12秒

一般ユーザで「/usr/bin/ld: cannot find -lgcc_s」のためリンク出来ない問題で悩んでいる。ちょっと横道にそれたが、libgcc について調べた。他の FreeBSD で報告されている問題とは若干違うようだ。

まずは、コンパイルとリンクを切り分ける。現在の環境は、もうすぐリリースされる FreeBSD 11.1-RELEASE相当。PRERELEASE だったり、RC だったするが、大した違いは無い。

% cat a.c 
int main(){ return 0; }
% cc -c a.c 
コンパイル自体に問題は無い。
% cc a.o
/usr/bin/ld: cannot find -lgcc_s
cc: error: linker command failed with exit code 1 (use -v to see invocation)
リンク時に失敗。
% cc -v a.o
FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 4.0.0)
Target: i386-unknown-freebsd11.1
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags
-m elf_i386_fbsd -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib a.o -lgcc --as-needed
-lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
/usr/bin/ld: cannot find -lgcc_s
cc: error: linker command failed with exit code 1 (use -v to see invocation)

不思議なことに、root で実行すると全く同じコマンドなのに成功する。

$ cc -v a.o
FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on LLVM 4.0.0)
Target: i386-unknown-freebsd11.1
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags
-m elf_i386_fbsd -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib a.o -lgcc --as-needed
-lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
$  ls -l a.out
-rwxr-xr-x  1 root  uyota  5355 Jun 30 01:24 a.out
二つのアカウントのライブラリ関連の環境変数も調べてみたが、違いは見当たらない。

前回次回