PIE binaries use R_*_RELATIVE dynamic relocations for indirect goto jump tables. BOLT creates entry points for their targets but does not mark these addresses as targets from data relocations, so indirect jumps with unknown control flow (which originates from indirect goto) have no CFG successors and are interpreted as potential tail calls, while the jump targets are incorrectly identified as additional entry points. Add these offsets to the function's list of non-entry relocation references instead of marking them as entry points. Extend relocation rewriting to also check whether a block is externally referenced. This mirrors behavior of data-to-code relocations in non-pie binaries.
14 lines
542 B
Text
14 lines
542 B
Text
// This test checks that BOLT recognizes unknown control flow from sources that
|
|
// use indirect goto.
|
|
|
|
REQUIRES: system-linux
|
|
|
|
RUN: %clang %cflags -pie %S/Inputs/indirect_goto.c -o %t.exe -Wl,-q
|
|
RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg --print-only=main \
|
|
RUN: | FileCheck --check-prefix=CHECK-PIE %s
|
|
|
|
// Check that BOLT discovers basic blocks for dynamic relocations with PIE.
|
|
CHECK-PIE: Binary Function "main" after building cfg {
|
|
CHECK-PIE: IsMultiEntry: 0
|
|
CHECK-PIE: BB Count : {{5|6}}
|
|
// BB Count can vary across architectures.
|