8
3

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 3 years have passed since last update.

C言語で0文字でセグフォらせる(ただし外道)

Last updated at Posted at 2020-07-01

から始まったセグフォコードゴルフ。やってみよー

参考リンク:

pythonを三行でセグフォらせる

pythonを2行でセグフォらせる

C言語で16文字でセグフォらせる

外道な回答

a.c

以上です!!やったー!!0文字だー!!

やったーじゃない、これにコンパイラオプション指定してごにょごにょしてやる。

[kmtr@localhost ~]$ cat Makefile
all: a.out

a.out : a.c Makefile
        LANG=C gcc a.c -o a.out -nostdlib -Wl,--build-id=none

clean :
        rm a.out

コンパイルと実行時のログ

[kmtr@localhost ~]$ cat a.c
[kmtr@localhost ~]$ make a.out
LANG=C gcc a.c -o a.out -nostdlib -Wl,--build-id=none
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078
[kmtr@localhost ~]$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
[kmtr@localhost ~]$ ./a.out
Segmentation fault (コアダンプ)

解説というほどでない解説

-nostdlib

リンク時に、標準スタートアップや標準ライブラリを使いません。

--build-id=none

気分でつけているだけですが、コンパイル時のsessionに紐づいたハッシュを生成しなくする(なくてもよい)

以上です。いや、何も書くことがない……

8
3
4

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
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?