61 lines · cpp
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-exception7//8//===----------------------------------------------------------------------===//9 10// Manually marking the .eh_frame_hdr as DW_EH_PE_omit to make libunwind to do11// the linear search.12// Assuming the begining of the function is at the start of the FDE range.13 14// clang-format off15 16// REQUIRES: target={{x86_64-.+}}17// REQUIRES: objcopy-available18// UNSUPPORTED: target={{.*-windows.*}}19 20// TODO: Figure out why this fails with Memory Sanitizer.21// XFAIL: msan22 23// RUN: %{build}24// RUN: %{objcopy} --dump-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe25// RUN: printf '\377' | dd of=%t_ehf_hdr.bin bs=1 seek=2 count=2 conv=notrunc status=none26// RUN: %{objcopy} --update-section .eh_frame_hdr=%t_ehf_hdr.bin %t.exe27// RUN: %{exec} %t.exe28 29// clang-format on30 31#include <assert.h>32#include <libunwind.h>33#include <stdint.h>34#include <stdio.h>35#include <unwind.h>36 37void f() {38 printf("123\n");39 void *pc = __builtin_return_address(0);40 void *fpc = (void *)&f;41 void *fpc1 = (void *)((uintptr_t)fpc + 1);42 43 struct dwarf_eh_bases bases;44 const void *fde_pc = _Unwind_Find_FDE(pc, &bases);45 const void *fde_fpc = _Unwind_Find_FDE(fpc, &bases);46 const void *fde_fpc1 = _Unwind_Find_FDE(fpc1, &bases);47 printf("fde_pc = %p\n", fde_pc);48 printf("fde_fpc = %p\n", fde_fpc);49 printf("fde_fpc1 = %p\n", fde_fpc1);50 fflush(stdout);51 assert(fde_pc != NULL);52 assert(fde_fpc != NULL);53 assert(fde_fpc1 != NULL);54 assert(fde_fpc == fde_fpc1);55}56 57int main(int, char **) {58 f();59 return 0;60}61