[lld] r234634 - [Mips] Support R_MIPS_EH relocation handling

Simon Atanasyan simon at atanasyan.com
Fri Apr 10 14:00:30 PDT 2015


Author: atanasyan
Date: Fri Apr 10 16:00:29 2015
New Revision: 234634

URL: http://llvm.org/viewvc/llvm-project?rev=234634&view=rev
Log:
[Mips] Support R_MIPS_EH relocation handling

The patch supports just the R_MIPS_EH relocation handling and does not
implement full specification of compact exception tables for MIPS ABIs.

Added:
    lld/trunk/test/elf/Mips/rel-eh-01.test
    lld/trunk/test/elf/Mips/rel-eh-02.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=234634&r1=234633&r2=234634&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Fri Apr 10 16:00:29 2015
@@ -56,6 +56,7 @@ static MipsRelocationParams getRelocatio
   case R_MIPS_32:
   case R_MIPS_GPREL32:
   case R_MIPS_PC32:
+  case R_MIPS_EH:
     return {4, 0xffffffff, 0, false};
   case LLD_R_MIPS_32_HI16:
     return {4, 0xffff0000, 0, false};
@@ -401,6 +402,7 @@ static ErrorOr<uint64_t> calculateReloca
     return relocPcLo16(relAddr, tgtAddr, addend);
   case R_MICROMIPS_LO16:
     return relocLo16(relAddr, tgtAddr, addend, isGP, true);
+  case R_MIPS_EH:
   case R_MIPS_GOT16:
   case R_MIPS_CALL16:
   case R_MIPS_GOT_DISP:

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=234634&r1=234633&r2=234634&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Fri Apr 10 16:00:29 2015
@@ -527,6 +527,7 @@ void RelocationPass<ELFT>::handleReferen
   case R_MICROMIPS_26_S1:
     handle26(atom, ref);
     break;
+  case R_MIPS_EH:
   case R_MIPS_GOT16:
   case R_MIPS_CALL16:
   case R_MICROMIPS_GOT16:
@@ -607,7 +608,8 @@ void RelocationPass<ELFT>::collectRefere
     _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_26 && refKind != R_MICROMIPS_26_S1 &&
+      refKind != R_MIPS_EH)
     _requiresPtrEquality.insert(ref.target());
 }
 
@@ -787,7 +789,7 @@ template <typename ELFT> void Relocation
 
   if (ref.kindValue() == R_MIPS_GOT_PAGE)
     ref.setTarget(getLocalGOTPageEntry(ref));
-  else if (ref.kindValue() == R_MIPS_GOT_DISP)
+  else if (ref.kindValue() == R_MIPS_GOT_DISP || ref.kindValue() == R_MIPS_EH)
     ref.setTarget(getLocalGOTEntry(ref));
   else if (isLocal(ref.target()))
     ref.setTarget(getLocalGOTPageEntry(ref));

Added: lld/trunk/test/elf/Mips/rel-eh-01.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-eh-01.test?rev=234634&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-eh-01.test (added)
+++ lld/trunk/test/elf/Mips/rel-eh-01.test Fri Apr 10 16:00:29 2015
@@ -0,0 +1,186 @@
+# Check R_MIPS_EH relocation handling: writing result of a relocation
+# calculation, adding GOT entries etc.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t2.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t1.o %t2.o %t.so
+# RUN: llvm-objdump -s -t %t.exe | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# RAW:      Contents of section .gnu_extab:
+# RAW-NEXT:  400178 001880ff ff000000 1c80ffff 2080ffff
+#                     ^ T1 GOT entry = 0xffff8018 = -32744
+#                                     ^ L1 GOT entry = 0xffff801c = -32740
+#           E1 GOT entry = 0xffff8020 = -32736 ^
+# RAW:      Contents of section .got:
+# RAW-NEXT:  401000 00000000 00000080 60014000 00204000
+# RAW-NEXT:  401010 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00402000 l    .data  00000004 L1
+# RAW: 00400160 g  F .text  00000004 T1
+
+# GOT:      Local entries [
+# GOT-NEXT:   Entry {
+# GOT-NEXT:     Address: 0x401008
+# GOT-NEXT:     Access: -32744
+# GOT-NEXT:     Initial: 0x400160
+# GOT-NEXT:   }
+# GOT-NEXT:   Entry {
+# GOT-NEXT:     Address: 0x40100C
+# GOT-NEXT:     Access: -32740
+# GOT-NEXT:     Initial: 0x402000
+# GOT-NEXT:   }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT:   Entry {
+# GOT-NEXT:     Address: 0x401010
+# GOT-NEXT:     Access: -32736
+# GOT-NEXT:     Initial: 0x0
+# GOT-NEXT:     Value: 0x0
+# GOT-NEXT:     Type: Function (0x2)
+# GOT-NEXT:     Section: Undefined (0x0)
+# GOT-NEXT:     Name: E1@ (1)
+# GOT-NEXT:   }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+
+# so.o
+---
+FileHeader:      
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+  Flags:   [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+            EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:        
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [SHF_ALLOC, SHF_EXECINSTR]
+    AddressAlign:  16
+    Size:          4
+
+Symbols:         
+  Global:          
+    - Name:    E1
+      Type:    STT_FUNC
+      Section: .text
+      Value:   0
+      Size:    4
+
+# t1.o
+---
+FileHeader:      
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+  Flags:   [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+            EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:        
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [SHF_ALLOC, SHF_EXECINSTR]
+    AddressAlign:  16
+    Size:          4
+
+Symbols:         
+  Global:          
+    - Name:    T1
+      Type:    STT_FUNC
+      Section: .text
+      Value:   0
+      Size:    4
+
+# t2.o
+---
+FileHeader:      
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+  Flags:   [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+            EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:        
+  - Name:          .text
+    Type:          SHT_PROGBITS
+    Flags:         [SHF_ALLOC, SHF_EXECINSTR]
+    AddressAlign:  16
+    Size:          8
+
+  - Name:          .data
+    Type:          SHT_PROGBITS
+    Flags:         [SHF_WRITE, SHF_ALLOC]
+    AddressAlign:  16
+    Size:          4
+
+  - Name:          .gnu_extab
+    Type:          SHT_PROGBITS
+    Flags:         [SHF_ALLOC]
+    AddressAlign:  4
+    Size:          16
+
+  - Name:          .rel.gnu_extab
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  4
+    Info:          .gnu_extab
+    Relocations:     
+      - Offset:  1
+        Symbol:  T1
+        Type:    R_MIPS_EH
+      - Offset:  8
+        Symbol:  L1
+        Type:    R_MIPS_EH
+      - Offset:  12
+        Symbol:  E1
+        Type:    R_MIPS_EH
+
+  - Name:          .eh_frame_entry
+    Type:          SHT_PROGBITS
+    Flags:         [SHF_ALLOC]
+    AddressAlign:  4
+    Content:       "0000000100000001"
+
+  - Name:          .rel.eh_frame_entry
+    Type:          SHT_REL
+    Link:          .symtab
+    AddressAlign:  4
+    Info:          .eh_frame_entry
+    Relocations:     
+      - Offset:  0
+        Symbol:  .text
+        Type:    R_MIPS_PC32
+      - Offset:  4
+        Symbol:  .gnu_extab
+        Type:    R_MIPS_PC32
+
+Symbols:         
+  Local:           
+    - Name:    .text
+      Type:    STT_SECTION
+      Section: .text
+    - Name:    .gnu_extab
+      Type:    STT_SECTION
+      Section: .gnu_extab
+    - Name:    L1
+      Type:    STT_OBJECT
+      Section: .data
+      Value:   0
+      Size:    4
+
+  Global:          
+    - Name:    T0
+      Type:    STT_FUNC
+      Section: .text
+      Value:   0
+      Size:    8
+    - Name:    E1
+    - Name:    T1
+...

Added: lld/trunk/test/elf/Mips/rel-eh-02.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-eh-02.test?rev=234634&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-eh-02.test (added)
+++ lld/trunk/test/elf/Mips/rel-eh-02.test Fri Apr 10 16:00:29 2015
@@ -0,0 +1,130 @@
+# Conditions:
+#   a) Linking a non-shared executable file.
+#   b) Relocations' targets are symbols defined in the shared object.
+# Check:
+#   a) The R_MIPS_REL32 relocation is not created for any symbols.
+#   b) The R_MIPS_COPY relocation is created for the D1 symbol.
+#   c) No entries in the dynamic symbols table has the STO_MIPS_PLT flag.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT-SYM:      Relocations [
+# PLT-SYM-NEXT:   Section (5) .rel.dyn {
+# PLT-SYM-NEXT:     0x{{[0-9A-F]+}} R_MIPS_COPY D1 0x0
+# PLT-SYM-NEXT:   }
+
+# PLT-SYM:      DynamicSymbols [
+# PLT-SYM-NOT:      Other: 8
+
+# so.o
+---
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+  Flags:   [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name:         .text
+  Type:         SHT_PROGBITS
+  Size:         8
+  AddressAlign: 16
+  Flags:        [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name:         .data
+  Type:         SHT_PROGBITS
+  Size:         0x08
+  AddressAlign: 4
+  Flags:        [SHF_WRITE, 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
+    - Name:    D1
+      Section: .data
+      Type:    STT_OBJECT
+      Value:   0
+      Size:    4
+
+# o.o
+---
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+  Flags:   [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name:         .text
+  Type:         SHT_PROGBITS
+  Size:         0x08
+  AddressAlign: 16
+  Flags:        [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name:         .data
+  Type:         SHT_PROGBITS
+  Size:         0x08
+  AddressAlign: 16
+  Flags:        [SHF_WRITE, SHF_ALLOC]
+
+- Name:         .rel.text
+  Type:         SHT_REL
+  Info:         .text
+  AddressAlign: 4
+  Relocations:
+    - Offset: 0
+      Symbol: T1
+      Type:   R_MIPS_26
+    - Offset: 4
+      Symbol: D1
+      Type:   R_MIPS_PC32
+
+- Name:         .rel.data
+  Type:         SHT_REL
+  Info:         .data
+  AddressAlign: 4
+  Relocations:
+    - Offset: 0
+      Symbol: T1
+      Type:   R_MIPS_EH
+    - Offset: 4
+      Symbol: T2
+      Type:   R_MIPS_EH
+    - Offset: 8
+      Symbol: D1
+      Type:   R_MIPS_EH
+
+Symbols:
+  Global:
+    - Name:    T0
+      Section: .text
+      Type:    STT_FUNC
+      Value:   0x0
+      Size:    8
+    - Name:    T1
+      Type:    STT_FUNC
+    - Name:    T2
+      Type:    STT_FUNC
+    - Name:    D0
+      Section: .data
+      Type:    STT_OBJECT
+      Value:   0x0
+      Size:    8
+    - Name:    D1
+      Type:    STT_OBJECT
+...





More information about the llvm-commits mailing list