[lld] r203410 - [Mips] Fix addendum reading for R_MIPS_HI16 / R_MIPS_LO16 relocations.
Simon Atanasyan
simon at atanasyan.com
Sun Mar 9 06:19:46 PDT 2014
Author: atanasyan
Date: Sun Mar 9 08:19:46 2014
New Revision: 203410
URL: http://llvm.org/viewvc/llvm-project?rev=203410&view=rev
Log:
[Mips] Fix addendum reading for R_MIPS_HI16 / R_MIPS_LO16 relocations.
Added:
lld/trunk/test/elf/Mips/hilo16-2.test
lld/trunk/test/elf/Mips/hilo16-3.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
lld/trunk/test/elf/Mips/hilo16-1.test
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=203410&r1=203409&r2=203410&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Sun Mar 9 08:19:46 2014
@@ -56,6 +56,23 @@ public:
return std::move(file);
}
+
+private:
+ typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
+ typedef llvm::object::Elf_Rel_Impl<ELFT, false> Elf_Rel;
+
+ ELFReference<ELFT> *
+ createRelocationReference(const Elf_Sym &symbol, const Elf_Rel &ri,
+ ArrayRef<uint8_t> content) override {
+ bool isMips64EL = this->_objFile->isMips64EL();
+ auto *ref = new (this->_readerStorage)
+ ELFReference<ELFT>(&ri, ri.r_offset - symbol.st_value, this->kindArch(),
+ ri.getType(isMips64EL), ri.getSymbol(isMips64EL));
+ int32_t addend =
+ *(int16_t *)(content.data() + ri.r_offset - symbol.st_value);
+ ref->setAddend(addend);
+ return ref;
+ }
};
} // elf
Modified: lld/trunk/test/elf/Mips/hilo16-1.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/hilo16-1.test?rev=203410&r1=203409&r2=203410&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/hilo16-1.test (original)
+++ lld/trunk/test/elf/Mips/hilo16-1.test Sun Mar 9 08:19:46 2014
@@ -1,41 +1,42 @@
-# Check handling of HI16 and LO16 relocations against _gp_disp symbol.
-# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t1 %s
-# RUN: lld -flavor gnu -target mipsel -shared -o %t2 %t1
-# RUN: llvm-objdump -section-headers -t -disassemble %t2 | FileCheck %s
+# Check handling multiple HI16 relocation followed by a single LO16 relocation.
+#
+# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s
+# RUN: lld -flavor gnu -target mipsel -e glob1 -o %t-exe %t-obj
+# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s
# CHECK: Disassembly of section .text:
# CHECK: glob1:
-# CHECK-NEXT: 114: 01 00 01 8c lw $1, 1($zero)
-# CHECK-NEXT: 118: 01 00 02 8c lw $2, 1($zero)
-# CHECK-NEXT: 11c: d8 8e 21 24 addiu $1, $1, -28968
-# CHECK: glob2:
-# CHECK-NEXT: 120: 01 00 01 8c lw $1, 1($zero)
-# CHECK-NEXT: 124: 01 00 02 8c lw $2, 1($zero)
-# CHECK-NEXT: 128: cc 8e 21 24 addiu $1, $1, -28980
-
-# CHECK: Sections:
-# CHECK: Idx Name Size Address Type
-# CHECK: 4 .text 00000018 0000000000000114 TEXT DATA
-# CHECK: 6 .got 00000008 0000000000001000 DATA
+# CHECK-NEXT: 400128: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 40012c: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 400130: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 400134: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 400138: 42 00 08 3c lui $8, 66
+# CHECK-NEXT: 40013c: 3e 00 08 3c lui $8, 62
+# CHECK-NEXT: 400140: 40 02 08 3c lui $8, 576
+# CHECK-NEXT: 400144: 40 fe 08 3c lui $8, 65088
+# CHECK-NEXT: 400148: 4d 01 08 85 lh $8, 333($8)
# CHECK: SYMBOL TABLE:
-# CHECK: 00000114 g F .text 0000000c glob1
-# CHECK: 00000120 g F .text 0000000c glob2
-# CHECK: 00001000 g *ABS* 00000000 _GLOBAL_OFFSET_TABLE_
-# CHECK: 00008ff0 g *ABS* 00000000 _gp_disp
+# CHECK: 00400128 g F .text 00000024 glob1
+# CHECK: 0040014c g F .text 00000004 glob2
.global glob1
.ent glob1
glob1:
- lw $1,%hi(_gp_disp) # (.got + 0x7ff0 - (.glob1 + 0) + 0x8000) >> 16
- lw $2,%hi(_gp_disp) # (.got + 0x7ff0 - (.glob1 + 4) + 0x8000) >> 16
- addiu $1,$1,%lo(_gp_disp) # .got + 0x7ff0 - (.glob1 + 8) + 4
+ lui $t0,%hi(glob2+0x1)
+ lui $t0,%hi(glob2+(-0x1))
+ lui $t0,%hi(glob2+0x1ff)
+ lui $t0,%hi(glob2+(-0x1ff))
+ lui $t0,%hi(glob2+0x1ffff)
+ lui $t0,%hi(glob2+(-0x1ffff))
+ lui $t0,%hi(glob2+0x1ffffff)
+ lui $t0,%hi(glob2+(-0x1ffffff))
+
+ lh $t0,%lo(glob2+(-0x1ffffff))($t0)
.end glob1
.global glob2
.ent glob2
glob2:
- lw $1,%hi(_gp_disp) # (.got + 0x7ff0 - (.glob2 + 0) + 0x8000) >> 16
- lw $2,%hi(_gp_disp) # (.got + 0x7ff0 - (.glob2 + 4) + 0x8000) >> 16
- addiu $1,$1,%lo(_gp_disp) # .got + 0x7ff0 - (.glob2 + 8) + 4
+ nop
.end glob2
Added: lld/trunk/test/elf/Mips/hilo16-2.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/hilo16-2.test?rev=203410&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/hilo16-2.test (added)
+++ lld/trunk/test/elf/Mips/hilo16-2.test Sun Mar 9 08:19:46 2014
@@ -0,0 +1,66 @@
+# Check handling of HI16 and LO16 relocations for regular symbol.
+#
+# R_MIPS_HI16: (AHL + S) - (short)(AHL + S)
+# R_MIPS_LO16: AHL + S
+# where AHL = (AHI << 16) + ALO
+#
+# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s
+# RUN: lld -flavor gnu -target mipsel -e glob1 -o %t-exe %t-obj
+# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK: glob1:
+# CHECK-NEXT: 400128: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 40012c: 69 01 08 85 lh $8, 361($8)
+# CHECK-NEXT: 400130: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 400134: 67 01 08 85 lh $8, 359($8)
+# CHECK-NEXT: 400138: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 40013c: 67 03 08 85 lh $8, 871($8)
+# CHECK-NEXT: 400140: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: 400144: 69 ff 08 85 lh $8, -151($8)
+# CHECK-NEXT: 400148: 42 00 08 3c lui $8, 66
+# CHECK-NEXT: 40014c: 67 01 08 85 lh $8, 359($8)
+# CHECK-NEXT: 400150: 3e 00 08 3c lui $8, 62
+# CHECK-NEXT: 400154: 69 01 08 85 lh $8, 361($8)
+# CHECK-NEXT: 400158: 40 02 08 3c lui $8, 576
+# CHECK-NEXT: 40015c: 67 01 08 85 lh $8, 359($8)
+# CHECK-NEXT: 400160: 40 fe 08 3c lui $8, 65088
+# CHECK-NEXT: 400164: 69 01 08 85 lh $8, 361($8)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400128 g F .text 00000040 glob1
+# CHECK: 00400168 g F .text 00000004 glob2
+
+ .global glob1
+ .ent glob1
+glob1:
+ lui $t0,%hi(glob2+0x1)
+ lh $t0,%lo(glob2+0x1)($t0)
+
+ lui $t0,%hi(glob2+(-0x1))
+ lh $t0,%lo(glob2+(-0x1))($t0)
+
+ lui $t0,%hi(glob2+0x1ff)
+ lh $t0,%lo(glob2+0x1ff)($t0)
+
+ lui $t0,%hi(glob2+(-0x1ff))
+ lh $t0,%lo(glob2+(-0x1ff))($t0)
+
+ lui $t0,%hi(glob2+0x1ffff)
+ lh $t0,%lo(glob2+0x1ffff)($t0)
+
+ lui $t0,%hi(glob2+(-0x1ffff))
+ lh $t0,%lo(glob2+(-0x1ffff))($t0)
+
+ lui $t0,%hi(glob2+0x1ffffff) # truncate
+ lh $t0,%lo(glob2+0x1ffffff)($t0)
+
+ lui $t0,%hi(glob2+(-0x1ffffff)) # truncate
+ lh $t0,%lo(glob2+(-0x1ffffff))($t0)
+ .end glob1
+
+ .global glob2
+ .ent glob2
+glob2:
+ nop
+ .end glob2
Added: lld/trunk/test/elf/Mips/hilo16-3.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/hilo16-3.test?rev=203410&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/hilo16-3.test (added)
+++ lld/trunk/test/elf/Mips/hilo16-3.test Sun Mar 9 08:19:46 2014
@@ -0,0 +1,45 @@
+# Check handling of HI16 and LO16 relocations for _gp_disp.
+#
+# R_MIPS_HI16: (AHL + GP - P) - (short)(AHL + GP - P)
+# R_MIPS_LO16: AHL + GP - P + 4
+# where AHL = (AHI << 16) + ALO
+#
+# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s
+# RUN: lld -flavor gnu -target mipsel -shared -o %t-so %t-obj
+# RUN: llvm-objdump -t -disassemble %t-so | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK: glob1:
+# CHECK-NEXT: f0: 01 00 08 3c lui $8, 1
+# CHECK-NEXT: f4: 01 8f 08 85 lh $8, -28927($8)
+# CHECK-NEXT: f8: 01 00 08 3c lui $8, 1
+# CHECK-NEXT: fc: f7 8e 08 85 lh $8, -28937($8)
+# CHECK-NEXT: 100: 01 00 08 3c lui $8, 1
+# CHECK-NEXT: 104: ef 90 08 85 lh $8, -28433($8)
+# CHECK-NEXT: 108: 01 00 08 3c lui $8, 1
+# CHECK-NEXT: 10c: e9 8c 08 85 lh $8, -29463($8)
+# CHECK-NEXT: 110: 03 00 08 3c lui $8, 3
+# CHECK-NEXT: 114: df 8e 08 85 lh $8, -28961($8)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 000000f0 g F .text 00000028 glob1
+# CHECK: 00008ff0 g *ABS* 00000000 _gp_disp
+
+ .global glob1
+ .ent glob1
+glob1:
+ lui $t0,%hi(_gp_disp+0x1)
+ lh $t0,%lo(_gp_disp+0x1)($t0)
+
+ lui $t0,%hi(_gp_disp+(-0x1))
+ lh $t0,%lo(_gp_disp+(-0x1))($t0)
+
+ lui $t0,%hi(_gp_disp+0x1ff)
+ lh $t0,%lo(_gp_disp+0x1ff)($t0)
+
+ lui $t0,%hi(_gp_disp+(-0x1ff))
+ lh $t0,%lo(_gp_disp+(-0x1ff))($t0)
+
+ lui $t0,%hi(_gp_disp+0x1ffff)
+ lh $t0,%lo(_gp_disp+0x1ffff)($t0)
+ .end glob1
More information about the llvm-commits
mailing list