yavtuk 0776fc32b1 [BOLT] Search section based on relocation symbol
We need to search referenced section based on relocations symbol section
to properly match end section symbols. For example on some binaries we
can observe that init_array_end/fini_array_end might be "placed" in to
the gap and since no section could be found for address the relocation
would be skipped resulting in wrong ADRP imm after emitting new text
resulting in binary sigsegv.

Credits for the test to Vladislav Khmelevskii aka yota9.
2023-02-08 00:15:56 +03:00

24 lines
804 B
C

// Test checks that bolt properly finds end section label.
// Linker script contains gap after destructor array, so
// __init_array_end address would not be owned by any section.
// REQUIRES: system-linux
// RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q \
// RUN: -Wl,-T %S/Inputs/array_end.lld_script
// RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm \
// RUN: --print-only="callFini" | FileCheck %s
// CHECK: adr [[REG:x[0-28]+]], "__fini_array_end/1"
__attribute__((destructor)) void destr() {}
__attribute__((noinline)) void callFini() {
extern void (*__fini_array_start[])();
extern void (*__fini_array_end[])();
unsigned long Count = __fini_array_end - __fini_array_start;
for (unsigned long I = 0; I < Count; ++I)
(*__fini_array_start[I])();
}
void _start() { callFini(); }