[lld] r239225 - [Mips] Check symbol alignment for some MIPS relocations.
Simon Atanasyan
simon at atanasyan.com
Sat Jun 6 10:26:28 PDT 2015
Author: atanasyan
Date: Sat Jun 6 12:26:28 2015
New Revision: 239225
URL: http://llvm.org/viewvc/llvm-project?rev=239225&view=rev
Log:
[Mips] Check symbol alignment for some MIPS relocations.
Added:
lld/trunk/test/elf/Mips/rel-pc18-s3-align.test
lld/trunk/test/elf/Mips/rel-pc19-s2-align.test
lld/trunk/test/elf/Mips/rel-pc21-s2-align.test
lld/trunk/test/elf/Mips/rel-pc26-s2-align.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.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=239225&r1=239224&r2=239225&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Sat Jun 6 12:26:28 2015
@@ -296,34 +296,37 @@ static int64_t relocGPRel32(uint64_t S,
/// \brief R_MIPS_PC18_S3, R_MICROMIPS_PC18_S3
/// local/external: (S + A - P) >> 3 (P with cleared 3 less significant bits)
-static int32_t relocPc18(uint64_t P, uint64_t S, int64_t A) {
+static ErrorOr<int64_t> relocPc18(uint64_t P, uint64_t S, int64_t A) {
A = llvm::SignExtend32<21>(A);
- // FIXME (simon): Check that S + A has 8-byte alignment
- int32_t result = S + A - ((P | 7) ^ 7);
- return result;
+ if ((S + A) & 6)
+ return make_unaligned_range_reloc_error();
+ return S + A - ((P | 7) ^ 7);
}
/// \brief R_MIPS_PC19_S2, R_MICROMIPS_PC19_S2
/// local/external: (S + A - P) >> 2
-static int32_t relocPc19(uint64_t P, uint64_t S, int64_t A) {
+static ErrorOr<int64_t> relocPc19(uint64_t P, uint64_t S, int64_t A) {
A = llvm::SignExtend32<21>(A);
- // FIXME (simon): Check that S + A has 4-byte alignment
+ if ((S + A) & 2)
+ return make_unaligned_range_reloc_error();
return S + A - P;
}
/// \brief R_MIPS_PC21_S2, R_MICROMIPS_PC21_S2
/// local/external: (S + A - P) >> 2
-static int32_t relocPc21(uint64_t P, uint64_t S, int64_t A) {
+static ErrorOr<int64_t> relocPc21(uint64_t P, uint64_t S, int64_t A) {
A = llvm::SignExtend32<23>(A);
- // FIXME (simon): Check that S + A has 4-byte alignment
+ if ((S + A) & 2)
+ return make_unaligned_range_reloc_error();
return S + A - P;
}
/// \brief R_MIPS_PC26_S2, R_MICROMIPS_PC26_S2
/// local/external: (S + A - P) >> 2
-static int32_t relocPc26(uint64_t P, uint64_t S, int64_t A) {
+static ErrorOr<int64_t> relocPc26(uint64_t P, uint64_t S, int64_t A) {
A = llvm::SignExtend32<28>(A);
- // FIXME (simon): Check that S + A has 4-byte alignment
+ if ((S + A) & 2)
+ return make_unaligned_range_reloc_error();
return S + A - P;
}
Added: lld/trunk/test/elf/Mips/rel-pc18-s3-align.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-pc18-s3-align.test?rev=239225&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-pc18-s3-align.test (added)
+++ lld/trunk/test/elf/Mips/rel-pc18-s3-align.test Sat Jun 6 12:26:28 2015
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC18_S3 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T1+0 to T1+0 of type 62 (R_MIPS_PC18_S3)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PC18_S3
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
Added: lld/trunk/test/elf/Mips/rel-pc19-s2-align.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-pc19-s2-align.test?rev=239225&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-pc19-s2-align.test (added)
+++ lld/trunk/test/elf/Mips/rel-pc19-s2-align.test Sat Jun 6 12:26:28 2015
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC19_S2 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T0+0 to T1+0 of type 63 (R_MIPS_PC19_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC19_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
Added: lld/trunk/test/elf/Mips/rel-pc21-s2-align.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-pc21-s2-align.test?rev=239225&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-pc21-s2-align.test (added)
+++ lld/trunk/test/elf/Mips/rel-pc21-s2-align.test Sat Jun 6 12:26:28 2015
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC21_S2 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T0+0 to T1+0 of type 60 (R_MIPS_PC21_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
Added: lld/trunk/test/elf/Mips/rel-pc26-s2-align.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-pc26-s2-align.test?rev=239225&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-pc26-s2-align.test (added)
+++ lld/trunk/test/elf/Mips/rel-pc26-s2-align.test Sat Jun 6 12:26:28 2015
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC26_S2 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T0+0 to T1+0 of type 61 (R_MIPS_PC26_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC26_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
More information about the llvm-commits
mailing list