summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Target.cpp8
-rw-r--r--lld/test/elf2/tls-error.s12
2 files changed, 18 insertions, 2 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 137dae39b3e..a8bd4a342ad 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -339,9 +339,13 @@ void X86_64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
error("R_X86_64_32S out of range");
write32le(Loc, SA);
break;
- case R_X86_64_TPOFF32:
- write32le(Loc, SA - Out<llvm::object::ELF64LE>::TlsInitImageAlignedSize);
+ case R_X86_64_TPOFF32: {
+ uint64_t Val = SA - Out<llvm::object::ELF64LE>::TlsInitImageAlignedSize;
+ if (!isInt<32>(Val))
+ error("R_X86_64_TPOFF32 out of range");
+ write32le(Loc, Val);
break;
+ }
default:
error("unrecognized reloc " + Twine(Type));
}
diff --git a/lld/test/elf2/tls-error.s b/lld/test/elf2/tls-error.s
new file mode 100644
index 00000000000..21b455a69d7
--- /dev/null
+++ b/lld/test/elf2/tls-error.s
@@ -0,0 +1,12 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+// RUN: not ld.lld2 %t -o %tout 2>&1 | FileCheck %s
+// CHECK: R_X86_64_TPOFF32 out of range
+
+.global _start
+_start:
+ movl %fs:a@tpoff, %eax
+.global a
+.section .tbss,"awT",@nobits
+a:
+.zero 0x80000001
OpenPOWER on IntegriCloud