最近ツイッターで
“while(1){LOVE++}”と書き込まれてる指輪があって、
そのソースは最適化でLOVEが消えてただの無限ループになる云々という話があったので検証。
用意したソースはこちら。
int main()
{
int LOVE = 0;
while(1){LOVE++;}
}
それじゃアセンブラを見てみましょ。
まずは最適化抜き。
gcc -O0 -s hoge.c
.file “hoge.c”
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl $0, -4(%ebp) ;LOVE=0
.L2:
addl $1, -4(%ebp) ;LOVE++
jmp .L2 ;JUMP TO L2
.size main, .-main
.ident “GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5”
.section .note.GNU-stack,”“,@progbits
LOVEは残ってますね。
gcc -O1 -s hoge.c
.file “hoge.c”
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
.L2:
jmp .L2 ;JUMP TO L2
.size main, .-main
.ident “GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5”
.section .note.GNU-stack,”“,@progbits
愛は最適化によって消滅しました。
447 notes
-
jun5k liked this
-
gogatsu26 liked this
-
katumayo reblogged this from gearmann
-
iaskell reblogged this from gearmann
-
gearmann reblogged this from poochin
-
fyam reblogged this from poochin
-
flashno1 reblogged this from poochin
-
flashno1 reblogged this from poochin
-
tamanobi liked this
-
kurostock liked this
-
ken-ton liked this
-
kappumblr reblogged this from poochin
-
poochin reblogged this from teokure
-
teokure reblogged this from goooose350
-
bdal400 reblogged this from es-s-etc
-
es-s-etc reblogged this from arccosine
-
goooose350 reblogged this from yamada123456789
-
bubirons reblogged this from exilias
-
misao17 reblogged this from anijakatze
-
yamada123456789 reblogged this from pengm-q
-
soulsphere reblogged this from kyomtea
-
chlono reblogged this from eimelle
-
pengm-q reblogged this from oyaki
-
yoc reblogged this from eimelle
-
oyaki reblogged this from manshiro
-
tsunafkin reblogged this from amagiri
-
amagiri reblogged this from arccosine
-
soulsphere liked this
-
smbd reblogged this from anijakatze
-
nawolets liked this
-
exilias liked this
-
exilias reblogged this from eimelle
-
manshiro reblogged this from anijakatze
-
arccosine reblogged this from anijakatze
-
kyomtea reblogged this from anijakatze
-
anijakatze reblogged this from eimelle
-
eimelle reblogged this from yuibb
-
jjjackps reblogged this from mamemomonga
-
bivanilla reblogged this from hcm-pri
-
colvetanta liked this
-
mamemomonga reblogged this from hcm-pri
-
hcm-pri reblogged this from yuibb
-
mozillerman reblogged this from yuibb
-
inariwan reblogged this from misoka
-
ryhmrt reblogged this from chordstriker
-
mkoji reblogged this from chordstriker
-
chordstriker reblogged this from hishochi
-
dfgkelxp reblogged this from nacookan
- Show more notes
