Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -492,8 +492,9 @@ default: return 0; case R_386_8: - case R_386_PC8: return *Buf; + case R_386_PC8: + return SignExtend64<8>(*Buf); case R_386_16: case R_386_PC16: return read16le(Buf); Index: test/ELF/i386-pc8-addend.s =================================================================== --- test/ELF/i386-pc8-addend.s +++ test/ELF/i386-pc8-addend.s @@ -0,0 +1,25 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %S/Inputs/i386-pc8.s -o %t2.o +# RUN: llvm-objdump -d %t1.o | FileCheck %s --check-prefix=OBJDISASM + +## Show that we have relocation with addend = 0xFF(-1), +## we do sign extend for its value in the code. +# OBJDISASM: Disassembly of section .text: +# OBJDISASM-NEXT: .text: +# OBJDISASM-NEXT: 0: ff + +## Check that there is no link error and relocation applied correctly. +# RUN: ld.lld %t1.o %t2.o -o %t.out +# RUN: llvm-objdump -d %t.out | FileCheck %s --check-prefix=DISASM +# RUN: llvm-readobj -symbols %t.out | FileCheck %s --check-prefix=SYM +# DISASM: Disassembly of section .text: +# DISASM-NEXT: .text: +# DISASM-NEXT: 11000: 03 +## 0x11004 - 0x11000 + addend = 0x3 +# SYM: Symbol { +# SYM: Name: und +# SYM-NEXT: Value: 0x11004 + +.code16 +.byte und-.-1