[PATCH] D28094: [ELF] - Implemented support for R_386_PC8/R_386_8 relocations.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 05:31:33 PST 2017
LGTM
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar updated this revision to Diff 85706.
> grimar added a comment.
>
> - Addressed review comments.
>
>
> https://reviews.llvm.org/D28094
>
> Files:
> ELF/Target.cpp
> test/ELF/Inputs/i386-pc8.s
> test/ELF/i386-pc8.s
> test/ELF/unknown-reloc.s
>
>
> Index: test/ELF/unknown-reloc.s
> ===================================================================
> --- test/ELF/unknown-reloc.s
> +++ test/ELF/unknown-reloc.s
> @@ -1,14 +0,0 @@
> -# 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/unknown-reloc.s -o %t2.o
> -# RUN: not ld.lld %t1.o %t2.o -o %t.out 2>&1 | FileCheck %s
> -
> -# CHECK: do not know how to handle relocation 'R_386_PC8' (23)
> -# CHECK: do not know how to handle relocation 'R_386_8' (22)
> -
> -.text
> -.global foo
> -foo:
> -
> -.byte und-foo
> -.byte foo
> Index: test/ELF/i386-pc8.s
> ===================================================================
> --- test/ELF/i386-pc8.s
> +++ test/ELF/i386-pc8.s
> @@ -0,0 +1,13 @@
> +# 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: ld.lld %t1.o %t2.o -o %t.out
> +# RUN: llvm-objdump -s -section=.text %t.out | FileCheck %s
> +
> +# CHECK: Contents of section .text:
> +# CHECK-NEXT: 11000 15253748
> +
> +.byte und-.+0x11
> +.byte und-.+0x22
> +.byte und+0x33
> +.byte und+0x44
> Index: test/ELF/Inputs/i386-pc8.s
> ===================================================================
> --- test/ELF/Inputs/i386-pc8.s
> +++ test/ELF/Inputs/i386-pc8.s
> @@ -0,0 +1,2 @@
> +.global und
> +und:
> Index: ELF/Target.cpp
> ===================================================================
> --- ELF/Target.cpp
> +++ ELF/Target.cpp
> @@ -356,6 +356,7 @@
>
> RelExpr X86TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
> switch (Type) {
> + case R_386_8:
> case R_386_16:
> case R_386_32:
> case R_386_TLS_LDO_32:
> @@ -366,6 +367,7 @@
> return R_TLSLD;
> case R_386_PLT32:
> return R_PLT_PC;
> + case R_386_PC8:
> case R_386_PC16:
> case R_386_PC32:
> return R_PC;
> @@ -486,6 +488,9 @@
> switch (Type) {
> default:
> return 0;
> + case R_386_8:
> + case R_386_PC8:
> + return *Buf;
> case R_386_16:
> case R_386_PC16:
> return read16le(Buf);
> @@ -505,8 +510,12 @@
> uint64_t Val) const {
> checkInt<32>(Loc, Val, Type);
>
> - // R_386_PC16 and R_386_16 are not part of the current i386 psABI. They are
> - // used by 16-bit x86 objects, like boot loaders.
> + // R_386_PC16/R_386_16/R_386_PC8/R_386_8 are not part of the current i386
> + // psABI. They are used by 16-bit x86 objects, like boot loaders.
> + if (Type == R_386_8 || Type == R_386_PC8) {
> + *Loc = (uint8_t)Val;
> + return;
> + }
> if (Type == R_386_16 || Type == R_386_PC16) {
> write16le(Loc, Val);
> return;
>
>
> Index: test/ELF/unknown-reloc.s
> ===================================================================
> --- test/ELF/unknown-reloc.s
> +++ test/ELF/unknown-reloc.s
> @@ -1,14 +0,0 @@
> -# 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/unknown-reloc.s -o %t2.o
> -# RUN: not ld.lld %t1.o %t2.o -o %t.out 2>&1 | FileCheck %s
> -
> -# CHECK: do not know how to handle relocation 'R_386_PC8' (23)
> -# CHECK: do not know how to handle relocation 'R_386_8' (22)
> -
> -.text
> -.global foo
> -foo:
> -
> -.byte und-foo
> -.byte foo
> Index: test/ELF/i386-pc8.s
> ===================================================================
> --- test/ELF/i386-pc8.s
> +++ test/ELF/i386-pc8.s
> @@ -0,0 +1,13 @@
> +# 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: ld.lld %t1.o %t2.o -o %t.out
> +# RUN: llvm-objdump -s -section=.text %t.out | FileCheck %s
> +
> +# CHECK: Contents of section .text:
> +# CHECK-NEXT: 11000 15253748
> +
> +.byte und-.+0x11
> +.byte und-.+0x22
> +.byte und+0x33
> +.byte und+0x44
> Index: test/ELF/Inputs/i386-pc8.s
> ===================================================================
> --- test/ELF/Inputs/i386-pc8.s
> +++ test/ELF/Inputs/i386-pc8.s
> @@ -0,0 +1,2 @@
> +.global und
> +und:
> Index: ELF/Target.cpp
> ===================================================================
> --- ELF/Target.cpp
> +++ ELF/Target.cpp
> @@ -356,6 +356,7 @@
>
> RelExpr X86TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
> switch (Type) {
> + case R_386_8:
> case R_386_16:
> case R_386_32:
> case R_386_TLS_LDO_32:
> @@ -366,6 +367,7 @@
> return R_TLSLD;
> case R_386_PLT32:
> return R_PLT_PC;
> + case R_386_PC8:
> case R_386_PC16:
> case R_386_PC32:
> return R_PC;
> @@ -486,6 +488,9 @@
> switch (Type) {
> default:
> return 0;
> + case R_386_8:
> + case R_386_PC8:
> + return *Buf;
> case R_386_16:
> case R_386_PC16:
> return read16le(Buf);
> @@ -505,8 +510,12 @@
> uint64_t Val) const {
> checkInt<32>(Loc, Val, Type);
>
> - // R_386_PC16 and R_386_16 are not part of the current i386 psABI. They are
> - // used by 16-bit x86 objects, like boot loaders.
> + // R_386_PC16/R_386_16/R_386_PC8/R_386_8 are not part of the current i386
> + // psABI. They are used by 16-bit x86 objects, like boot loaders.
> + if (Type == R_386_8 || Type == R_386_PC8) {
> + *Loc = (uint8_t)Val;
> + return;
> + }
> if (Type == R_386_16 || Type == R_386_PC16) {
> write16le(Loc, Val);
> return;
More information about the llvm-commits
mailing list