|
| 1 | +// -*- C++ -*- |
| 2 | +//===----------------------------------------------------------------------===// |
| 3 | +// |
| 4 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +// Manually marking the .eh_frame_hdr as DW_EH_PE_omit to make libunwind to do |
| 11 | +// the linear search. |
| 12 | +// Assuming the begining of the function is at the start of the FDE range. |
| 13 | + |
| 14 | +// clang-format off |
| 15 | + |
| 16 | +// REQUIRES: linux |
| 17 | + |
| 18 | +// TODO: Figure out why this fails with Memory Sanitizer. |
| 19 | +// XFAIL: msan |
| 20 | + |
| 21 | +// RUN: %{build} |
| 22 | +// RUN: objcopy --dump-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe |
| 23 | +// RUN: echo -ne '\xFF' | dd of=%t_ehf_hdr.bin bs=1 seek=2 count=2 conv=notrunc status=none |
| 24 | +// RUN: objcopy --update-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe |
| 25 | +// RUN: %{exec} %t.exe |
| 26 | + |
| 27 | +// clang-format on |
| 28 | + |
| 29 | +#include <assert.h> |
| 30 | +#include <libunwind.h> |
| 31 | +#include <stdint.h> |
| 32 | +#include <stdio.h> |
| 33 | +#include <unwind.h> |
| 34 | + |
| 35 | +void f() { |
| 36 | + printf("123\n"); |
| 37 | + void *pc = __builtin_return_address(0); |
| 38 | + void *fpc = (void *)&f; |
| 39 | + void *fpc1 = (void *)((uintptr_t)fpc + 1); |
| 40 | + |
| 41 | + struct dwarf_eh_bases bases; |
| 42 | + const void *fde_pc = _Unwind_Find_FDE(pc, &bases); |
| 43 | + const void *fde_fpc = _Unwind_Find_FDE(fpc, &bases); |
| 44 | + const void *fde_fpc1 = _Unwind_Find_FDE(fpc1, &bases); |
| 45 | + printf("fde_pc = %p\n", fde_pc); |
| 46 | + printf("fde_fpc = %p\n", fde_fpc); |
| 47 | + printf("fde_fpc1 = %p\n", fde_fpc1); |
| 48 | + fflush(stdout); |
| 49 | + assert(fde_pc != NULL); |
| 50 | + assert(fde_fpc != NULL); |
| 51 | + assert(fde_fpc1 != NULL); |
| 52 | + assert(fde_fpc == fde_fpc1); |
| 53 | +} |
| 54 | + |
| 55 | +int main() { |
| 56 | + f(); |
| 57 | + return 0; |
| 58 | +} |
0 commit comments