## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates symbols that were recently added to LLVM without proper annotations. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). ## Overview The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS: - Add `LLVM_EXPORT_TEMPLATE` and `LLVM_TEMPLATE_ABI` annotations to explicitly instantiated instances of `llvm::object::SFrameParser`. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
57 lines
2.0 KiB
C++
57 lines
2.0 KiB
C++
//===- SFrameParser.cpp ---------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Object/SFrameParser.h"
|
|
#include "llvm/BinaryFormat/SFrame.h"
|
|
#include "llvm/Object/Error.h"
|
|
#include "llvm/Support/FormatVariadic.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::object;
|
|
|
|
template <typename T>
|
|
static Expected<const T &> getDataSliceAs(ArrayRef<uint8_t> Data,
|
|
uint64_t Offset) {
|
|
static_assert(std::is_trivial_v<T>);
|
|
if (Data.size() < Offset + sizeof(T)) {
|
|
return createStringError(
|
|
formatv("unexpected end of data at offset {0:x} while reading [{1:x}, "
|
|
"{2:x})",
|
|
Data.size(), Offset, Offset + sizeof(T))
|
|
.str(),
|
|
object_error::unexpected_eof);
|
|
}
|
|
return *reinterpret_cast<const T *>(Data.data() + Offset);
|
|
}
|
|
|
|
template <endianness E>
|
|
Expected<SFrameParser<E>> SFrameParser<E>::create(ArrayRef<uint8_t> Contents) {
|
|
Expected<const sframe::Preamble<E> &> Preamble =
|
|
getDataSliceAs<sframe::Preamble<E>>(Contents, 0);
|
|
if (!Preamble)
|
|
return Preamble.takeError();
|
|
|
|
if (Preamble->Magic != sframe::Magic)
|
|
return createError(
|
|
formatv("invalid magic number ({0:x+4})", Preamble->Magic.value()));
|
|
if (Preamble->Version != sframe::Version::V2)
|
|
return createError(
|
|
formatv("invalid/unsupported version number ({0})",
|
|
static_cast<unsigned>(Preamble->Version.value())));
|
|
|
|
Expected<const sframe::Header<E> &> Header =
|
|
getDataSliceAs<sframe::Header<E>>(Contents, 0);
|
|
if (!Header)
|
|
return Header.takeError();
|
|
return SFrameParser(Contents, *Header);
|
|
}
|
|
|
|
template class LLVM_EXPORT_TEMPLATE llvm::object::SFrameParser<endianness::big>;
|
|
template class LLVM_EXPORT_TEMPLATE
|
|
llvm::object::SFrameParser<endianness::little>;
|