[lld] r240763 - [Mips] Create LA25 stubs for all branch relocations

Simon Atanasyan simon at atanasyan.com
Fri Jun 26 00:25:07 PDT 2015


Author: atanasyan
Date: Fri Jun 26 02:25:06 2015
New Revision: 240763

URL: http://llvm.org/viewvc/llvm-project?rev=240763&view=rev
Log:
[Mips] Create LA25 stubs for all branch relocations

Added:
    lld/trunk/test/elf/Mips/la25-stub-npic-01.test
    lld/trunk/test/elf/Mips/la25-stub-npic-02.test
    lld/trunk/test/elf/Mips/la25-stub-npic-shared.test
    lld/trunk/test/elf/Mips/la25-stub-pic.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=240763&r1=240762&r2=240763&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Fri Jun 26 02:25:06 2015
@@ -387,7 +387,7 @@ private:
                                      const Reference &ref) const;
 
   void handlePlain(const MipsELFDefinedAtom<ELFT> &atom, Reference &ref);
-  void handle26(const MipsELFDefinedAtom<ELFT> &atom, Reference &ref);
+  void handleBranch(const MipsELFDefinedAtom<ELFT> &atom, Reference &ref);
   void handleGOT(Reference &ref);
 
   const GOTAtom *getLocalGOTEntry(const Reference &ref);
@@ -400,7 +400,6 @@ private:
   const PLTAtom *getPLTEntry(const Atom *a);
   const PLTAtom *getPLTRegEntry(const Atom *a);
   const PLTAtom *getPLTMicroEntry(const Atom *a);
-  const LA25Atom *getLA25Entry(const Atom *target, bool isMicroMips);
   const LA25Atom *getLA25RegEntry(const Atom *a);
   const LA25Atom *getLA25MicroEntry(const Atom *a);
   const ObjectAtom *getObjectEntry(const SharedLibraryAtom *a);
@@ -410,7 +409,8 @@ private:
   bool isLocal(const Atom *a) const;
   bool isLocalCall(const Atom *a) const;
   bool isDynamic(const Atom *atom) const;
-  bool requireLA25Stub(const Atom *a) const;
+  bool requireLA25Stub(const MipsELFDefinedAtom<ELFT> &atom,
+                       const Reference &ref) const;
   bool requirePLTEntry(const Atom *a) const;
   bool requireCopy(const Atom *a) const;
   bool mightBeDynamic(const MipsELFDefinedAtom<ELFT> &atom,
@@ -551,7 +551,14 @@ void RelocationPass<ELFT>::handleReferen
     break;
   case R_MIPS_26:
   case R_MICROMIPS_26_S1:
-    handle26(atom, ref);
+  case R_MIPS_PC16:
+  case R_MIPS_PC21_S2:
+  case R_MIPS_PC26_S2:
+  case R_MICROMIPS_PC7_S1:
+  case R_MICROMIPS_PC10_S1:
+  case R_MICROMIPS_PC16_S1:
+  case R_MICROMIPS_PC23_S2:
+    handleBranch(atom, ref);
     break;
   case R_MIPS_EH:
   case R_MIPS_GOT16:
@@ -659,14 +666,28 @@ RelocationPass<ELFT>::collectReferenceIn
   else
     _hasStaticRelocations.insert(ref.target());
 
-  if (refKind != R_MIPS_CALL16 && refKind != R_MICROMIPS_CALL16 &&
-      refKind != R_MIPS_26 && refKind != R_MICROMIPS_26_S1 &&
-      refKind != R_MIPS_GOT_HI16 && refKind != R_MIPS_GOT_LO16 &&
-      refKind != R_MIPS_CALL_HI16 && refKind != R_MIPS_CALL_LO16 &&
-      refKind != R_MICROMIPS_GOT_HI16 && refKind != R_MICROMIPS_GOT_LO16 &&
-      refKind != R_MICROMIPS_CALL_HI16 && refKind != R_MICROMIPS_CALL_LO16 &&
-      refKind != R_MIPS_EH)
+  switch (refKind) {
+  case R_MIPS_CALL16:
+  case R_MICROMIPS_CALL16:
+  case R_MIPS_26:
+  case R_MICROMIPS_26_S1:
+  case R_MIPS_PC16:
+  case R_MIPS_PC21_S2:
+  case R_MIPS_PC26_S2:
+  case R_MICROMIPS_PC7_S1:
+  case R_MICROMIPS_PC10_S1:
+  case R_MICROMIPS_PC16_S1:
+  case R_MICROMIPS_PC23_S2:
+  case R_MIPS_CALL_HI16:
+  case R_MIPS_CALL_LO16:
+  case R_MICROMIPS_CALL_HI16:
+  case R_MICROMIPS_CALL_LO16:
+  case R_MIPS_EH:
+    break;
+  default:
     _requiresPtrEquality.insert(ref.target());
+    break;
+  }
   return std::error_code();
 }
 
@@ -843,12 +864,6 @@ static bool isMicroMips(const MipsELFDef
 }
 
 template <typename ELFT>
-const LA25Atom *RelocationPass<ELFT>::getLA25Entry(const Atom *target,
-                                                   bool isMicroMips) {
-  return isMicroMips ? getLA25MicroEntry(target) : getLA25RegEntry(target);
-}
-
-template <typename ELFT>
 const PLTAtom *RelocationPass<ELFT>::getPLTEntry(const Atom *a) {
   // If file contains microMIPS code try to reuse compressed PLT entry...
   if (isMicroMips()) {
@@ -878,23 +893,28 @@ void RelocationPass<ELFT>::handlePlain(c
     ref.setTarget(getObjectEntry(cast<SharedLibraryAtom>(ref.target())));
 }
 
-template <typename ELFT>
-void RelocationPass<ELFT>::handle26(const MipsELFDefinedAtom<ELFT> &atom,
-                                    Reference &ref) {
-  bool isMicro = ref.kindValue() == R_MICROMIPS_26_S1;
-  assert((isMicro || ref.kindValue() == R_MIPS_26) && "Unexpected relocation");
-
-  const auto *sla = dyn_cast<SharedLibraryAtom>(ref.target());
-  if (sla && sla->type() == SharedLibraryAtom::Type::Code)
-    ref.setTarget(isMicro ? getPLTMicroEntry(sla) : getPLTRegEntry(sla));
+static bool isMicroMipsRelocation(Reference::KindValue kind) {
+  return R_MICROMIPS_26_S1 <= kind && kind <= R_MICROMIPS_PC19_S2;
+}
 
-  if (requireLA25Stub(ref.target()))
-    ref.setTarget(getLA25Entry(ref.target(), isMicro));
+template <typename ELFT>
+void RelocationPass<ELFT>::handleBranch(const MipsELFDefinedAtom<ELFT> &atom,
+                                        Reference &ref) {
+  bool isMicro = isMicroMipsRelocation(ref.kindValue());
+  if (const auto *sla = dyn_cast<SharedLibraryAtom>(ref.target())) {
+    if (sla->type() == SharedLibraryAtom::Type::Code)
+      ref.setTarget(isMicro ? getPLTMicroEntry(sla) : getPLTRegEntry(sla));
+  } else if (requireLA25Stub(atom, ref)) {
+    if (isMicro)
+      ref.setTarget(getLA25MicroEntry(ref.target()));
+    else
+      ref.setTarget(getLA25RegEntry(ref.target()));
+  }
 
   if (!isLocal(ref.target())) {
-    if (isMicro)
+    if (ref.kindValue() == R_MICROMIPS_26_S1)
       ref.setKindValue(LLD_R_MICROMIPS_GLOBAL_26_S1);
-    else
+    else if (ref.kindValue() == R_MIPS_26)
       ref.setKindValue(LLD_R_MIPS_GLOBAL_26);
   }
 }
@@ -948,11 +968,14 @@ bool RelocationPass<ELFT>::isLocalCall(c
 }
 
 template <typename ELFT>
-bool RelocationPass<ELFT>::requireLA25Stub(const Atom *a) const {
-  if (isLocal(a))
+bool RelocationPass<ELFT>::requireLA25Stub(const MipsELFDefinedAtom<ELFT> &atom,
+                                           const Reference &ref) const {
+  if (atom.file().isPIC())
     return false;
-  if (auto *da = dyn_cast<DefinedAtom>(a))
-    return static_cast<const MipsELFDefinedAtom<ELFT> *>(da)->file().isPIC();
+  if (auto *da = dyn_cast<DefinedAtom>(ref.target()))
+    return static_cast<const MipsELFDefinedAtom<ELFT> *>(da)->file().isPIC() ||
+           da->codeModel() == DefinedAtom::codeMipsMicroPIC ||
+           da->codeModel() == DefinedAtom::codeMipsPIC;
   return false;
 }
 

Added: lld/trunk/test/elf/Mips/la25-stub-npic-01.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/la25-stub-npic-01.test?rev=240763&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/la25-stub-npic-01.test (added)
+++ lld/trunk/test/elf/Mips/la25-stub-npic-01.test Fri Jun 26 02:25:06 2015
@@ -0,0 +1,153 @@
+# Check that LA25 stubs are created for branch relocations
+# when a PIC function is called from non-pic code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-reg.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe \
+# RUN:     %t-reg.o %t-micro.o %t-pic.o
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK-NOT:  Contents of section .plt:
+# CHECK:      Contents of section .text:
+# CHECK-NEXT:  400110 54001000 0f000000 0e000000 0d000000
+#              ^ T0   ^ .pic.T1 (0x400150)
+#                              ^ 0x400114 + 0x3c = 0x400150
+#                                       ^ ...
+# CHECK-NEXT:  400120 2000b000 1e000000 1c000000 00001a00
+#              ^ T3   ^ .pic.T2
+#                              ^ ...
+# CHECK-NEXT:  400130 00000c00 00000000 00000000 00000000
+# CHECK-NEXT:  400140 00000000 00000000 00000000 00000000
+#                     ^ T1     ^ T2
+# CHECK-NEXT:  400150 4000193c 50001008 40013927 00000000
+#                     ^ .pic.T1
+# CHECK-NEXT:  400160 b9414000 20d4a200 39334501 00000000
+#                     ^ .pic.T2
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400110 g F .text  00000010 T0
+# CHECK: 00400120 g F .text  00000014 T3
+# CHECK: 00400140 g F .text  00000004 T1
+# CHECK: 00400144 g F .text  00000004 T2
+
+# pic.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+             EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name:          .text
+  Type:          SHT_PROGBITS
+  Size:          8
+  AddressAlign:  16
+  Flags:         [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+  Global:
+    - Name:     T1
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    0
+      Size:     4
+    - Name:     T2
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    4
+      Size:     4
+      Other:    [STO_MIPS_MICROMIPS]
+
+# reg.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          16
+
+  - Name:          .rel.text
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  0x04
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T1
+        Type:    R_MIPS_26
+      - Offset:  4
+        Symbol:  T1
+        Type:    R_MIPS_PC16
+      - Offset:  8
+        Symbol:  T1
+        Type:    R_MIPS_PC21_S2
+      - Offset:  12
+        Symbol:  T1
+        Type:    R_MIPS_PC26_S2
+
+Symbols:
+  Global:
+    - Name:     T0
+      Section:  .text
+      Size:     16
+    - Name:     T1
+
+# micro.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          20
+
+  - Name:          .rel.text
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  0x04
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T2
+        Type:    R_MICROMIPS_26_S1
+      - Offset:  4
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC7_S1
+      - Offset:  8
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC10_S1
+      - Offset:  12
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC16_S1
+      - Offset:  16
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC23_S2
+
+Symbols:
+  Global:
+    - Name:     T3
+      Section:  .text
+      Size:     20
+      Other:    [STO_MIPS_MICROMIPS]
+    - Name:     T2
+...

Added: lld/trunk/test/elf/Mips/la25-stub-npic-02.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/la25-stub-npic-02.test?rev=240763&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/la25-stub-npic-02.test (added)
+++ lld/trunk/test/elf/Mips/la25-stub-npic-02.test Fri Jun 26 02:25:06 2015
@@ -0,0 +1,123 @@
+# Check that LA25 stubs are created for branch relocations
+# when a PIC function is defined in a non-PIC file and
+# is called from non-pic code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t1.o %t2.o
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK-NOT:  Contents of section .plt:
+# CHECK:      Contents of section .text:
+# CHECK-NEXT:  400110 00000000 00000000 50001000 09000000
+#                     ^ T1     ^ T2     ^ .pic.T1 (0x400140)
+# CHECK-NEXT:  400120 08000000 07000000 2000a800 12000000
+#                                       ^ .pic.T2 (0x400150)
+# CHECK-NEXT:  400130 10000000 00000e00 00000600 00000000
+# CHECK-NEXT:  400140 4000193c 44001008 10013927 00000000
+#                     ^ .pic.T1
+# CHECK-NEXT:  400150 b9414000 20d48a00 39331501 00000000
+#                     ^ .pic.T2
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400110 g F .text  00000004 T1
+# CHECK: 00400114 g F .text  00000004 T2
+# CHECK: 00400118 g F .text  00000010 T0
+# CHECK: 00400128 g F .text  00000014 T3
+
+# 1.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name:          .text
+  Type:          SHT_PROGBITS
+  Size:          8
+  AddressAlign:  16
+  Flags:         [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+  Global:
+    - Name:     T1
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    0
+      Size:     4
+      Other:    [STO_MIPS_PIC]
+    - Name:     T2
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    4
+      Size:     4
+      Other:    [STO_MIPS_MICROMIPS, STO_MIPS_PIC]
+
+# 2.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          36
+
+  - Name:          .rel.text
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  0x04
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T1
+        Type:    R_MIPS_26
+      - Offset:  4
+        Symbol:  T1
+        Type:    R_MIPS_PC16
+      - Offset:  8
+        Symbol:  T1
+        Type:    R_MIPS_PC21_S2
+      - Offset:  12
+        Symbol:  T1
+        Type:    R_MIPS_PC26_S2
+      - Offset:  16
+        Symbol:  T2
+        Type:    R_MICROMIPS_26_S1
+      - Offset:  20
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC7_S1
+      - Offset:  24
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC10_S1
+      - Offset:  28
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC16_S1
+      - Offset:  32
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC23_S2
+
+Symbols:
+  Global:
+    - Name:     T0
+      Section:  .text
+      Value:    0
+      Size:     16
+    - Name:     T3
+      Section:  .text
+      Value:    16
+      Size:     20
+      Other:    [STO_MIPS_MICROMIPS]
+    - Name:     T1
+    - Name:     T2
+...

Added: lld/trunk/test/elf/Mips/la25-stub-npic-shared.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/la25-stub-npic-shared.test?rev=240763&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/la25-stub-npic-shared.test (added)
+++ lld/trunk/test/elf/Mips/la25-stub-npic-shared.test Fri Jun 26 02:25:06 2015
@@ -0,0 +1,152 @@
+# Check that PLT entries are created for branch relocations
+# when a PIC shared library function is called from non-pic code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-reg.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-pic.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-reg.o %t-micro.o %t.so
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK:      Contents of section .plt:
+# CHECK-NEXT:  400190 40001c3c 0020998f 00209c27 23c01c03
+# CHECK-NEXT:  4001a0 2178e003 82c01800 09f82003 feff1827
+# CHECK-NEXT:  4001b0 40000f3c 0820f98d 08002003 0820f825
+#                     ^ PLT.T1
+# CHECK-NEXT:  4001c0 00799307 22ff0000 9945020f
+#                     ^ PLT.T2
+
+# CHECK:      Contents of section .text:
+# CHECK-NEXT:  4001cc 6c001000 f8ff0000 f7ff1f00 f6ffff03
+#              ^ T0   ^ PLT.T1 (0x4001b0)
+#                              ^ 0x4001d0 -32 = 0x4001b0
+#                                       ^ ...
+# CHECK-NEXT:  4001dc 2000e000 70000000 ee030000 0000ecff
+#              ^ T3   ^ PLT.T2
+#                              ^ ...
+# CHECK-NEXT:  4001ec 7f00f5ff
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 004001cc g F .text  00000010 T0
+# CHECK: 004001dc g F .text  00000014 T3
+
+# pic.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+             EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name:          .text
+  Type:          SHT_PROGBITS
+  Size:          8
+  AddressAlign:  16
+  Flags:         [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+  Global:
+    - Name:     T1
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    0
+      Size:     4
+    - Name:     T2
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    4
+      Size:     4
+      Other:    [STO_MIPS_MICROMIPS]
+
+# reg.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          16
+
+  - Name:          .rel.text
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  0x04
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T1
+        Type:    R_MIPS_26
+      - Offset:  4
+        Symbol:  T1
+        Type:    R_MIPS_PC16
+      - Offset:  8
+        Symbol:  T1
+        Type:    R_MIPS_PC21_S2
+      - Offset:  12
+        Symbol:  T1
+        Type:    R_MIPS_PC26_S2
+
+Symbols:
+  Global:
+    - Name:     T0
+      Section:  .text
+      Size:     16
+    - Name:     T1
+
+# micro.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          20
+
+  - Name:          .rel.text
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  0x04
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T2
+        Type:    R_MICROMIPS_26_S1
+      - Offset:  4
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC7_S1
+      - Offset:  8
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC10_S1
+      - Offset:  12
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC16_S1
+      - Offset:  16
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC23_S2
+
+Symbols:
+  Global:
+    - Name:     T3
+      Section:  .text
+      Size:     20
+      Other:    [STO_MIPS_MICROMIPS]
+    - Name:     T2
+...

Added: lld/trunk/test/elf/Mips/la25-stub-pic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/la25-stub-pic.test?rev=240763&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/la25-stub-pic.test (added)
+++ lld/trunk/test/elf/Mips/la25-stub-pic.test Fri Jun 26 02:25:06 2015
@@ -0,0 +1,144 @@
+# Check that we do not create LA26 stubs and PLT entries
+# when a PIC function is called from PIC code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-reg.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o %t-reg.o %t-micro.o
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK-NOT:  Contents of section .plt:
+# CHECK:      Contents of section .text:
+# CHECK-NEXT:  400110 00000000 00000000 44001000 fdff0000
+#                     ^ T1     ^ T2     ^ T1 (0x400110)
+#                                                ^ 0x40011c - 12 = 0x0x400110
+# CHECK-NEXT:  400120 fcff1f00 fbffff03 20008a00 74000000
+#                                       ^ T2 (0x400114)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400110 g F .text  00000004 T1
+# CHECK: 00400114 g F .text  00000004 T2
+# CHECK: 00400118 g F .text  00000010 T0
+# CHECK: 00400128 g F .text  00000014 T3
+
+# pic.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+             EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name:          .text
+  Type:          SHT_PROGBITS
+  Size:          8
+  AddressAlign:  16
+  Flags:         [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+  Global:
+    - Name:     T1
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    0
+      Size:     4
+    - Name:     T2
+      Section:  .text
+      Type:     STT_FUNC
+      Value:    4
+      Size:     4
+      Other:    [STO_MIPS_MICROMIPS]
+
+# reg.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_PIC]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          16
+
+  - Name:          .rel.text
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  0x04
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T1
+        Type:    R_MIPS_26
+      - Offset:  4
+        Symbol:  T1
+        Type:    R_MIPS_PC16
+      - Offset:  8
+        Symbol:  T1
+        Type:    R_MIPS_PC21_S2
+      - Offset:  12
+        Symbol:  T1
+        Type:    R_MIPS_PC26_S2
+
+Symbols:
+  Global:
+    - Name:     T0
+      Section:  .text
+      Size:     16
+    - Name:     T1
+
+# micro.o
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+             EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  4
+    Size:          20
+
+  - Name:          .rel.text
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  0x04
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  T2
+        Type:    R_MICROMIPS_26_S1
+      - Offset:  4
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC7_S1
+      - Offset:  8
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC10_S1
+      - Offset:  12
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC16_S1
+      - Offset:  16
+        Symbol:  T2
+        Type:    R_MICROMIPS_PC23_S2
+
+Symbols:
+  Global:
+    - Name:     T3
+      Section:  .text
+      Size:     20
+      Other:    [STO_MIPS_MICROMIPS]
+    - Name:     T2
+...





More information about the llvm-commits mailing list