1// This test checks that .eh_frame_hdr address is in bounds of the last LOAD
2// end address i.e. the section address is smaller then the LOAD end address.
3
4// REQUIRES: system-linux,bolt-runtime,target=x86_64{{.*}}
5
6// RUN: %clangxx %cxxflags -static -Wl,-q %s -o %t.exe -Wl,--entry=_start
7// RUN: llvm-bolt %t.exe -o %t.instr -instrument \
8// RUN: --instrumentation-file=%t.fdata -instrumentation-sleep-time=1
9// RUN: (llvm-readelf -SW %t.instr | grep -v bolt; llvm-readelf -lW %t.instr | \
10// RUN: grep LOAD | tail -n 1) | FileCheck %s
11
12// CHECK: {{.*}} .eh_frame_hdr PROGBITS [[#%x, EH_ADDR:]]
13// CHECK: LOAD 0x[[#%x, LD_OFFSET:]] 0x[[#%x, LD_VADDR:]] 0x[[#%x, LD_FSIZE:]]
14// CHECK-SAME: 0x[[#%x, LD_MEMSIZE:]]
15//
16// If .eh_frame_hdr address bigger then last LOAD segment end address test would
17// fail with overflow error, otherwise the result of the expression is 0 that
18// could be found on this line e.g. in LOAD align field.
19// CHECK-SAME: [[#LD_VADDR + LD_MEMSIZE - max(LD_VADDR + LD_MEMSIZE,EH_ADDR)]]
20
21#include <cstdio>
22#include <stdexcept>
23
24void foo() { throw std::runtime_error("Exception from foo()"); }
25
26void bar() { foo(); }
27
28int main() {
29 try {
30 bar();
31 } catch (const std::exception &e) {
32 printf(format: "Exception caught: %s\n", e.what());
33 }
34}
35
36extern "C" {
37void _start();
38}
39
40void _start() { main(); }
41

source code of bolt/test/X86/instrumentation-eh_frame_hdr.cpp