Index: ELF/Arch/X86.cpp =================================================================== --- ELF/Arch/X86.cpp +++ ELF/Arch/X86.cpp @@ -255,7 +255,7 @@ // R_386_{PC,}{8,16} are not part of the i386 psABI, but they are // being used for some 16-bit programs such as boot loaders, so // we want to support them. - checkUInt(Loc, Val, 8, Type); + checkIntUInt(Loc, Val, 8, Type); *Loc = Val; break; case R_386_PC8: @@ -263,7 +263,7 @@ *Loc = Val; break; case R_386_16: - checkUInt(Loc, Val, 16, Type); + checkIntUInt(Loc, Val, 16, Type); write16le(Loc, Val); break; case R_386_PC16: Index: test/ELF/i386-reloc-16-large-addend.s =================================================================== --- test/ELF/i386-reloc-16-large-addend.s +++ test/ELF/i386-reloc-16-large-addend.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t +# RUN: ld.lld -Ttext 0x7c00 %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 7c00 b800ff + +.code16 +.global _start +_start: + movw $_start+0x8300,%ax Index: test/ELF/i386-reloc-16.s =================================================================== --- test/ELF/i386-reloc-16.s +++ test/ELF/i386-reloc-16.s @@ -10,6 +10,6 @@ // CHECK-NEXT: 1000 42 // RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s -// ERROR: relocation R_386_16 out of range: 65536 is not in [0, 65535] +// ERROR: relocation R_386_16 out of range: 65536 is not in [-32768, 32767] .short foo Index: test/ELF/i386-reloc-8-large-addend.s =================================================================== --- test/ELF/i386-reloc-8-large-addend.s +++ test/ELF/i386-reloc-8-large-addend.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t +# RUN: ld.lld -Ttext 0x7c %t -o %t2 +# RUN: llvm-objdump -s %t2 | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 007c b4ff + +.code16 +.global _start +_start: + movb $_start+0x83,%ah Index: test/ELF/i386-reloc-8.s =================================================================== --- test/ELF/i386-reloc-8.s +++ test/ELF/i386-reloc-8.s @@ -10,6 +10,6 @@ // CHECK-NEXT: 1000 ff // RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s -// ERROR: relocation R_386_8 out of range: 256 is not in [0, 255] +// ERROR: relocation R_386_8 out of range: 256 is not in [-128, 127] .byte foo