148 lines · c
1//===-- FuzzerPlatform.h --------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8// Common platform macros.9//===----------------------------------------------------------------------===//10 11#ifndef LLVM_FUZZER_PLATFORM_H12#define LLVM_FUZZER_PLATFORM_H13 14// Platform detection.15#ifdef __linux__16#define LIBFUZZER_APPLE 017#define LIBFUZZER_FUCHSIA 018#define LIBFUZZER_LINUX 119#define LIBFUZZER_NETBSD 020#define LIBFUZZER_FREEBSD 021#define LIBFUZZER_WINDOWS 022#define LIBFUZZER_EMSCRIPTEN 023#elif __APPLE__24#define LIBFUZZER_APPLE 125#define LIBFUZZER_FUCHSIA 026#define LIBFUZZER_LINUX 027#define LIBFUZZER_NETBSD 028#define LIBFUZZER_FREEBSD 029#define LIBFUZZER_WINDOWS 030#define LIBFUZZER_EMSCRIPTEN 031#elif __NetBSD__32#define LIBFUZZER_APPLE 033#define LIBFUZZER_FUCHSIA 034#define LIBFUZZER_LINUX 035#define LIBFUZZER_NETBSD 136#define LIBFUZZER_FREEBSD 037#define LIBFUZZER_WINDOWS 038#define LIBFUZZER_EMSCRIPTEN 039#elif __FreeBSD__40#define LIBFUZZER_APPLE 041#define LIBFUZZER_FUCHSIA 042#define LIBFUZZER_LINUX 043#define LIBFUZZER_NETBSD 044#define LIBFUZZER_FREEBSD 145#define LIBFUZZER_WINDOWS 046#define LIBFUZZER_EMSCRIPTEN 047#elif _WIN3248#define LIBFUZZER_APPLE 049#define LIBFUZZER_FUCHSIA 050#define LIBFUZZER_LINUX 051#define LIBFUZZER_NETBSD 052#define LIBFUZZER_FREEBSD 053#define LIBFUZZER_WINDOWS 154#define LIBFUZZER_EMSCRIPTEN 055#elif __Fuchsia__56#define LIBFUZZER_APPLE 057#define LIBFUZZER_FUCHSIA 158#define LIBFUZZER_LINUX 059#define LIBFUZZER_NETBSD 060#define LIBFUZZER_FREEBSD 061#define LIBFUZZER_WINDOWS 062#define LIBFUZZER_EMSCRIPTEN 063#elif __EMSCRIPTEN__64#define LIBFUZZER_APPLE 065#define LIBFUZZER_FUCHSIA 066#define LIBFUZZER_LINUX 067#define LIBFUZZER_NETBSD 068#define LIBFUZZER_FREEBSD 069#define LIBFUZZER_WINDOWS 070#define LIBFUZZER_EMSCRIPTEN 171#else72#error "Support for your platform has not been implemented"73#endif74 75#if defined(_MSC_VER) && !defined(__clang__)76// MSVC compiler is being used.77#define LIBFUZZER_MSVC 178#else79#define LIBFUZZER_MSVC 080#endif81 82#ifndef __has_attribute83#define __has_attribute(x) 084#endif85 86#define LIBFUZZER_POSIX \87 (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD || \88 LIBFUZZER_FREEBSD || LIBFUZZER_EMSCRIPTEN)89 90#ifdef __x86_6491#if __has_attribute(target)92#define ATTRIBUTE_TARGET_POPCNT __attribute__((target("popcnt")))93#else94#define ATTRIBUTE_TARGET_POPCNT95#endif96#else97#define ATTRIBUTE_TARGET_POPCNT98#endif99 100#ifdef __clang__ // avoid gcc warning.101#if __has_attribute(no_sanitize)102#define ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))103#else104#define ATTRIBUTE_NO_SANITIZE_MEMORY105#endif106#define ALWAYS_INLINE __attribute__((always_inline))107#else108#define ATTRIBUTE_NO_SANITIZE_MEMORY109#define ALWAYS_INLINE110#endif // __clang__111 112#if LIBFUZZER_WINDOWS113#define ATTRIBUTE_NO_SANITIZE_ADDRESS114#else115#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))116#endif117 118#if LIBFUZZER_WINDOWS119#define ATTRIBUTE_ALIGNED(X) __declspec(align(X))120#define ATTRIBUTE_INTERFACE __declspec(dllexport)121// This is used for __sancov_lowest_stack which is needed for122// -fsanitize-coverage=stack-depth. That feature is not yet available on123// Windows, so make the symbol static to avoid linking errors.124#define ATTRIBUTES_INTERFACE_TLS_INITIAL_EXEC static125#define ATTRIBUTE_NOINLINE __declspec(noinline)126#else127#define ATTRIBUTE_ALIGNED(X) __attribute__((aligned(X)))128#define ATTRIBUTE_INTERFACE __attribute__((visibility("default")))129#define ATTRIBUTES_INTERFACE_TLS_INITIAL_EXEC \130 ATTRIBUTE_INTERFACE __attribute__((tls_model("initial-exec"))) thread_local131 132#define ATTRIBUTE_NOINLINE __attribute__((noinline))133#endif134 135#if defined(__has_feature)136#if __has_feature(address_sanitizer)137#define ATTRIBUTE_NO_SANITIZE_ALL ATTRIBUTE_NO_SANITIZE_ADDRESS138#elif __has_feature(memory_sanitizer)139#define ATTRIBUTE_NO_SANITIZE_ALL ATTRIBUTE_NO_SANITIZE_MEMORY140#else141#define ATTRIBUTE_NO_SANITIZE_ALL142#endif143#else144#define ATTRIBUTE_NO_SANITIZE_ALL145#endif146 147#endif // LLVM_FUZZER_PLATFORM_H148