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,42 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o +# RUN: llvm-objdump -d %t1.o | FileCheck %s --check-prefix=OBJDISASM +# RUN: llvm-readobj -r %t1.o | FileCheck %s --check-prefix=OBJRELOC + +## Show that we have R_386_PC8 relocation with addend = 0xFF(-1). +# OBJDISASM: Disassembly of section .text: +# OBJDISASM-NEXT: .text: +# OBJDISASM-NEXT: 0: eb ff jmp -1 <.text+0x1> +# OBJRELOC: Relocations [ +# OBJRELOC-NEXT: Section {{.*}} .rel.text { +# OBJRELOC-NEXT: 0x1 R_386_PC8 .foo 0x0 +# OBJRELOC-NEXT: } +# OBJRELOC-NEXT: ] + +## Check that there is no link error and relocation applied correctly. +# RUN: ld.lld %t1.o -o %t.out +# RUN: llvm-objdump -d %t.out | FileCheck %s --check-prefix=DISASM +# DISASM: Disassembly of section .text: +# DISASM-NEXT: .text: +# DISASM-NEXT: 11000: eb 04 jmp 4 +# DISASM: Disassembly of section .foo: +# DISASM-NEXT: foo: +# DISASM-NEXT: 11006: 90 nop + +# CHECK: Contents of section .text: +# CHECK-NEXT: 0000 15253748 + +.code16 + +.byte 0xeb # short (2-byte) jump +.byte foo-1f + +1: +nop +nop +nop +nop + +.section ".foo", "ax" +foo: + nop