[llvm-bugs] [Bug 24970] New: llvm uses PLT to call locally defined function for PIE

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 28 06:00:25 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24970

            Bug ID: 24970
           Summary: llvm uses PLT to call locally defined function for PIE
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: hjl.tools at gmail.com
                CC: llvm-bugs at lists.llvm.org,
                    michael.m.kuperstein at intel.com
    Classification: Unclassified

On x86 and x86-64, llvm uses PLT to call locally defined function for PIE.
But PLT shouldn't be needed:

[hjl at gnu-32 bin]$ cat z.c
int glob;

int foo(int i)
{
   return glob;
}

void
bar ()
{
  glob = foo(5);
}
[hjl at gnu-32 bin]$ ./clang -S -O1 -fPIE -m64 z.c
[hjl at gnu-32 bin]$ cat z.s
    .text
    .file    "z.c"
    .globl    foo
    .align    16, 0x90
    .type    foo, at function
foo:                                    # @foo
    .cfi_startproc
# BB#0:
    movq    glob at GOTPCREL(%rip), %rax
    movl    (%rax), %eax
    retq
.Lfunc_end0:
    .size    foo, .Lfunc_end0-foo
    .cfi_endproc

    .globl    bar
    .align    16, 0x90
    .type    bar, at function
bar:                                    # @bar
    .cfi_startproc
# BB#0:
    pushq    %rax
.Ltmp0:
    .cfi_def_cfa_offset 16
    callq    foo at PLT
    movq    glob at GOTPCREL(%rip), %rcx
    movl    %eax, (%rcx)
    popq    %rax
    retq
.Lfunc_end1:
    .size    bar, .Lfunc_end1-bar
    .cfi_endproc

    .type    glob, at object            # @glob
    .comm    glob,4,4
[hjl at gnu-32 bin]$ gcc -S -O1 -fPIE -m64 z.c
[hjl at gnu-32 bin]$ cat z.s
    .file    "z.c"
    .text
    .globl    foo
    .type    foo, @function
foo:
.LFB0:
    .cfi_startproc
    movl    glob(%rip), %eax
    ret
    .cfi_endproc
.LFE0:
    .size    foo, .-foo
    .globl    bar
    .type    bar, @function
bar:
.LFB1:
    .cfi_startproc
    rep ret
    .cfi_endproc
.LFE1:
    .size    bar, .-bar
    .comm    glob,4,4
[hjl at gnu-32 bin]$

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150928/ffb6d989/attachment.html>


More information about the llvm-bugs mailing list