<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>5230</bug_id>
          
          <creation_ts>2004-09-20 12:43:06 +0400</creation_ts>
          <short_desc>suboptimal code generated with -fPIC</short_desc>
          <delta_ts>2010-11-04 23:22:20 +0300</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Development</classification>
          <product>Sisyphus</product>
          <component>gcc4.4</component>
          <version>unstable</version>
          <rep_platform>all</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P1</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alexey Voinov">voins</reporter>
          <assigned_to name="Gleb F-Malinovskiy">glebfm</assigned_to>
          <cc>glebfm</cc>
          
          <qa_contact>qa-sisyphus</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>18851</commentid>
    <comment_count>0</comment_count>
    <who name="Alexey Voinov">voins</who>
    <bug_when>2004-09-20 12:43:06 +0400</bug_when>
    <thetext>$ cat &gt; test.c
#include &lt;stdlib.h&gt;
void *f(int flag) { return flag ? malloc(1) : NULL; }

$ gcc -S -O3 -fomit-frame-pointer -fPIC -DPIC test.c -o -

        .file   &quot;test.c&quot;
        .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,&quot;&quot;,@progbits
        .ident  &quot;GCC: (GNU) 3.3.3 20040412 (ALT Linux, build 3.3.3-alt5)&quot;

It&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>21037</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Voinov">voins</who>
    <bug_when>2005-01-11 18:38:02 +0300</bug_when>
    <thetext>still in gcc3.4</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>38347</commentid>
    <comment_count>2</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2006-05-27 03:00:01 +0400</bug_when>
    <thetext>Same with gcc-4.1.1; maybe I should report it upstream? :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80527</commentid>
    <comment_count>3</comment_count>
    <who name="Andrey Rahmatullin">wrar</who>
    <bug_when>2008-10-31 16:00:44 +0300</bug_when>
    <thetext>Ой что я нашёл :)
#6052 сюда же.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114839</commentid>
    <comment_count>4</comment_count>
    <who name="Kirill A. Shutemov">kas</who>
    <bug_when>2010-11-04 23:22:20 +0300</bug_when>
    <thetext>$ gcc -S -O3 -fomit-frame-pointer -fPIC -DPIC test.c -o -
        .file   &quot;test.c&quot;
        .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  &quot;GCC: (GNU) 4.5.1 20100924 (ALT Linux 4.5.1-alt1)&quot;
        .section        .note.GNU-stack,&quot;&quot;,@progbits


It seems fixed in gcc4.5.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>