1 //===-- RuntimeDyldCOFF.cpp - Run-time dynamic linker for MC-JIT -*- C++ -*-==//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Implementation of COFF support for the MC-JIT runtime dynamic linker.
11 //===----------------------------------------------------------------------===//
13 #include "RuntimeDyldCOFF.h"
14 #include "Targets/RuntimeDyldCOFFI386.h"
15 #include "Targets/RuntimeDyldCOFFThumb.h"
16 #include "Targets/RuntimeDyldCOFFX86_64.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Object/ObjectFile.h"
22 using namespace llvm::object
;
24 #define DEBUG_TYPE "dyld"
28 class LoadedCOFFObjectInfo final
29 : public LoadedObjectInfoHelper
<LoadedCOFFObjectInfo
,
30 RuntimeDyld::LoadedObjectInfo
> {
33 RuntimeDyldImpl
&RTDyld
,
34 RuntimeDyld::LoadedObjectInfo::ObjSectionToIDMap ObjSecToIDMap
)
35 : LoadedObjectInfoHelper(RTDyld
, std::move(ObjSecToIDMap
)) {}
37 OwningBinary
<ObjectFile
>
38 getObjectForDebug(const ObjectFile
&Obj
) const override
{
39 return OwningBinary
<ObjectFile
>();
46 std::unique_ptr
<RuntimeDyldCOFF
>
47 llvm::RuntimeDyldCOFF::create(Triple::ArchType Arch
,
48 RuntimeDyld::MemoryManager
&MemMgr
,
49 JITSymbolResolver
&Resolver
) {
51 default: llvm_unreachable("Unsupported target for RuntimeDyldCOFF.");
53 return std::make_unique
<RuntimeDyldCOFFI386
>(MemMgr
, Resolver
);
55 return std::make_unique
<RuntimeDyldCOFFThumb
>(MemMgr
, Resolver
);
57 return std::make_unique
<RuntimeDyldCOFFX86_64
>(MemMgr
, Resolver
);
61 std::unique_ptr
<RuntimeDyld::LoadedObjectInfo
>
62 RuntimeDyldCOFF::loadObject(const object::ObjectFile
&O
) {
63 if (auto ObjSectionToIDOrErr
= loadObjectImpl(O
)) {
64 return std::make_unique
<LoadedCOFFObjectInfo
>(*this, *ObjSectionToIDOrErr
);
67 raw_string_ostream
ErrStream(ErrorStr
);
68 logAllUnhandledErrors(ObjSectionToIDOrErr
.takeError(), ErrStream
);
73 uint64_t RuntimeDyldCOFF::getSymbolOffset(const SymbolRef
&Sym
) {
74 // The value in a relocatable COFF object is the offset.
75 return Sym
.getValue();
78 bool RuntimeDyldCOFF::isCompatibleFile(const object::ObjectFile
&Obj
) const {