diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp --- a/lld/ELF/Thunks.cpp +++ b/lld/ELF/Thunks.cpp @@ -910,7 +910,7 @@ void PPC64R12SetupStub::writeTo(uint8_t *buf) { int64_t offset = destination.getVA() - getThunkTargetSym()->getVA(); if (!isInt<34>(offset)) - fatal("offset must fit in 34 bits to encode in the instruction"); + fatal("offset overflow 34 bits; recompile using the large code model"); uint64_t paddi = PADDI_R12_NO_DISP | (((offset >> 16) & 0x3ffff) << 32) | (offset & 0xffff); @@ -927,7 +927,7 @@ void PPC64PCRelPLTStub::writeTo(uint8_t *buf) { int64_t offset = destination.getGotPltVA() - getThunkTargetSym()->getVA(); if (!isInt<34>(offset)) - fatal("offset must fit in 34 bits to encode in the instruction"); + fatal("offset overflow 34 bits; recompile using the large code model"); uint64_t pld = PLD_R12_NO_DISP | (((offset >> 16) & 0x3ffff) << 32) | (offset & 0xffff); @@ -965,7 +965,7 @@ void PPC64PCRelLongBranchThunk::writeTo(uint8_t *buf) { int64_t offset = destination.getVA() - getThunkTargetSym()->getVA(); if (!isInt<34>(offset)) - fatal("offset overflow 34 bits, please compile using the large code model"); + fatal("offset overflow 34 bits; recompile using the large code model"); uint64_t paddi = PADDI_R12_NO_DISP | (((offset >> 16) & 0x3ffff) << 32) | (offset & 0xffff); diff --git a/lld/test/ELF/ppc64-pcrel-call-to-extern-error.s b/lld/test/ELF/ppc64-pcrel-call-to-extern-error.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/ppc64-pcrel-call-to-extern-error.s @@ -0,0 +1,33 @@ +# REQUIRES: ppc, linux +# RUN: echo 'SECTIONS { \ +# RUN: .text_high 0x200002010 : { *(.text_high) } \ +# RUN: }' > %t.script + +## In this test, we do not use -o /dev/null like other similar cases do since +## it will fail in some enviroments with out-of-memory errors associated with +## buffering the output in memeory. The test is enabled for ppc linux only since +## writing to an allocated file will cause time out error for this case on freebsd. + +# RUN: llvm-mc -filetype=obj -triple=powerpc64le --defsym AUX=1 %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t2.o +# RUN: ld.lld --shared --soname=t2.so %t2.o -o %t2.so +# RUN: not ld.lld -T %t.script %t1.o %t2.so -o %t 2>&1 | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=powerpc64 --defsym AUX=1 %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t2.o +# RUN: ld.lld --shared --soname=t2.so %t2.o -o %t2.so +# RUN: not ld.lld -T %t.script %t1.o %t2.so -o %t 2>&1 | FileCheck %s + +# CHECK: error: offset overflow 34 bits; recompile using the large code model + +.ifdef AUX +.section .text_high, "ax", %progbits +caller: + .localentry caller, 1 + bl callee@notoc + blr +.else +.globl callee +callee: + blr +.endif diff --git a/lld/test/ELF/ppc64-pcrel-call-to-toc-error.s b/lld/test/ELF/ppc64-pcrel-call-to-toc-error.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/ppc64-pcrel-call-to-toc-error.s @@ -0,0 +1,37 @@ +# REQUIRES: ppc, linux +# RUN: echo 'SECTIONS { \ +# RUN: .text_low 0x2000: { *(.text_low) } \ +# RUN: .text_high 0x200002010 : { *(.text_high) } \ +# RUN: }' > %t.script + +## In this test, we do not use -o /dev/null like other similar cases do since +## it will fail in some enviroments with out-of-memory errors associated with +## buffering the output in memeory. The test is enabled for ppc linux only since +## writing to an allocated file will cause time out error for this case on freebsd. + +# RUN: llvm-mc -filetype=obj -triple=ppc64le %s -o %t.o +# RUN: not ld.lld -T %t.script %t.o -o %t 2>&1 | FileCheck %s + +# RUN: llvm-mc -filetype=obj -triple=ppc64 %s -o %t.o +# RUN: not ld.lld -T %t.script %t.o -o %t 2>&1 | FileCheck %s + +# CHECK: error: offset overflow 34 bits; recompile using the large code model + +.section .text_high, "ax", %progbits +callee: + .Lfunc_gep1: + addis 2, 12, .TOC.-.Lfunc_gep1@ha + addi 2, 2, .TOC.-.Lfunc_gep1@l + .Lfunc_lep1: + .localentry callee, .Lfunc_lep1-.Lfunc_gep1 + addis 4, 2, global@toc@ha + lwz 4, global@toc@l(4) + blr + +.section .text_low, "ax", %progbits +caller: + .localentry caller, 1 + bl callee@notoc + blr +global: + .long 0 diff --git a/lld/test/ELF/ppc64-pcrel-long-branch-error.s b/lld/test/ELF/ppc64-pcrel-long-branch-error.s --- a/lld/test/ELF/ppc64-pcrel-long-branch-error.s +++ b/lld/test/ELF/ppc64-pcrel-long-branch-error.s @@ -19,7 +19,7 @@ # RUN: llvm-mc -filetype=obj -triple=ppc64 -defsym HIDDEN=1 %s -o %t.o # RUN: not ld.lld -shared -T %t.script %t.o -o %t 2>&1 | FileCheck %s -# CHECK: error: offset overflow 34 bits, please compile using the large code model +# CHECK: error: offset overflow 34 bits; recompile using the large code model .section .text_low, "ax", %progbits .globl _start