On Thu, Jun 21, 2012 at 07:54:35AM -0400, James McCoy wrote: > On Thu, Jun 21, 2012 at 07:59:06AM +0200, Philipp Marek wrote: > > Just out of curiosity, could you show the disassembler output of the > > OutputWrite() function for gcc-4.6, and gcc-4.7 with -O1 and -O2? > > > > # objdump -Sgd <name-of-obj-file> > > > > and pasting only this function might be a good way. > > Sure, attached files for those combinations.
Another potentially useful data point is that adding -fstack-protector causes -O1 to no longer work. I noticed this while trying to prepare an upload of Vim which works around the optimization problem. With -fstack-protector, I have to drop down to -O0 to get the code to work. -- James GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <james...@debian.org>
0000000000001b2a <OutputWrite>: /* Output buffer management */ static PyObject * OutputWrite(PyObject *self, PyObject *args) { 1b2a: 55 push %rbp 1b2b: 53 push %rbx 1b2c: 48 83 ec 18 sub $0x18,%rsp 1b30: 48 89 f0 mov %rsi,%rax int len; char *str = NULL; 1b33: 48 c7 44 24 08 00 00 movq $0x0,0x8(%rsp) 1b3a: 00 00 int error = ((OutputObject *)(self))->error; 1b3c: 8b 5f 18 mov 0x18(%rdi),%ebx if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len)) 1b3f: 4c 8d 44 24 04 lea 0x4(%rsp),%r8 1b44: 48 8d 4c 24 08 lea 0x8(%rsp),%rcx 1b49: 48 8b 15 00 00 00 00 mov 0x0(%rip),%rdx # 1b50 <OutputWrite+0x26> 1b50: be 00 00 00 00 mov $0x0,%esi 1b55: 48 89 c7 mov %rax,%rdi 1b58: b8 00 00 00 00 mov $0x0,%eax 1b5d: e8 00 00 00 00 callq 1b62 <OutputWrite+0x38> 1b62: 85 c0 test %eax,%eax 1b64: 74 50 je 1bb6 <OutputWrite+0x8c> return NULL; /* TODO: This works around a gcc optimizer problem and avoids Vim * from crashing. Should find a real solution. */ if (str == NULL) 1b66: 48 83 7c 24 08 00 cmpq $0x0,0x8(%rsp) 1b6c: 74 4f je 1bbd <OutputWrite+0x93> return NULL; Py_BEGIN_ALLOW_THREADS 1b6e: e8 00 00 00 00 callq 1b73 <OutputWrite+0x49> 1b73: 48 89 c5 mov %rax,%rbp Python_Lock_Vim(); writer((writefn)(error ? emsg : msg), (char_u *)str, len); 1b76: 48 63 54 24 04 movslq 0x4(%rsp),%rdx 1b7b: 85 db test %ebx,%ebx 1b7d: b8 00 00 00 00 mov $0x0,%eax 1b82: bf 00 00 00 00 mov $0x0,%edi 1b87: 48 0f 45 f8 cmovne %rax,%rdi 1b8b: 48 8b 74 24 08 mov 0x8(%rsp),%rsi 1b90: e8 dd fc ff ff callq 1872 <writer> Python_Release_Vim(); Py_END_ALLOW_THREADS 1b95: 48 89 ef mov %rbp,%rdi 1b98: e8 00 00 00 00 callq 1b9d <OutputWrite+0x73> PyMem_Free(str); 1b9d: 48 8b 7c 24 08 mov 0x8(%rsp),%rdi 1ba2: e8 00 00 00 00 callq 1ba7 <OutputWrite+0x7d> Py_INCREF(Py_None); 1ba7: 48 83 05 00 00 00 00 addq $0x1,0x0(%rip) # 1baf <OutputWrite+0x85> 1bae: 01 return Py_None; 1baf: b8 00 00 00 00 mov $0x0,%eax 1bb4: eb 0c jmp 1bc2 <OutputWrite+0x98> int len; char *str = NULL; int error = ((OutputObject *)(self))->error; if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len)) return NULL; 1bb6: b8 00 00 00 00 mov $0x0,%eax 1bbb: eb 05 jmp 1bc2 <OutputWrite+0x98> /* TODO: This works around a gcc optimizer problem and avoids Vim * from crashing. Should find a real solution. */ if (str == NULL) return NULL; 1bbd: b8 00 00 00 00 mov $0x0,%eax Py_END_ALLOW_THREADS PyMem_Free(str); Py_INCREF(Py_None); return Py_None; } 1bc2: 48 83 c4 18 add $0x18,%rsp 1bc6: 5b pop %rbx 1bc7: 5d pop %rbp 1bc8: c3 retq
000000000000000c <OutputWrite>: /* Output buffer management */ static PyObject * OutputWrite(PyObject *self, PyObject *args) { c: 55 push %rbp d: 48 89 e5 mov %rsp,%rbp 10: 48 83 ec 30 sub $0x30,%rsp 14: 48 89 7d d8 mov %rdi,-0x28(%rbp) 18: 48 89 75 d0 mov %rsi,-0x30(%rbp) int len; char *str = NULL; 1c: 48 c7 45 f0 00 00 00 movq $0x0,-0x10(%rbp) 23: 00 int error = ((OutputObject *)(self))->error; 24: 48 8b 45 d8 mov -0x28(%rbp),%rax 28: 48 8b 40 18 mov 0x18(%rax),%rax 2c: 89 45 ec mov %eax,-0x14(%rbp) if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len)) 2f: 48 8b 15 00 00 00 00 mov 0x0(%rip),%rdx # 36 <OutputWrite+0x2a> 36: 48 8d 75 e8 lea -0x18(%rbp),%rsi 3a: 48 8d 4d f0 lea -0x10(%rbp),%rcx 3e: 48 8b 45 d0 mov -0x30(%rbp),%rax 42: 49 89 f0 mov %rsi,%r8 45: be 00 00 00 00 mov $0x0,%esi 4a: 48 89 c7 mov %rax,%rdi 4d: b8 00 00 00 00 mov $0x0,%eax 52: e8 00 00 00 00 callq 57 <OutputWrite+0x4b> 57: 85 c0 test %eax,%eax 59: 75 07 jne 62 <OutputWrite+0x56> return NULL; 5b: b8 00 00 00 00 mov $0x0,%eax 60: eb 79 jmp db <OutputWrite+0xcf> /* TODO: This works around a gcc optimizer problem and avoids Vim * from crashing. Should find a real solution. */ if (str == NULL) 62: 48 8b 45 f0 mov -0x10(%rbp),%rax 66: 48 85 c0 test %rax,%rax 69: 75 07 jne 72 <OutputWrite+0x66> return NULL; 6b: b8 00 00 00 00 mov $0x0,%eax 70: eb 69 jmp db <OutputWrite+0xcf> Py_BEGIN_ALLOW_THREADS 72: e8 00 00 00 00 callq 77 <OutputWrite+0x6b> 77: 48 89 45 f8 mov %rax,-0x8(%rbp) Python_Lock_Vim(); 7b: e8 80 ff ff ff callq 0 <Python_Lock_Vim> writer((writefn)(error ? emsg : msg), (char_u *)str, len); 80: 8b 45 e8 mov -0x18(%rbp),%eax 83: 48 63 d0 movslq %eax,%rdx 86: 48 8b 4d f0 mov -0x10(%rbp),%rcx 8a: 83 7d ec 00 cmpl $0x0,-0x14(%rbp) 8e: 74 07 je 97 <OutputWrite+0x8b> 90: b8 00 00 00 00 mov $0x0,%eax 95: eb 05 jmp 9c <OutputWrite+0x90> 97: b8 00 00 00 00 mov $0x0,%eax 9c: 48 89 ce mov %rcx,%rsi 9f: 48 89 c7 mov %rax,%rdi a2: e8 ca 02 00 00 callq 371 <writer> Python_Release_Vim(); a7: e8 5a ff ff ff callq 6 <Python_Release_Vim> Py_END_ALLOW_THREADS ac: 48 8b 45 f8 mov -0x8(%rbp),%rax b0: 48 89 c7 mov %rax,%rdi b3: e8 00 00 00 00 callq b8 <OutputWrite+0xac> PyMem_Free(str); b8: 48 8b 45 f0 mov -0x10(%rbp),%rax bc: 48 89 c7 mov %rax,%rdi bf: e8 00 00 00 00 callq c4 <OutputWrite+0xb8> Py_INCREF(Py_None); c4: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # cb <OutputWrite+0xbf> cb: 48 83 c0 01 add $0x1,%rax cf: 48 89 05 00 00 00 00 mov %rax,0x0(%rip) # d6 <OutputWrite+0xca> return Py_None; d6: b8 00 00 00 00 mov $0x0,%eax } db: c9 leaveq dc: c3 retq
signature.asc
Description: Digital signature