blob: b4b5b354ae18e098b867ef6751d14488324f4047 [file] [log] [blame]
// Copyright 2025 The IREE Authors
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// Compile-time configuration for libbacktrace.
// Based on Bazel Central Registry's approach - no autotools needed.
// https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/libbacktrace
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdint.h>
// ELF word size detection.
#if UINTPTR_MAX == 0xffffffff
#define BACKTRACE_ELF_SIZE 32
#ifdef __i386__
#define HAVE_ATOMIC_FUNCTIONS 1
#define HAVE_SYNC_FUNCTIONS 1
#endif
#else
#if UINTPTR_MAX != 0xffffffffffffffffULL
#error bad elf word size!?
#endif
#define BACKTRACE_ELF_SIZE 64
#define HAVE_ATOMIC_FUNCTIONS 1
#define HAVE_SYNC_FUNCTIONS 1
#endif
// Platform detection.
#if defined __ELF__
// dl_iterate_phdr availability detected at CMake configure time.
// This allows proper cross-compilation support for embedded Linux targets
// where the libc may not provide this function (e.g., newlib, minimal uclibc).
@LIBBACKTRACE_DL_ITERATE_PHDR_DEF@
@LIBBACKTRACE_LINK_H_DEF@
// FreeBSD-specific features.
#if defined __has_include
#if __has_include(<sys/sysctl.h>)
#include <sys/sysctl.h>
#if defined KERN_PROC
#define HAVE_KERN_PROC 1
#endif
#if defined KERN_PROC_ARGS
#define HAVE_KERN_PROC_ARGS 1
#endif
#endif
#endif
#elif defined __MACH__
#define HAVE_MACH_O_DYLD_H 1
#else
#error This code only supports ELF (Linux) or Mach-O (macOS)
#endif
// Standard POSIX features available on Linux/macOS.
#define HAVE_FCNTL 1
#define HAVE_LSTAT 1
#define HAVE_MEMORY_H 1
#define HAVE_READLINK 1
#define HAVE_CLOCK_GETTIME 1
#define HAVE_DECL_GETPAGESIZE 1
#define HAVE_DECL_STRNLEN 1
#define HAVE_DECL__PGMPTR 0
#define HAVE_DLFCN_H 1
#define HAVE_GETIPINFO 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_SYS_MMAN_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_UNISTD_H 1