diff options
-rw-r--r-- | lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp | 7 | ||||
-rw-r--r-- | test/NaCl/ARM/negative-addend.ll | 19 | ||||
-rw-r--r-- | test/NaCl/X86/negative-addend.ll | 27 |
3 files changed, 53 insertions, 0 deletions
diff --git a/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp index 613edb00b5..7c1ebd1d3f 100644 --- a/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -99,12 +99,19 @@ public: assert(Fixup.getOffset() + Size <= DataSize && "Invalid fixup offset!"); + // @LOCALMOD-BEGIN + // This check breaks negative addends on x86-32. It makes x86-32 + // behaviour inconsistent with x86-64 and ARM. + // See: https://code.google.com/p/nativeclient/issues/detail?id=3548 +#if 0 // Check that uppper bits are either all zeros or all ones. // Specifically ignore overflow/underflow as long as the leakage is // limited to the lower bits. This is to remain compatible with // other assemblers. assert(isIntN(Size * 8 + 1, Value) && "Value does not fit in the Fixup field"); +#endif + // @LOCALMOD-END for (unsigned i = 0; i != Size; ++i) Data[Fixup.getOffset() + i] = uint8_t(Value >> (i * 8)); diff --git a/test/NaCl/ARM/negative-addend.ll b/test/NaCl/ARM/negative-addend.ll new file mode 100644 index 0000000000..41d7eba43c --- /dev/null +++ b/test/NaCl/ARM/negative-addend.ll @@ -0,0 +1,19 @@ +; RUN: pnacl-llc -mtriple=arm-unknown-nacl -filetype=obj %s -o - \ +; RUN: | llvm-objdump -r - | FileCheck %s -check-prefix=ARM + +; Check that "add" works for negative values when used as a +; ConstantExpr in a global variable initializer. +; See: https://code.google.com/p/nativeclient/issues/detail?id=3548 + + +; @spacer and @var end up in the BSS section. +; @spacer is at offset 0. @var is at offset 4096 = 0x1000. + +@spacer = internal global [4096 x i8] zeroinitializer +@var = internal global i32 zeroinitializer + +@negative_offset = internal global i32 add + (i32 ptrtoint (i32* @var to i32), i32 -8) + +; ARM: RELOCATION RECORDS FOR [.data.rel.local]: +; ARM-NEXT: 0 R_ARM_ABS32 .bss diff --git a/test/NaCl/X86/negative-addend.ll b/test/NaCl/X86/negative-addend.ll new file mode 100644 index 0000000000..e46f091cc0 --- /dev/null +++ b/test/NaCl/X86/negative-addend.ll @@ -0,0 +1,27 @@ +; RUN: pnacl-llc -mtriple=i386-unknown-nacl -filetype=obj %s -o - \ +; RUN: | llvm-objdump -r - | FileCheck %s -check-prefix=X8632 +; RUN: pnacl-llc -mtriple=x86_64-unknown-nacl -filetype=obj %s -o - \ +; RUN: | llvm-objdump -r - | FileCheck %s -check-prefix=X8664 + +; Check that "add" works for negative values when used as a +; ConstantExpr in a global variable initializer. +; See: https://code.google.com/p/nativeclient/issues/detail?id=3548 + + +; @spacer and @var end up in the BSS section. +; @spacer is at offset 0. @var is at offset 4096 = 0x1000. + +@spacer = internal global [4096 x i8] zeroinitializer +@var = internal global i32 zeroinitializer + +@negative_offset = internal global i32 add + (i32 ptrtoint (i32* @var to i32), i32 -8) + +; Note that the addend 4294971384 below equals 0x100000ff8, where +; 0xff8 comes from subtracting 8 from the offset of @var. + +; X8632: RELOCATION RECORDS FOR [.data]: +; X8632-NEXT: 0 R_386_32 Unknown + +; X8664: RELOCATION RECORDS FOR [.data]: +; X8664-NEXT: 0 R_X86_64_32 .bss+4294971384 |