Path: blob/main/contrib/llvm-project/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp
35262 views
//===- FuzzerExtFunctionsWeak.cpp - Interface to external functions -------===//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// Implementation for Linux. This relies on the linker's support for weak8// symbols. We don't use this approach on Apple platforms because it requires9// clients of LibFuzzer to pass ``-U _<symbol_name>`` to the linker to allow10// weak symbols to be undefined. That is a complication we don't want to expose11// to clients right now.12//===----------------------------------------------------------------------===//13#include "FuzzerPlatform.h"14#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUCHSIA || \15LIBFUZZER_FREEBSD || LIBFUZZER_EMSCRIPTEN1617#include "FuzzerExtFunctions.h"18#include "FuzzerIO.h"1920extern "C" {21// Declare these symbols as weak to allow them to be optionally defined.22#define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \23__attribute__((weak, visibility("default"))) RETURN_TYPE NAME FUNC_SIG2425#include "FuzzerExtFunctions.def"2627#undef EXT_FUNC28}2930using namespace fuzzer;3132static void CheckFnPtr(void *FnPtr, const char *FnName, bool WarnIfMissing) {33if (FnPtr == nullptr && WarnIfMissing) {34Printf("WARNING: Failed to find function \"%s\".\n", FnName);35}36}3738namespace fuzzer {3940ExternalFunctions::ExternalFunctions() {41#define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \42this->NAME = ::NAME; \43CheckFnPtr(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(::NAME)), \44#NAME, WARN);4546#include "FuzzerExtFunctions.def"4748#undef EXT_FUNC49}5051} // namespace fuzzer5253#endif545556