[PATCH] D43952: [ELF][MIPS] Don't change every dynamic relocation into R_MIPS_REL32

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 09:37:29 PST 2018


arichardson created this revision.
arichardson added reviewers: atanasyan, ruiu, espindola.
Herald added subscribers: llvm-commits, sdardis, emaste.

I was debugging some strange crashes in a dynamically linked CHERI binary
and it turns out that LLD always emits R_MIPS_REL32/R_MIPS_64 dynamic
relocations (even for an undefined symbol). The crash I was getting
happened because the program loaded a global function pointer referencing
an undefined symbol. However, because the wrong relocation was being
emitted RTLD only added the relocbase to the function pointer. Therefore
the program crashed when jumping to the start of the mapped ELF file
since that does not contain valid instructions.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D43952

Files:
  ELF/Arch/Mips.cpp
  test/ELF/mips-32.s
  test/ELF/mips-64.s
  test/ELF/mips-data-relocation-undef.s
  test/ELF/rel-addend-with-rela-input.s


Index: test/ELF/rel-addend-with-rela-input.s
===================================================================
--- test/ELF/rel-addend-with-rela-input.s
+++ test/ELF/rel-addend-with-rela-input.s
@@ -32,7 +32,7 @@
 #                                        ^--- Addend for relocation in .rel.dyn
 # RELA-TO-REL:     Relocations [
 # RELA-TO-REL-NEXT:  Section ({{.+}}) .rel.dyn {
-# RELA-TO-REL-NEXT:     0x10000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE foo 0x0
+# RELA-TO-REL-NEXT:     0x10000 R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE foo 0x0
 # RELA-TO-REL-NEXT:  }
 # RELA-TO-REL-NEXT: ]
 
Index: test/ELF/mips-data-relocation-undef.s
===================================================================
--- /dev/null
+++ test/ELF/mips-data-relocation-undef.s
@@ -0,0 +1,14 @@
+# REQUIRES: mips
+# RUN: llvm-mc -triple=mips64-unknown-freebsd -filetype=obj %s -o %t.o
+# RUN: ld.lld -shared %t.o -o %t.so
+# RUN: llvm-readobj -expand-relocs -r -t %t.so
+
+.global foo
+
+.data
+.global bar
+bar:
+  .quad foo
+.size bar, 8
+
+
Index: test/ELF/mips-64.s
===================================================================
--- test/ELF/mips-64.s
+++ test/ELF/mips-64.s
@@ -32,7 +32,7 @@
 # CHECK:      Relocations [
 # CHECK-NEXT:   Section (7) .rel.dyn {
 # CHECK-NEXT:     0x20010 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE - 0x0
-# CHECK-NEXT:     0x20008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE v2 0x0
+# CHECK-NEXT:     0x20008 R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE v2 0x0
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 
Index: test/ELF/mips-32.s
===================================================================
--- test/ELF/mips-32.s
+++ test/ELF/mips-32.s
@@ -48,7 +48,7 @@
 # REL:      Relocations [
 # REL-NEXT:   Section (7) .rel.dyn {
 # REL-NEXT:     0x20008 R_MIPS_REL32 - 0x0
-# REL-NEXT:     0x20004 R_MIPS_REL32 v2 0x0
+# REL-NEXT:     0x20004 R_MIPS_32 v2 0x0
 # REL-NEXT:   }
 # REL-NEXT: ]
 
Index: ELF/Arch/Mips.cpp
===================================================================
--- ELF/Arch/Mips.cpp
+++ ELF/Arch/Mips.cpp
@@ -188,7 +188,8 @@
 }
 
 template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {
-  return RelativeRel;
+  // TODO: are there any that need to change?
+  return Type;
 }
 
 template <class ELFT>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43952.136552.patch
Type: text/x-patch
Size: 2224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180301/7391ae87/attachment.bin>


More information about the llvm-commits mailing list