From fe3e0a2abff09d47696115b8cfcb0e0054a3eaf7 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Sun, 9 Mar 2014 13:20:01 +0000 Subject: [PATCH] [Mips] Fix addendum reading for R_MIPS_26 relocation. llvm-svn: 203412 --- lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h | 2 +- lld/test/elf/Mips/r26-2.test | 40 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lld/test/elf/Mips/r26-2.test diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h index cb1cf78d65c3..12bbafa7d052 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h @@ -74,7 +74,7 @@ private: ref->setAddend(*(int32_t *)ap); break; case R_MIPS_26: - ref->setAddend(*(int16_t *)ap); + ref->setAddend(*(int32_t *)ap & 0x3ffffff); break; case R_MIPS_HI16: case R_MIPS_LO16: diff --git a/lld/test/elf/Mips/r26-2.test b/lld/test/elf/Mips/r26-2.test new file mode 100644 index 000000000000..2e49d4ac2be8 --- /dev/null +++ b/lld/test/elf/Mips/r26-2.test @@ -0,0 +1,40 @@ +# Check reading addendum for R_MIPS_26 relocation. +# +# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: __start: +# CHECK-NEXT: 400128: 00 00 00 00 nop + +# CHECK: loc: +# CHECK-NEXT: 40012c: 4a 00 50 0c jal 20971816 +# CHECK-NEXT: 400130: 00 00 00 00 nop +# CHECK-NEXT: 400134: 4a 00 90 0c jal 37749032 +# CHECK-NEXT: 400138: 00 00 00 00 nop +# CHECK-NEXT: 40013c: 46 00 10 0c jal 4194584 +# CHECK-NEXT: 400140: 00 00 00 00 nop +# CHECK-NEXT: 400144: 4b 00 50 0c jal 20971820 +# CHECK-NEXT: 400148: 00 00 00 00 nop +# CHECK-NEXT: 40014c: 4b 00 90 0c jal 37749036 +# CHECK-NEXT: 400150: 00 00 00 00 nop +# CHECK-NEXT: 400154: 47 00 10 0c jal 4194588 +# CHECK-NEXT: 400158: 00 00 00 00 nop + +# CHECK: SYMBOL TABLE: +# CHECK: 0040012c l F .text 00000030 loc +# CHECK: 00400128 g F .text 00000004 __start + + .global __start + .ent __start +__start: + nop +loc: + jal __start + 0x1000000 + jal __start + 0x2000000 + jal __start + (-0x10) + jal loc + 0x1000000 + jal loc + 0x2000000 + jal loc + (-0x10) + .end __start