{"action":"created","issue":{"url":"https://api.github.com/repos/joelpx/reverse/issues/7","labels_url":"https://api.github.com/repos/joelpx/reverse/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/joelpx/reverse/issues/7/comments","events_url":"https://api.github.com/repos/joelpx/reverse/issues/7/events","html_url":"https://github.com/joelpx/reverse/issues/7","id":62686079,"number":7,"title":"GCC optimizations (-Os, -O2, -O3 but not -O1) cause KeyError","user":{"login":"dnet","id":163115,"avatar_url":"https://avatars.githubusercontent.com/u/163115?v=3","gravatar_id":"","url":"https://api.github.com/users/dnet","html_url":"https://github.com/dnet","followers_url":"https://api.github.com/users/dnet/followers","following_url":"https://api.github.com/users/dnet/following{/other_user}","gists_url":"https://api.github.com/users/dnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnet/subscriptions","organizations_url":"https://api.github.com/users/dnet/orgs","repos_url":"https://api.github.com/users/dnet/repos","events_url":"https://api.github.com/users/dnet/events{/privacy}","received_events_url":"https://api.github.com/users/dnet/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-18T12:52:10Z","updated_at":"2015-03-18T13:06:23Z","closed_at":"2015-03-18T13:05:24Z","body":"The file `keyerror.c` has the following contents:\r\n\r\n```c\r\nint main(int argc, char **argv) {\r\n    return 0;\r\n}\r\n```\r\n\r\nI compiled several versions that only differ in optimization level:\r\n\r\n    $ gcc     keyerror.c -o keyerror-normal\r\n    $ gcc -O1 keyerror.c -o keyerror-o1\r\n    $ gcc -O2 keyerror.c -o keyerror-o2\r\n    $ gcc -O3 keyerror.c -o keyerror-o3\r\n    $ gcc -Os keyerror.c -o keyerror-os\r\n\r\nThe first two work like it should:\r\n\r\n    $ python3 reverse.py keyerror-normal\r\n    function main {\r\n        0x4004b6: push rbp\r\n        0x4004b7: rbp = rsp # mov rbp, rsp\r\n        0x4004ba: var1 = edi # mov dword ptr [rbp - 4], edi\r\n        0x4004bd: var2 = rsi # mov qword ptr [rbp - 0x10], rsi\r\n        0x4004c1: eax = 0 # mov eax, 0\r\n        0x4004c6: pop rbp\r\n        0x4004c7: ret\r\n    }\r\n    $ python3 reverse.py keyerror-o1\r\n    function main {\r\n        0x4004b6: eax = 0 # mov eax, 0\r\n        0x4004bb: ret\r\n    }\r\n\r\nHowever, the other three cause `KeyError` like below:\r\n\r\n    $ python3 reverse.py keyerror-o2\r\n    Traceback (most recent call last):\r\n      File \"reverse.py\", line 122, in <module>\r\n        gph = dis.extract_func(addr)\r\n      File \"/home/dnet/_projekt/reverse/lib/disassembler.py\", line 195, in extract_func\r\n        curr = self.code[addr]\r\n    KeyError: 4195264\r\n    $ python3 reverse.py keyerror-o3\r\n    Traceback (most recent call last):\r\n      File \"reverse.py\", line 122, in <module>\r\n        gph = dis.extract_func(addr)\r\n      File \"/home/dnet/_projekt/reverse/lib/disassembler.py\", line 195, in extract_func\r\n        curr = self.code[addr]\r\n    KeyError: 4195264\r\n    $ python3 reverse.py keyerror-os\r\n    Traceback (most recent call last):\r\n      File \"reverse.py\", line 122, in <module>\r\n        gph = dis.extract_func(addr)\r\n      File \"/home/dnet/_projekt/reverse/lib/disassembler.py\", line 195, in extract_func\r\n        curr = self.code[addr]\r\n    KeyError: 4195264\r\n\r\nI zipped and uploaded the source file and the five binaries to http://vsza.hu/joelpx-reverse-issue-keyerror-20150318.zip"},"comment":{"url":"https://api.github.com/repos/joelpx/reverse/issues/comments/82962236","html_url":"https://github.com/joelpx/reverse/issues/7#issuecomment-82962236","issue_url":"https://api.github.com/repos/joelpx/reverse/issues/7","id":82962236,"user":{"login":"joelpx","id":4718852,"avatar_url":"https://avatars.githubusercontent.com/u/4718852?v=3","gravatar_id":"","url":"https://api.github.com/users/joelpx","html_url":"https://github.com/joelpx","followers_url":"https://api.github.com/users/joelpx/followers","following_url":"https://api.github.com/users/joelpx/following{/other_user}","gists_url":"https://api.github.com/users/joelpx/gists{/gist_id}","starred_url":"https://api.github.com/users/joelpx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelpx/subscriptions","organizations_url":"https://api.github.com/users/joelpx/orgs","repos_url":"https://api.github.com/users/joelpx/repos","events_url":"https://api.github.com/users/joelpx/events{/privacy}","received_events_url":"https://api.github.com/users/joelpx/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T13:06:23Z","updated_at":"2015-03-18T13:06:23Z","body":"Yes i've juste checked."}}