CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
110 lines
3.8 KiB
C++
110 lines
3.8 KiB
C++
//===-- COFFLinkGraphTests.cpp - Unit tests for COFF LinkGraph utils ------===//
|
|
//
|
|
// 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 "JITLinkTestUtils.h"
|
|
|
|
#include "llvm/ExecutionEngine/JITLink/COFF.h"
|
|
#include "llvm/ExecutionEngine/JITLink/JITLink.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::jitlink;
|
|
|
|
TEST(COFFLinkGraphTest, GetImageBaseSymbolReturnsNullWhenMissing) {
|
|
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
|
|
Triple("x86_64-pc-windows-msvc"), SubtargetFeatures(),
|
|
getGenericEdgeKindName);
|
|
|
|
GetImageBaseSymbol GetIB;
|
|
EXPECT_EQ(GetIB(G), nullptr);
|
|
}
|
|
|
|
TEST(COFFLinkGraphTest, GetImageBaseSymbolFindsExternal) {
|
|
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
|
|
Triple("x86_64-pc-windows-msvc"), SubtargetFeatures(),
|
|
getGenericEdgeKindName);
|
|
|
|
auto &ExtSym = G.addExternalSymbol(G.intern("__ImageBase"), 0, false);
|
|
GetImageBaseSymbol GetIB;
|
|
EXPECT_EQ(GetIB(G), &ExtSym);
|
|
}
|
|
|
|
TEST(COFFLinkGraphTest, GetImageBaseSymbolFindsAbsolute) {
|
|
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
|
|
Triple("x86_64-pc-windows-msvc"), SubtargetFeatures(),
|
|
getGenericEdgeKindName);
|
|
|
|
auto &AbsSym =
|
|
G.addAbsoluteSymbol(G.intern("__ImageBase"), orc::ExecutorAddr(0x1000), 0,
|
|
Linkage::Strong, Scope::Default, true);
|
|
GetImageBaseSymbol GetIB;
|
|
EXPECT_EQ(GetIB(G), &AbsSym);
|
|
}
|
|
|
|
TEST(COFFLinkGraphTest, GetImageBaseSymbolFindsDefined) {
|
|
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
|
|
Triple("x86_64-pc-windows-msvc"), SubtargetFeatures(),
|
|
getGenericEdgeKindName);
|
|
|
|
auto &Sec =
|
|
G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
|
|
auto &B =
|
|
G.createContentBlock(Sec, BlockContent, orc::ExecutorAddr(0x2000), 8, 0);
|
|
auto &DefSym =
|
|
G.addDefinedSymbol(B, 0, G.intern("__ImageBase"), 4, Linkage::Strong,
|
|
Scope::Default, false, false);
|
|
GetImageBaseSymbol GetIB;
|
|
EXPECT_EQ(GetIB(G), &DefSym);
|
|
}
|
|
|
|
TEST(COFFLinkGraphTest, GetImageBaseSymbolCachesResult) {
|
|
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
|
|
Triple("x86_64-pc-windows-msvc"), SubtargetFeatures(),
|
|
getGenericEdgeKindName);
|
|
|
|
auto &ExtSym = G.addExternalSymbol(G.intern("__ImageBase"), 0, false);
|
|
GetImageBaseSymbol GetIB;
|
|
EXPECT_EQ(GetIB(G), &ExtSym);
|
|
|
|
// Remove the symbol -- cached result should still be returned.
|
|
G.removeExternalSymbol(ExtSym);
|
|
EXPECT_EQ(GetIB(G), &ExtSym);
|
|
}
|
|
|
|
TEST(COFFLinkGraphTest, GetImageBaseSymbolReset) {
|
|
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
|
|
Triple("x86_64-pc-windows-msvc"), SubtargetFeatures(),
|
|
getGenericEdgeKindName);
|
|
|
|
GetImageBaseSymbol GetIB;
|
|
EXPECT_EQ(GetIB(G), nullptr);
|
|
|
|
// Add a symbol and reset -- should now find it.
|
|
auto &ExtSym = G.addExternalSymbol(G.intern("__ImageBase"), 0, false);
|
|
GetIB.reset();
|
|
EXPECT_EQ(GetIB(G), &ExtSym);
|
|
|
|
// Reset with an explicit cache value of nullptr -- should return nullptr
|
|
// without searching.
|
|
GetIB.reset(nullptr);
|
|
EXPECT_EQ(GetIB(G), nullptr);
|
|
}
|
|
|
|
TEST(COFFLinkGraphTest, GetImageBaseSymbolCustomName) {
|
|
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
|
|
Triple("x86_64-pc-windows-msvc"), SubtargetFeatures(),
|
|
getGenericEdgeKindName);
|
|
|
|
G.addExternalSymbol(G.intern("__ImageBase"), 0, false);
|
|
auto &CustomSym = G.addExternalSymbol(G.intern("__CustomBase"), 0, false);
|
|
|
|
GetImageBaseSymbol GetIB("__CustomBase");
|
|
EXPECT_EQ(GetIB(G), &CustomSym);
|
|
}
|