pw_elf#
ELF file support
Experimental C++17
pw_elf
provides support for interact with Executable and Linkable Format
(ELF) files.
Note
This module is currently very limited, primarily supporting other Pigweed modules. Additional functionality (e.g. iterating sections, segments) may be added in the future.
Guides#
Read an ELF section into a buffer#
1#include "pw_elf/reader.h"
2
3#include <vector>
4
5#include "pw_status/try.h"
6#include "pw_stream/std_file_stream.h"
7
8pw::Status ReaderExample() {
9 // Open a file stream for the ELF image.
10 pw::stream::StdFileReader stream("/tmp/example.elf");
11
12 // Create an ElfReader from the file stream.
13 PW_TRY_ASSIGN(auto reader, pw::elf::ElfReader::FromStream(stream));
14
15 // Read the .example section into a vector.
16 PW_TRY_ASSIGN(std::vector<std::byte> section_data,
17 reader.ReadSection(".example"));
18
19 return pw::OkStatus();
20}
API reference#
-
class ElfReader#
A basic reader for ELF files.
Public Functions
-
inline StatusWithSize SeekToSection(std::string_view name)#
Seeks the associated stream to the beginning of the data of the section with the given name.
- Parameters:
name – [in] The name of the desired section.
- Returns:
May return other error codes from the underlying stream.
-
Result<std::vector<std::byte>> ReadSection(std::string_view name)#
Reads a section with the given name.
- Parameters:
name – [in] The name of the desired section.
- Returns:
May return other error codes from the underlying stream.
Public Static Functions
-
static Result<ElfReader> FromStream(stream::SeekableReader &stream)#
Creates an ElfReader from a stream.
- Returns:
Code
Description
The reader was initialized successfully.
The input file was invalid.
Input stream exhausted (EOF).
Some aspect of the ELF file is not (yet) supported by this class, e.g., non-native endianness, or 64-bit ELF on a 32-bit host.
May return other error codes from the underlying stream.
-
inline StatusWithSize SeekToSection(std::string_view name)#