[lld] r246337 - [Mips] Support grouping of multiple consecutive relocations in case of N32 and 64-bit MIPS ABIs

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 14:39:21 PDT 2015


Author: atanasyan
Date: Fri Aug 28 16:39:21 2015
New Revision: 246337

URL: http://llvm.org/viewvc/llvm-project?rev=246337&view=rev
Log:
[Mips] Support grouping of multiple consecutive relocations in case of N32 and 64-bit MIPS ABIs

Added:
    lld/trunk/test/elf/Mips/n32-rela-chain.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp?rev=246337&r1=246336&r2=246337&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp Fri Aug 28 16:39:21 2015
@@ -226,12 +226,26 @@ void MipsELFFile<ELFT>::createRelocation
     const Elf_Sym *symbol, ArrayRef<uint8_t> content,
     range<const Elf_Rela *> rels) {
   const auto value = this->getSymbolValue(symbol);
+  unsigned numInGroup = 0;
   for (const auto &rel : rels) {
-    if (rel.r_offset < value || value + content.size() <= rel.r_offset)
+    if (rel.r_offset < value || value + content.size() <= rel.r_offset) {
+      numInGroup = 0;
       continue;
+    }
+    if (numInGroup > 0) {
+      auto &last =
+          *static_cast<MipsELFReference<ELFT> *>(this->_references.back());
+      if (last.offsetInAtom() + value == rel.r_offset) {
+        last.setTag(last.tag() |
+                    (rel.getType(isMips64EL<ELFT>()) << 8 * (numInGroup - 1)));
+        ++numInGroup;
+        continue;
+      }
+    }
     auto r = new (this->_readerStorage) MipsELFReference<ELFT>(value, rel);
     this->addReferenceToSymbol(r, symbol);
     this->_references.push_back(r);
+    numInGroup = 1;
   }
 }
 

Added: lld/trunk/test/elf/Mips/n32-rela-chain.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/n32-rela-chain.test?rev=246337&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/n32-rela-chain.test (added)
+++ lld/trunk/test/elf/Mips/n32-rela-chain.test Fri Aug 28 16:39:21 2015
@@ -0,0 +1,68 @@
+# Check grouping of multiple consecutive relocations in case of N32
+# and 64-bit MIPS ABIs.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor gnu -target mips -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK:      Contents of section .text:
+# CHECK-NEXT:  10000130 00001001 00002004
+
+# CHECK: 10002000 l   .data   00000004 D0
+
+---
+FileHeader:
+  Class:    ELFCLASS32
+  Data:     ELFDATA2MSB
+  Type:     ET_REL
+  Machine:  EM_MIPS
+  Flags:    [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64, EF_MIPS_ABI2]
+
+Sections:
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:  16
+    Size:          8
+
+  - Name:          .rel.text
+    Type:          SHT_RELA
+    Link:          .symtab
+    AddressAlign:  4
+    Info:          .text
+    Relocations:
+      - Offset:  0
+        Symbol:  D0
+        Type:    R_MIPS_32
+        Addend:  0x10000
+      - Offset:  0
+        Symbol:  D0
+        Type:    R_MIPS_HI16
+      - Offset:  4
+        Symbol:  D0
+        Type:    R_MIPS_32
+        Addend:  4
+      - Offset:  4
+        Symbol:  D0
+        Type:    R_MIPS_LO16
+
+  - Name:          .data
+    Type:          SHT_PROGBITS
+    Flags:         [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:  16
+    Size:          4
+
+Symbols:
+  Local:
+    - Name:     D0
+      Type:     STT_FUNC
+      Section:  .data
+      Value:    0
+      Size:     4
+  Global:
+    - Name:     __start
+      Type:     STT_FUNC
+      Section:  .text
+      Value:    0
+      Size:     8
+...




More information about the llvm-commits mailing list