llvm-project/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCheckerImpl.h
Stefan Gränitz 6a433d77b1
[llvm-jitlink] Allow optional stub-kind filter in stub_addr() expressions (#78369)
We use `jitlink-check` lines in LIT tests as the primary tool for
testing JITLink backends. Parsing and evaluation of the expressions is
implemented in `RuntimeDyldChecker`. The `stub_addr(obj, name)`
expression allows to obtain the linker-generated stub for the external
symbol `name` in object file `obj`.

This patch adds support for a filter parameter to select one out of many
stubs. This is necessary for the AArch32 JITLink backend, which must be
able to emit two different kinds of stubs depending on the instruction
set state (Arm/Thumb) of the relocation site. Since the new parameter is
optional, we don't have to update existing tests.

Filters are regular expressions without brackets that match exactly one
existing stub. Given object file `armv7.o` with two stubs for external
function `ext` of kinds `armv7_abs_le` and `thumbv7_abs_le`, we get the
following filter results e.g.:
```
stub_addr(armv7.o, ext, thumb)        thumbv7_abs_le
stub_addr(armv7.o, ext, thumbv7)      thumbv7_abs_le
stub_addr(armv7.o, ext, armv7_abs_le) armv7_abs_le
stub_addr(armv7.o, ext, v7_.*_le)     Error: "ext" has 2 candidate stubs in file "armv7.o". Please refine stub-kind filter "v7_.*_le" for disambiguation (encountered kinds are "thumbv7_abs_le", "armv7_abs_le").
stub_addr(armv7.o, ext, v8)           Error: "ext" has 2 stubs in file "armv7.o", but none of them matches the stub-kind filter "v8" (all encountered kinds are "thumbv7_abs_le", "armv7_abs_le").
```
2024-01-20 09:57:03 +01:00

86 lines
3.1 KiB
C++

//===-- RuntimeDyldCheckerImpl.h -- RuntimeDyld test framework --*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDCHECKERIMPL_H
#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDCHECKERIMPL_H
#include "RuntimeDyldImpl.h"
namespace llvm {
/// Holds target-specific properties for a symbol.
using TargetFlagsType = uint8_t;
class RuntimeDyldCheckerImpl {
friend class RuntimeDyldChecker;
friend class RuntimeDyldCheckerExprEval;
using IsSymbolValidFunction =
RuntimeDyldChecker::IsSymbolValidFunction;
using GetSymbolInfoFunction = RuntimeDyldChecker::GetSymbolInfoFunction;
using GetSectionInfoFunction = RuntimeDyldChecker::GetSectionInfoFunction;
using GetStubInfoFunction = RuntimeDyldChecker::GetStubInfoFunction;
using GetGOTInfoFunction = RuntimeDyldChecker::GetGOTInfoFunction;
public:
RuntimeDyldCheckerImpl(IsSymbolValidFunction IsSymbolValid,
GetSymbolInfoFunction GetSymbolInfo,
GetSectionInfoFunction GetSectionInfo,
GetStubInfoFunction GetStubInfo,
GetGOTInfoFunction GetGOTInfo,
llvm::endianness Endianness, Triple TT, StringRef CPU,
SubtargetFeatures TF, llvm::raw_ostream &ErrStream);
bool check(StringRef CheckExpr) const;
bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
private:
// StubMap typedefs.
Expected<JITSymbolResolver::LookupResult>
lookup(const JITSymbolResolver::LookupSet &Symbols) const;
bool isSymbolValid(StringRef Symbol) const;
uint64_t getSymbolLocalAddr(StringRef Symbol) const;
uint64_t getSymbolRemoteAddr(StringRef Symbol) const;
uint64_t readMemoryAtAddr(uint64_t Addr, unsigned Size) const;
StringRef getSymbolContent(StringRef Symbol) const;
TargetFlagsType getTargetFlag(StringRef Symbol) const;
Triple getTripleForSymbol(TargetFlagsType Flag) const;
StringRef getCPU() const { return CPU; }
SubtargetFeatures getFeatures() const { return TF; }
std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
StringRef SectionName,
bool IsInsideLoad) const;
std::pair<uint64_t, std::string>
getStubOrGOTAddrFor(StringRef StubContainerName, StringRef Symbol,
StringRef StubKindFilter, bool IsInsideLoad,
bool IsStubAddr) const;
std::optional<uint64_t> getSectionLoadAddress(void *LocalAddr) const;
IsSymbolValidFunction IsSymbolValid;
GetSymbolInfoFunction GetSymbolInfo;
GetSectionInfoFunction GetSectionInfo;
GetStubInfoFunction GetStubInfo;
GetGOTInfoFunction GetGOTInfo;
llvm::endianness Endianness;
Triple TT;
std::string CPU;
SubtargetFeatures TF;
llvm::raw_ostream &ErrStream;
};
}
#endif