Path: blob/main/contrib/llvm-project/compiler-rt/lib/fuzzer/FuzzerPlatform.h
35262 views
//===-- FuzzerPlatform.h --------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7// Common platform macros.8//===----------------------------------------------------------------------===//910#ifndef LLVM_FUZZER_PLATFORM_H11#define LLVM_FUZZER_PLATFORM_H1213// Platform detection.14#ifdef __linux__15#define LIBFUZZER_APPLE 016#define LIBFUZZER_FUCHSIA 017#define LIBFUZZER_LINUX 118#define LIBFUZZER_NETBSD 019#define LIBFUZZER_FREEBSD 020#define LIBFUZZER_WINDOWS 021#define LIBFUZZER_EMSCRIPTEN 022#elif __APPLE__23#define LIBFUZZER_APPLE 124#define LIBFUZZER_FUCHSIA 025#define LIBFUZZER_LINUX 026#define LIBFUZZER_NETBSD 027#define LIBFUZZER_FREEBSD 028#define LIBFUZZER_WINDOWS 029#define LIBFUZZER_EMSCRIPTEN 030#elif __NetBSD__31#define LIBFUZZER_APPLE 032#define LIBFUZZER_FUCHSIA 033#define LIBFUZZER_LINUX 034#define LIBFUZZER_NETBSD 135#define LIBFUZZER_FREEBSD 036#define LIBFUZZER_WINDOWS 037#define LIBFUZZER_EMSCRIPTEN 038#elif __FreeBSD__39#define LIBFUZZER_APPLE 040#define LIBFUZZER_FUCHSIA 041#define LIBFUZZER_LINUX 042#define LIBFUZZER_NETBSD 043#define LIBFUZZER_FREEBSD 144#define LIBFUZZER_WINDOWS 045#define LIBFUZZER_EMSCRIPTEN 046#elif _WIN3247#define LIBFUZZER_APPLE 048#define LIBFUZZER_FUCHSIA 049#define LIBFUZZER_LINUX 050#define LIBFUZZER_NETBSD 051#define LIBFUZZER_FREEBSD 052#define LIBFUZZER_WINDOWS 153#define LIBFUZZER_EMSCRIPTEN 054#elif __Fuchsia__55#define LIBFUZZER_APPLE 056#define LIBFUZZER_FUCHSIA 157#define LIBFUZZER_LINUX 058#define LIBFUZZER_NETBSD 059#define LIBFUZZER_FREEBSD 060#define LIBFUZZER_WINDOWS 061#define LIBFUZZER_EMSCRIPTEN 062#elif __EMSCRIPTEN__63#define LIBFUZZER_APPLE 064#define LIBFUZZER_FUCHSIA 065#define LIBFUZZER_LINUX 066#define LIBFUZZER_NETBSD 067#define LIBFUZZER_FREEBSD 068#define LIBFUZZER_WINDOWS 069#define LIBFUZZER_EMSCRIPTEN 170#else71#error "Support for your platform has not been implemented"72#endif7374#if defined(_MSC_VER) && !defined(__clang__)75// MSVC compiler is being used.76#define LIBFUZZER_MSVC 177#else78#define LIBFUZZER_MSVC 079#endif8081#ifndef __has_attribute82#define __has_attribute(x) 083#endif8485#define LIBFUZZER_POSIX \86(LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD || \87LIBFUZZER_FREEBSD || LIBFUZZER_EMSCRIPTEN)8889#if defined(__x86_64) && defined(__POPCNT__)90#if __has_attribute(target)91#define ATTRIBUTE_TARGET_POPCNT __attribute__((target("popcnt")))92#else93#define ATTRIBUTE_TARGET_POPCNT94#endif95#else96#define ATTRIBUTE_TARGET_POPCNT97#endif9899#ifdef __clang__ // avoid gcc warning.100#if __has_attribute(no_sanitize)101#define ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))102#else103#define ATTRIBUTE_NO_SANITIZE_MEMORY104#endif105#define ALWAYS_INLINE __attribute__((always_inline))106#else107#define ATTRIBUTE_NO_SANITIZE_MEMORY108#define ALWAYS_INLINE109#endif // __clang__110111#if LIBFUZZER_WINDOWS112#define ATTRIBUTE_NO_SANITIZE_ADDRESS113#else114#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))115#endif116117#if LIBFUZZER_WINDOWS118#define ATTRIBUTE_ALIGNED(X) __declspec(align(X))119#define ATTRIBUTE_INTERFACE __declspec(dllexport)120// This is used for __sancov_lowest_stack which is needed for121// -fsanitize-coverage=stack-depth. That feature is not yet available on122// Windows, so make the symbol static to avoid linking errors.123#define ATTRIBUTES_INTERFACE_TLS_INITIAL_EXEC static124#define ATTRIBUTE_NOINLINE __declspec(noinline)125#else126#define ATTRIBUTE_ALIGNED(X) __attribute__((aligned(X)))127#define ATTRIBUTE_INTERFACE __attribute__((visibility("default")))128#define ATTRIBUTES_INTERFACE_TLS_INITIAL_EXEC \129ATTRIBUTE_INTERFACE __attribute__((tls_model("initial-exec"))) thread_local130131#define ATTRIBUTE_NOINLINE __attribute__((noinline))132#endif133134#if defined(__has_feature)135#if __has_feature(address_sanitizer)136#define ATTRIBUTE_NO_SANITIZE_ALL ATTRIBUTE_NO_SANITIZE_ADDRESS137#elif __has_feature(memory_sanitizer)138#define ATTRIBUTE_NO_SANITIZE_ALL ATTRIBUTE_NO_SANITIZE_MEMORY139#else140#define ATTRIBUTE_NO_SANITIZE_ALL141#endif142#else143#define ATTRIBUTE_NO_SANITIZE_ALL144#endif145146#endif // LLVM_FUZZER_PLATFORM_H147148149