| Summary: | suboptimal code generated with -fPIC | ||
|---|---|---|---|
| Product: | Sisyphus | Reporter: | Alexey Voinov <voins> |
| Component: | gcc4.4 | Assignee: | Gleb F-Malinovskiy <glebfm> |
| Status: | CLOSED WORKSFORME | QA Contact: | qa-sisyphus |
| Severity: | enhancement | ||
| Priority: | P1 | CC: | glebfm |
| Version: | unstable | ||
| Hardware: | all | ||
| OS: | Linux | ||
still in gcc3.4 Same with gcc-4.1.1; maybe I should report it upstream? :) $ gcc -S -O3 -fomit-frame-pointer -fPIC -DPIC test.c -o -
.file "test.c"
.text
.p2align 4,,15
.globl f
.type f, @function
f:
.LFB12:
.cfi_startproc
testl %edi, %edi
jne .L4
xorl %eax, %eax
ret
.p2align 4,,10
.p2align 3
.L4:
movl $1, %edi
jmp malloc@PLT
.cfi_endproc
.LFE12:
.size f, .-f
.ident "GCC: (GNU) 4.5.1 20100924 (ALT Linux 4.5.1-alt1)"
.section .note.GNU-stack,"",@progbits
It seems fixed in gcc4.5.
|
$ cat > test.c #include <stdlib.h> void *f(int flag) { return flag ? malloc(1) : NULL; } $ gcc -S -O3 -fomit-frame-pointer -fPIC -DPIC test.c -o - .file "test.c" .text .p2align 4,,15 .globl f .type f, @function f: pushl %ebx pushl %eax call .L3 .L3: popl %ebx addl $_GLOBAL_OFFSET_TABLE_+[.-.L3], %ebx pushl %eax movl 16(%esp), %edx testl %edx, %edx je .L2 subl $12, %esp pushl $1 call malloc@PLT addl $16, %esp .L1: popl %edx popl %ecx popl %ebx ret .p2align 4,,7 .L2: xorl %eax, %eax jmp .L1 .size f, .-f .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.3.3 20040412 (ALT Linux, build 3.3.3-alt5)" It's clearly visible that check if flag is equal to 0 performed after loading address of _GLOBAL_OFFSET_TABLE_ in %ebx. It would be more effective to perform this check before loading GOT in %ebx.