llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-bolt Author: Amir Ayupov (aaupov) <details> <summary>Changes</summary> Lift the restriction that builtin_unreachable has to be strictly within `MaxSize` of a function. Test Plan: added builtin_unreachable.s --- Full diff: https://github.com/llvm/llvm-project/pull/111771.diff 2 Files Affected: - (modified) bolt/lib/Core/BinaryFunction.cpp (+3-2) - (added) bolt/test/X86/builtin_unreachable.s (+33) ``````````diff diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 27c8ccefedee10..8b1f441a3a01da 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1365,8 +1365,9 @@ Error BinaryFunction::disassemble() { if (containsAddress(TargetAddress)) { TargetSymbol = getOrCreateLocalLabel(TargetAddress); } else { - if (TargetAddress == getAddress() + getSize() && - TargetAddress < getAddress() + getMaxSize() && + if (BC.isELF() && !BC.getBinaryDataAtAddress(TargetAddress) && + TargetAddress == getAddress() + getSize() && + TargetAddress <= getAddress() + getMaxSize() && !(BC.isAArch64() && BC.handleAArch64Veneer(TargetAddress, /*MatchOnly*/ true))) { // Result of __builtin_unreachable(). diff --git a/bolt/test/X86/builtin_unreachable.s b/bolt/test/X86/builtin_unreachable.s new file mode 100644 index 00000000000000..ab533629d1a846 --- /dev/null +++ b/bolt/test/X86/builtin_unreachable.s @@ -0,0 +1,33 @@ +## Check that BOLT properly identifies a jump to builtin_unreachable + +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o +# RUN: ld.lld -q -o %t %t.o +# RUN: llvm-bolt %t -o %t.null -lite=0 -print-disasm | FileCheck %s +# CHECK: callq bar +# CHECK-NEXT: nop + +.text +.globl main +.type main, @function +main: + call foo + .size main, .-main + +.section .mytext.bar, "ax" +.globl bar +.type bar, @function +bar: + ud2 + .size bar, .-bar + +.section .mytext.foo, "ax" +.globl foo +.type foo, @function +foo: +.cfi_startproc + callq bar + jmp .Lunreachable + ret + .cfi_endproc + .size foo, .-foo +.Lunreachable: `````````` </details> https://github.com/llvm/llvm-project/pull/111771 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits