template <typename DecodedStorage>

class LoadModule

Defined at line 44 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

The ld::LoadModule template class provides a base class for a

information about a given ELF file's use in a particular dynamic linking

scenario. This includes things like its name and runtime load bias.

The template parameter can either be a ld::DecodedModule

<

...> instantiation

or subclass of one, or it can be some pointer-like type that can be

dereferenced with `*` to get to one. That can be a plain pointer, a pointer

to `const`, a smart pointer type of some kind, or even something like

`std::optional`.

This provides proxy methods for read-only access to the object derived from

ld::DecodedModule. The ld::LoadModule object itself holds little more than

the module name. A mutable decoded module object can be modified via the

`decoded()` accessor.

Public Members

static const bool kMutableDecoded

Public Methods

void LoadModule<DecodedStorage> ()

Defined at line 94 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void LoadModule<DecodedStorage> (const LoadModule<DecodedStorage> & )

Defined at line 96 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void LoadModule<DecodedStorage> (LoadModule<DecodedStorage> && )

Defined at line 98 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void LoadModule<DecodedStorage> (std::string_view name)

The LoadModule is initially constructed just with a name, which is what

will eventually appear in Module::link_map::name. This is the name by

which the module is initially found (in the filesystem or whatever).

When the object has a DT_SONAME (Module::soname), this is usually the

same; but nothing guarantees that.

Defined at line 105 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void LoadModule<DecodedStorage> (const Soname & name)

Defined at line 106 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

LoadModule<DecodedStorage> & operator= (LoadModule<DecodedStorage> && )

Defined at line 108 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

const Soname & name ()

Defined at line 110 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void set_name (const Soname & name)

Defined at line 112 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void set_name (std::string_view name)

Defined at line 116 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void set_decoded (DecodedStorage decoded)

If the template parameter is pointer-like, then HasDecoded() is initially

false and this must be used to install a pointer.

Defined at line 123 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

bool operator== (const Soname & name)

For convenient container searches, equality comparison against a (hashed)

name checks both name fields. An unloaded module only has a load name.

A loaded module may also have a SONAME.

Defined at line 131 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

Ref name_ref ()

This returns an object that can be used like a LoadModule* pointing at

this, but is suitable for use in a container like std::unordered_set or

fbl::HashTable keyed by name().

Defined at line 138 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

Ref soname_ref ()

This returns an object that can be used like a LoadModule* pointing at

this, but is suitable for use in a container like std::unordered_set or

fbl::HashTable keyed by soname().

Defined at line 143 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

size_type static_tls_bias ()

This returns the offset from the thread pointer to this module's static

TLS block if it has one. The value is assigned by AssignStaticTls, below.

This method should not be called unless AssignStaticTls has been called.

Defined at line 148 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

template <elfldltl::ElfMachine Machine = elfldltl::ElfMachine::kNative, size_type RedZone = 0>
bool AssignStaticTls (elfldltl::TlsLayout<Elf> & tls_layout)

Use ths TlsLayout object to assign a static TLS offset for this module's

PT_TLS segment, if it has one. SetTls() has already been called if it

will be. This returns false if there was no PT_TLS segment. If it

returns true, then the .tls_module() and .static_tls_bias() should go into

the Abi array fields at the the index TLS module ID - 1. If Decoded is

const, then the module ID is not available directly in this class and a

subclass tls_module_id() definition must be used to fetch it.

Defined at line 158 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

bool HasDecoded ()

This returns true if it's safe to call the decoded() method. This is

always true if the template parameter is a DecodedModule type itself.

If it's instead some pointer-like type, then this can return false

before the pointer has been installed.

TODO(https://fxbug.dev/326524302): There is not yet any way to install it!

Defined at line 182 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

Decoded & decoded ()

Access the underlying DecodedModule object. This must not be called if

HasDecoded() returns false. There are both const and mutable overloads

for this. But note that Decoded might be a const type itself when the

template parameter is a pointer-like type, in which case decoded() always

returns a const reference even when called on a mutable LoadModule.

Defined at line 195 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

const Decoded & decoded ()

Defined at line 196 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

template <typename... Args, bool CanEmplace = Decoded::kModuleInline && kMutableDecoded, typename = std::enable_if_t<CanEmplace>>
void EmplaceModule (uint32_t modid, Args &&... args)

When Decoded is mutable and uses AbiModuleInline::kYes, EmplaceModule(..)

just constructs Module{...}).

Defined at line 202 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

template <typename... Args, bool CanNew = !Decoded::kModuleInline && kMutableDecoded, typename = std::enable_if_t<CanNew>>
void NewModule (uint32_t modid, Args &&... args)

When Decoded is mutable and uses AbiModuleInline::kNo, then calling

NewModule(a..., c...) does new (a...) Module{c...}. The last argument in

a... must be a fbl::AllocChecker that indicates whether `new` succeeded.

Defined at line 212 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

bool HasModule ()

The following methods are simple proxies for the same method on decoded().

Note only const overloads are provided here, for reading information from

the DecodedModule to use in loading and dynamic linking. For filling in

the information from the file in the first place, use decoded() for the

mutable reference.

Defined at line 223 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

const Module & module ()

Defined at line 225 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

const Soname & soname ()

Defined at line 227 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

const LoadInfo & load_info ()

Defined at line 229 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

template <bool RI = Decoded::kRelocInfo, typename = std::enable_if_t<RI>>
const RelocationInfo & reloc_info ()

Defined at line 232 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

const TlsModule & tls_module ()

Defined at line 236 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

const auto & symbol_info ()

The following methods satisfy the Module template API for use with

elfldltl::ResolverDefinition (see

<lib

/elfldltl/resolve.h>).

Defined at line 241 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

template <bool M = kMutableDecoded, typename = std::enable_if_t<M>>
size_type load_bias ()

This is only provided when Decoded is mutable. In that case, after

decoding and choosing load address, module() will be updated via

ld::SetModuleVaddrBounds. In other cases, a derived class must implement

load_bias() itself.

Defined at line 248 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

bool uses_static_tls ()

Defined at line 252 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

template <bool M = kMutableDecoded, typename = std::enable_if_t<M>>
size_type tls_module_id ()

This is only provided when Decoded is mutable. In that case, SetTls

installs the actual TLS module ID and this will return it. When Decoded

is const, then SetTls will be called with the placeholder TLS module ID 1

just so that it's nonzero to indicate the module has a PT_TLS at all. The

derived class must define tls_module_id() itself to return the real TLS

module ID it assigns and stores elsewhere.

Defined at line 261 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

template <auto& diag>
LookupResult Lookup (auto & diag, elfldltl::SymbolName & name)

This can be overridden in a subclass for custom semantics.

Defined at line 266 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

Protected Methods

auto & decoded_storage ()

Defined at line 271 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

auto & decoded_storage ()

Defined at line 272 of file ../../sdk/lib/ld/include/lib/ld/load-module.h

void SetAbiName ()

Defined at line 274 of file ../../sdk/lib/ld/include/lib/ld/load-module.h