diff options
author | Alexander Richardson <arichardson.kde@gmail.com> | 2017-10-06 16:15:59 +0000 |
---|---|---|
committer | Alexander Richardson <arichardson.kde@gmail.com> | 2017-10-06 16:15:59 +0000 |
commit | f52a3b94e15a94b2c07c67cb2f513b00758ed7bc (patch) | |
tree | a91ae824913c45ac38ea912556d48957e71bb5a2 | |
parent | 195a66f6ebba94fba0c9da510f336556c856a189 (diff) | |
download | bcm5719-llvm-f52a3b94e15a94b2c07c67cb2f513b00758ed7bc.tar.gz bcm5719-llvm-f52a3b94e15a94b2c07c67cb2f513b00758ed7bc.zip |
[ELF][MIPS] Check for overflow when writing R_MIPS_CALL16 and R_MIPS_TLS_GOTTPREL
Summary:
These are 16 bit relocations and not part of a HI/LO pair so we need to
check that they don't overflow.
Reviewers: atanasyan
Reviewed By: atanasyan
Subscribers: ruiu, llvm-commits, emaste, sdardis
Tags: #lld
Differential Revision: https://reviews.llvm.org/D38614
llvm-svn: 315073
-rw-r--r-- | lld/ELF/Arch/Mips.cpp | 4 | ||||
-rw-r--r-- | lld/test/ELF/mips-out-of-bounds-call16-reloc.s | 29 |
2 files changed, 31 insertions, 2 deletions
diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp index 8706edcff74..6420ec73a99 100644 --- a/lld/ELF/Arch/Mips.cpp +++ b/lld/ELF/Arch/Mips.cpp @@ -501,21 +501,21 @@ void MIPS<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { writeMicroRelocation32<E>(Loc, Val, 16, 0); } break; + case R_MIPS_CALL16: case R_MIPS_GOT_DISP: case R_MIPS_GOT_PAGE: case R_MIPS_GPREL16: case R_MIPS_TLS_GD: + case R_MIPS_TLS_GOTTPREL: case R_MIPS_TLS_LDM: checkInt<16>(Loc, Val, Type); LLVM_FALLTHROUGH; - case R_MIPS_CALL16: case R_MIPS_CALL_LO16: case R_MIPS_GOT_LO16: case R_MIPS_GOT_OFST: case R_MIPS_LO16: case R_MIPS_PCLO16: case R_MIPS_TLS_DTPREL_LO16: - case R_MIPS_TLS_GOTTPREL: case R_MIPS_TLS_TPREL_LO16: writeRelocation<E>(Loc, Val, 16, 0); break; diff --git a/lld/test/ELF/mips-out-of-bounds-call16-reloc.s b/lld/test/ELF/mips-out-of-bounds-call16-reloc.s new file mode 100644 index 00000000000..e5ac59c9530 --- /dev/null +++ b/lld/test/ELF/mips-out-of-bounds-call16-reloc.s @@ -0,0 +1,29 @@ +# Check that we create an error on an out-of-bounds R_MIPS_CALL_16 + +# REQUIRES: mips +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t1.o +# RUN: not ld.lld %t1.o -o %t.exe 2>&1 | FileCheck %s + +# CHECK: relocation R_MIPS_CALL16 out of range + +.macro generate_values + .irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + .irp j, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + .irp k, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + .irp l, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + .text + .globl sym_\i\j\k\l + sym_\i\j\k\l: + nop + lw $25,%call16(sym_\i\j\k\l)($28) + .endr + .endr + .endr + .endr +.endm + +generate_values + +.globl __start +__start: + nop |