[llvm-bugs] [Bug 39080] New: PowerPC64: function calls missing relocations in PIC codegen when the callee is defined in same CU.

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 25 15:16:14 PDT 2018


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

            Bug ID: 39080
           Summary: PowerPC64: function calls missing relocations in PIC
                    codegen when the callee is defined in same CU.
           Product: libraries
           Version: trunk
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedbugs at nondot.org
          Reporter: sfertile at ca.ibm.com
                CC: llvm-bugs at lists.llvm.org

When compiling a file for a shared object (-fpic and not -fPIE) we need to emit
a relocation for calls where the callee is interposable. When the callee is
defined in the same translation unit we fail to do this.

eg:
test.c:
__attribute__((noinline))
int defined(int i) {
  return i;
}

int a = 55;

int caller(void) {
  return defined (a);
}

clang -O2 -c -fpic test.c                                                       
objdump -Dr test.o | less 

0000000000000000 <defined>:
   0:   20 00 80 4e     blr
        ...

0000000000000010 <caller>:
  10:   00 00 4c 3c     addis   r2,r12,0
                        10: R_PPC64_REL16_HA    .TOC.
  14:   00 00 42 38     addi    r2,r2,0
                        14: R_PPC64_REL16_LO    .TOC.+0x4
  18:   a6 02 08 7c     mflr    r0
  1c:   10 00 01 f8     std     r0,16(r1)
  20:   e1 ff 21 f8     stdu    r1,-32(r1)
  24:   00 00 62 3c     addis   r3,r2,0
                        24: R_PPC64_TOC16_HA    .toc
  28:   00 00 63 e8     ld      r3,0(r3)
                        28: R_PPC64_TOC16_LO_DS .toc
  2c:   02 00 63 e8     lwa     r3,0(r3)
  30:   d1 ff ff 4b     bl      0 <defined>
  34:   00 00 00 60     nop
  38:   20 00 21 38     addi    r1,r1,32
  3c:   10 00 01 e8     ld      r0,16(r1)
  40:   a6 03 08 7c     mtlr    r0
  44:   20 00 80 4e     blr


Instead of having a relocation to defined, the bl instruction already has the
offset immediate encoded in it `4bffffd1` = `bl -0x30`. This means the linker
will never create a plt stub for the call and if the dynamic linker resolves a
different definition of `defined` at runtime some calls will be redirect to
that definition while others will still call this definition. 

It can be worked around by using the `--function-sections` option as we emit
the relocation in that case:

  20:   01 00 00 48     bl      20 <caller+0x20>
                        20: R_PPC64_REL24       defined

-- 
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/20180925/3139f0e9/attachment.html>


More information about the llvm-bugs mailing list