Index: bolt/lib/Rewrite/RewriteInstance.cpp =================================================================== --- bolt/lib/Rewrite/RewriteInstance.cpp +++ bolt/lib/Rewrite/RewriteInstance.cpp @@ -1058,6 +1058,16 @@ continue; } + if (Address == Section->getAddress() + Section->getSize()) { + assert(SymbolSize == 0 && + "unexpect non-zero sized symbol at end of section"); + LLVM_DEBUG( + dbgs() + << "BOLT-DEBUG: rejecting as symbol points to end of its section\n"); + registerName(SymbolSize); + continue; + } + // Assembly functions could be ST_NONE with 0 size. Check that the // corresponding section is a code section and they are not inside any // other known function to consider them. Index: bolt/test/X86/section-end-sym.s =================================================================== --- /dev/null +++ bolt/test/X86/section-end-sym.s @@ -0,0 +1,29 @@ +## Check that BOLT doesn't consider end-of-section symbols (e.g., _etext) as +## functions. + +# REQUIRES: system-linux + +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t.exe -q +# RUN: llvm-bolt %t.exe -o /dev/null --print-cfg --debug-only=bolt 2>&1 \ +# RUN: | FileCheck %s + +# CHECK: considering symbol etext for function +# CHECK-NEXT: rejecting as symbol points to end of its section +# CHECK-NOT: Binary Function "etext{{.*}}" after building cfg + + + .text + .globl _start + .type _start,@function +_start: + retq + .size _start, .-_start + + .align 0x1000 + .globl etext +etext: + + .data +.Lfoo: + .word 0