Fix checks for R_386_8 and R_386_16.

Results created by these relocations are expected to be zero extended
at runtime.

llvm-svn: 294988
This commit is contained in:
Rafael Espindola 2017-02-13 21:29:56 +00:00
parent 752f73b680
commit 195fba2967
7 changed files with 46 additions and 0 deletions

View File

@ -517,11 +517,17 @@ void X86TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
// we want to support them.
switch (Type) {
case R_386_8:
checkUInt<8>(Loc, Val, Type);
*Loc = Val;
break;
case R_386_PC8:
checkInt<8>(Loc, Val, Type);
*Loc = Val;
break;
case R_386_16:
checkUInt<16>(Loc, Val, Type);
write16le(Loc, Val);
break;
case R_386_PC16:
checkInt<16>(Loc, Val, Type);
write16le(Loc, Val);

View File

@ -0,0 +1,3 @@
.globl foo
.hidden foo
foo = 65536

View File

@ -0,0 +1,3 @@
.globl foo
.hidden foo
foo = 0xffff

View File

@ -0,0 +1,3 @@
.globl foo
.hidden foo
foo = 256

View File

@ -0,0 +1,3 @@
.globl foo
.hidden foo
foo = 0xff

View File

@ -0,0 +1,14 @@
// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/x86-64-reloc-16.s -o %t1
// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/x86-64-reloc-16-error.s -o %t2
// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t
// RUN: ld.lld -shared %t %t1 -o %t3
// CHECK: Contents of section .text:
// CHECK-NEXT: 200000 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
.short foo

View File

@ -0,0 +1,14 @@
// REQUIRES: x86
// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/i386-reloc-8.s -o %t1
// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/i386-reloc-8-error.s -o %t2
// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t
// RUN: ld.lld -shared %t %t1 -o %t3
// CHECK: Contents of section .text:
// CHECK-NEXT: 200000 42
// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
// ERROR: relocation R_386_8 out of range
.byte foo