main=195;
Segmentation fault する。
Plamo Linux 5.0 x86_64版にて
$ cat main195.c main=195; $ gcc main195.c $ ./a.out Segmentation fault
gcc の attribute で section 指定
$ cat main195.c __attribute__((section(".text")))main=195; $ gcc main195.c $ ./a.out # Segmentation fault しない
33文字も長くなった。
GNU as のオプションを使う
GCC の man page より
http://linuxjm.sourceforge.jp/html/GNU_gcc/man1/gcc.1.html
- -Wa,option
- option をアセンブラに対するオプションとして渡します。option がコンマを含む場合は、そのコンマで区切られた複数のオプションとして与えられます。
GNU as の man page より
http://linuxjm.sourceforge.jp/html/GNU_binutils/man1/as.1.html
- -R
- データセクションをテキストセクションと一緒にする。
$ cat main195.c main=195; $ gcc -Wa,-R main195.c $ ./a.out # Segmentation fault しない
コマンドが 7文字長くなるだけで OK。