[PATCH] D29490: [ELF] - Use SignExtend when reading R_386_PC8 addend.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 3 08:52:49 PST 2017
%S/Inputs/i386-pc8.s is missing, but why do you need it to be in another
file?
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar updated this revision to Diff 86970.
> grimar added a comment.
>
> - Addressed comments, simplified testcase.
>
>
> https://reviews.llvm.org/D29490
>
> Files:
> ELF/Target.cpp
> test/ELF/i386-pc8-addend.s
>
>
> 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
> 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
> 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);
More information about the llvm-commits
mailing list