template <class ElfLayout, template <typename> class Container, PhdrLoadPolicy Policy = PhdrLoadPolicy::kBasic, template <class SegmentType> class SegmentWrapper = NoSegmentWrapper>

class LoadInfo

Defined at line 262 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

This constructs *Segment by copying from a segment of the corresponding

*Segment type possibly from some different LoadInfo

<

...> instantiation. In

the default case, this is no different from copy construction. But a

segment subclass must override this with its own Copy method that also

copies its additional state. Copying can fail, using the Diagnostics object

and returning the fit::error

<bool

> of whatever its *Error calls return.

The CopyFrom method copies each segment that way to initialize the object

from any other LoadInfo

<

...> instantiation whose segments are accepted by

copied-to the SegmentWrapper types' Copy methods. That could be just its

own types that are move-only but can be copied with costlier work that might

fail, or it could be a different compatible SegmentWrapper. The default

*Segment::Copy functions will accept any corresponding segment type but will

just ignore any extra state added by the other SegmentWrapper.

The GetPhdrObserver method is used with elfldltl::DecodePhdrs (see phdr.h)

to call AddSegment, which can also be called directly with a valid sequence

of PT_LOAD segments.

The RelroBounds function returns the normalized [start, end) of RELRO so

protection can be applied there. The returned LoadInfo::Region object also

has size() and empty() for convenience.

The ApplyRelro method uses this to adjust the segments for uses where

relocation precedes loading, after all segments have been added.

After adjustment, VisitSegments can be used to iterate over segments()

using std::visit.

Public Methods

template <class Diagnostics, template <typename> class OtherContainer, PhdrLoadPolicy OtherPolicy, template <class> class OtherWrapper>
bool CopyFrom (Diagnostics & diag, const LoadInfo<Elf, OtherContainer, OtherPolicy, OtherWrapper> & other)

The remaining template parameters are deduced from the

LoadInfo

<

...> instantiation of the argument, which could differ.

Defined at line 299 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

Container<Segment> & segments ()

Defined at line 323 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

const Container<Segment> & segments ()

Defined at line 324 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

size_type vaddr_start ()

Defined at line 326 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

size_type vaddr_size ()

Defined at line 328 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

bool contains_vaddr_range (size_type vaddr, size_type len)

Defined at line 330 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Diagnostics>
bool AddSegment (Diagnostics & diagnostics, size_type page_size, const Phdr & phdr, bool merge)

Add a PT_LOAD segment. Merge with the preceding segment if they are

adjacent and compatible, unless merge=false.

Defined at line 338 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Diagnostics, class NewSegment>
bool AddSegment (Diagnostics & diagnostics, NewSegment new_segment, bool merge)

Add a Segment or *Segment object already constructed.

Defined at line 365 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

auto GetPhdrObserver (size_type page_size, bool merge)

Get an ephemeral object to pass to elfldltl::DecodePhdrs. The returned

observer object must not outlive this LoadInfo object. The optional

merge=false argument prevents merging adjacent segments that are

apparently compatible. This can be avoided if it will be done later after

possibly changing segments' mergeability, as when ApplyRelro is used.

Defined at line 386 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

Segment RemoveLastSegment ()

Defined at line 393 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <typename T>
bool VisitSegments (T && visitor)

Iterate over segments() by calling std::visit(visitor, segment).

Return false the first time the visitor returns false.

Defined at line 404 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <typename T>
bool VisitSegments (T && visitor)

Defined at line 409 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <typename T>
bool VisitSegment (T && visitor, const Segment & segment)

Defined at line 414 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <typename T>
bool VisitSegment (T && visitor, const Segment & segment)

Defined at line 414 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

typename Container<Segment>::const_iterator FindSegment (size_type vaddr)

Defined at line 418 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

Region RelroBounds (const std::optional<Phdr> & relro, size_type page_size)

When loading before relocation, the RelroBounds() region can just be made

read-only in memory after relocation. Partial pages in the RELRO region are

excluded from RelroBounds, as protections can only be applied per-page.

TODO(https://fxbug.dev/42074388): Address the discrepancy between our round-up behavior and

glibc's round-down behavior for RELRO start.

Defined at line 444 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

Region RelroBounds (const std::optional<Phdr> & relro, size_type page_size)

When loading before relocation, the RelroBounds() region can just be made

read-only in memory after relocation. Partial pages in the RELRO region are

excluded from RelroBounds, as protections can only be applied per-page.

TODO(https://fxbug.dev/42074388): Address the discrepancy between our round-up behavior and

glibc's round-down behavior for RELRO start.

Defined at line 444 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Diagnostics>
bool ApplyRelro (Diagnostics & diagnostics, const std::optional<Phdr> & relro, size_type page_size, bool merge_ro)

Apply RELRO for loading after relocation, adjusting the segments to

promote RELRO to read-only. If the merge_ro flag is true, then the RELRO

segment can be merged with an adjacent true read-only segment. This is

appropriate if relocations have been applied in place to the same image;

whether merged or not, the RELRO segment will be part of a ConstantSegment

with relro() false. If already-relocated segments are stored separately

from true read-only segments (such as in a COW mirror of the original

portion of the file), the RELRO segment instead becomes a ConstantSegment

with relro() true.

Defined at line 466 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Diagnostics>
bool ApplyRelro (Diagnostics & diagnostics, const std::optional<Phdr> & relro, size_type page_size, bool merge_ro)

Apply RELRO for loading after relocation, adjusting the segments to

promote RELRO to read-only. If the merge_ro flag is true, then the RELRO

segment can be merged with an adjacent true read-only segment. This is

appropriate if relocations have been applied in place to the same image;

whether merged or not, the RELRO segment will be part of a ConstantSegment

with relro() false. If already-relocated segments are stored separately

from true read-only segments (such as in a COW mirror of the original

portion of the file), the RELRO segment instead becomes a ConstantSegment

with relro() true.

Defined at line 466 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Writer>
Writer & SymbolizerContext (Writer & writer, unsigned int id, std::string_view name, std::span<const std::byte> build_id, size_type load_address, std::string_view prefix)

This uses the symbolizer_markup::Writer API to emit the contextual

elements describing this ELF module. The ID number should be unique among

modules in the same address space, i.e. since the last Reset() in the same

markup output stream.

Defined at line 529 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Writer>
Writer & SymbolizerContext (Writer & writer, unsigned int id, std::string_view name, std::span<const std::byte> build_id, size_type load_address, std::string_view prefix)

This uses the symbolizer_markup::Writer API to emit the contextual

elements describing this ELF module. The ID number should be unique among

modules in the same address space, i.e. since the last Reset() in the same

markup output stream.

Defined at line 529 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Writer>
Writer & SymbolizerContext (Writer & writer, unsigned int id, std::string_view name, std::span<const std::byte> build_id, size_type load_address, std::string_view prefix)

This uses the symbolizer_markup::Writer API to emit the contextual

elements describing this ELF module. The ID number should be unique among

modules in the same address space, i.e. since the last Reset() in the same

markup output stream.

Defined at line 529 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Writer>
Writer & SymbolizerContext (Writer & writer, unsigned int id, std::string_view name, std::span<const std::byte> build_id, size_type load_address, std::string_view prefix)

This uses the symbolizer_markup::Writer API to emit the contextual

elements describing this ELF module. The ID number should be unique among

modules in the same address space, i.e. since the last Reset() in the same

markup output stream.

Defined at line 529 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

template <class Writer>
Writer & SymbolizerContext (Writer & writer, unsigned int id, std::string_view name, std::span<const std::byte> build_id, size_type load_address, std::string_view prefix)

This uses the symbolizer_markup::Writer API to emit the contextual

elements describing this ELF module. The ID number should be unique among

modules in the same address space, i.e. since the last Reset() in the same

markup output stream.

Defined at line 529 of file ../../src/lib/elfldltl/include/lib/elfldltl/load.h

Records