tiny.tldr.formats.elf.format.binary
Defined in formats.elf.format.
API (11)
Actions
Public operations.
alignForwardalignForwardU64decodeSectionHeadersisElfreadSectionHeaderreadSymbol: Decodes one symbol table entry into the parsed symbol shape, by way ofreadSymbolRecord.readSymbolRecord: Decodes one 24-byte ELF64 symbol table entry, stored little-endian, into its on-disk record so the entry's byte layout is read in one place.requireRangesectionBytesstringFromTablevalidateAlignment
Source
Source: lib/tldr/src/formats/elf/binary.zig
zig
const std = @import("std");const root = @import("../../root.zig");const record = @import("record.zig");const model = root.model;const native_endian = record.native_endian;const shdr_size = record.shdr_size;const SectionHeader = record.SectionHeader;const Symbol = record.Symbol;const SymbolRecord = record.SymbolRecord;const byte = @import("byte.zig");const copyInto = byte.copyInto;const readU16 = byte.readU16;const readU32 = byte.readU32;const readU64 = byte.readU64;pub fn sectionBytes(bytes: []const u8, section: SectionHeader) model.Error![]const u8 { if (section.section_type == std.elf.SHT_NOBITS) return &.{}; try requireRange(bytes, section.offset, section.size); const start: usize = @intCast(section.offset); const size: usize = @intCast(section.size); return bytes[start .. start + size];}pub fn isElf(bytes: []const u8) bool { return bytes.len >= 4 and std.mem.eql(u8, bytes[0..4], std.elf.MAGIC);}pub fn requireRange(bytes: []const u8, offset: u64, size: u64) model.Error!void { if (offset > bytes.len) return error.InvalidRange; if (size > bytes.len - offset) return error.InvalidRange;}pub fn stringFromTable(table: []const u8, offset: u32) model.Error![]const u8 { if (offset >= table.len) return error.InvalidStringTable; const start: usize = @intCast(offset); const end = std.mem.indexOfScalarPos(u8, table, start, 0) orelse return error.InvalidStringTable; return table[start..end];}pub fn decodeSectionHeaders(bytes: []const u8, shoff: u64, sections: []SectionHeader) void { if (native_endian == .little) { const start: usize = @intCast(shoff); const byte_count = sections.len * shdr_size; @memcpy(std.mem.sliceAsBytes(sections), bytes[start..][0..byte_count]); return; } for (sections, 0..) |*section, index| { const offset: u64 = shoff + @as(u64, @intCast(index)) * shdr_size; section.* = readSectionHeader(bytes, offset); }}pub fn readSectionHeader(bytes: []const u8, offset: u64) SectionHeader { const start: usize = @intCast(offset); return .{ .name_offset = readU32(bytes[start..], 0), .section_type = readU32(bytes[start..], 4), .flags = readU64(bytes[start..], 8), .address = readU64(bytes[start..], 16), .offset = readU64(bytes[start..], 24), .size = readU64(bytes[start..], 32), .link = readU32(bytes[start..], 40), .info = readU32(bytes[start..], 44), .alignment = readU64(bytes[start..], 48), .entry_size = readU64(bytes[start..], 56), };}/// Decodes one 24-byte ELF64 symbol table entry, stored little-endian, into its/// on-disk record so the entry's byte layout is read in one place. The function/// is the only decoder of that entry: `readSymbol` and `View.symbol` both call/// it.pub fn readSymbolRecord(bytes: []const u8) SymbolRecord { return .{ .name_offset = readU32(bytes, 0), .info = bytes[4], .other = bytes[5], .section_index = readU16(bytes, 6), .value = readU64(bytes, 8), .size = readU64(bytes, 16), };}/// Decodes one symbol table entry into the parsed symbol shape, by way of/// `readSymbolRecord`. The object parser calls this function for each entry of/// a symbol table before it resolves the names. The result's `name` is empty,/// because the name lives in the symbol string table, which the caller holds/// and looks up afterwards.pub fn readSymbol(bytes: []const u8) Symbol { const wire = readSymbolRecord(bytes); return .{ .name_offset = wire.name_offset, .info = wire.info, .other = wire.other, .section_index = wire.section_index, .value = wire.value, .size = wire.size, };}pub fn validateAlignment(alignment: u64) model.Error!void { if (alignment == 0) return; if ((alignment & (alignment - 1)) != 0) return error.InvalidAlignment;}pub fn alignForward(value: usize, alignment: usize) usize { if (alignment == 0) return value; const mask = alignment - 1; return (value + mask) & ~mask;}pub fn alignForwardU64(value: u64, alignment: u64) u64 { if (alignment == 0) return value; const mask = alignment - 1; return (value + mask) & ~mask;}Source: lib/tldr/src/formats/elf/format.zig:2
zig
pub const binary = @import("binary.zig");Complete caller list for formats.elf.format.binary.requireRange
13 direct callers.
tiny.tldr.formats.elf.format.binary.sectionBytes[function] atlib/tldr/src/formats/elf/binary.zig:18tiny.tldr.formats.elf.ehframe.header.writer.write[function] atlib/tldr/src/formats/elf/ehframe/header/writer.zig:42lib.tldr.src.formats.elf.metadata.linkedSectionByName[function] — private source atlib/tldr/src/formats/elf/metadata.zig:161in nearest public ownerlib.tldr.src.formats.elf.metadatalib.tldr.src.formats.elf.metadata.loadProgramHeaderByAddressAndType[function] — private source atlib/tldr/src/formats/elf/metadata.zig:186in nearest public ownerlib.tldr.src.formats.elf.metadatalib.tldr.src.formats.elf.metadata.metadataLayout[function] — private source atlib/tldr/src/formats/elf/metadata.zig:126in nearest public ownerlib.tldr.src.formats.elf.metadatatiny.tldr.formats.elf.note.finishBuildId[function] atlib/tldr/src/formats/elf/note.zig:44tiny.tldr.formats.elf.note.finishBuildIdSection[function] atlib/tldr/src/formats/elf/note.zig:56tiny.tldr.formats.elf.note.patchGenerated[function] atlib/tldr/src/formats/elf/note.zig:93tiny.tldr.formats.elf.note.writeBuildIdHeader[function] atlib/tldr/src/formats/elf/note.zig:33tiny.tldr.formats.elf.parser.parseObjectSelectionSummary[function] atlib/tldr/src/formats/elf/parser.zig:280tiny.tldr.formats.elf.parser.parseObjectWithOptions[function] atlib/tldr/src/formats/elf/parser.zig:397lib.tldr.src.load.LoadIterator.init[function] — private source atlib/tldr/src/load.zig:165in nearest public ownerlib.tldr.src.loadlib.tldr.src.load.copyLoadSegments[function] — private source atlib/tldr/src/load.zig:122in nearest public ownerlib.tldr.src.load
Complete caller list for formats.elf.format.binary.sectionBytes
23 direct callers.
lib.tldr.src.formats.elf.ehframe.header.reservation.countEntries[function] — private source atlib/tldr/src/formats/elf/ehframe/header/reservation.zig:48in nearest public ownertiny.tldr.formats.elf.ehframe.header.reservationlib.tldr.src.formats.elf.ehframe.header.writer.collectEntries[function] — private source atlib/tldr/src/formats/elf/ehframe/header/writer.zig:80in nearest public ownertiny.tldr.formats.elf.ehframe.header.writertiny.tldr.formats.elf.ehframe.Scan.prepare[method] atlib/tldr/src/formats/elf/ehframe/scan.zig:61tiny.tldr.formats.elf.group.record.bytes[function] atlib/tldr/src/formats/elf/group/record.zig:22lib.tldr.src.formats.elf.icf.hash.section[function] — private source atlib/tldr/src/formats/elf/icf/hash.zig:11in nearest public ownerlib.tldr.src.formats.elf.icf.hashlib.tldr.src.formats.elf.icf.match.sections[function] — private source atlib/tldr/src/formats/elf/icf/match.zig:11in nearest public ownerlib.tldr.src.formats.elf.icf.matchtiny.tldr.formats.elf.merge.Fixed.collect[method] atlib/tldr/src/formats/elf/merge/fixed.zig:67tiny.tldr.formats.elf.merge.String.register[method] atlib/tldr/src/formats/elf/merge/string.zig:50lib.tldr.src.formats.elf.metadata.linkedSectionByName[function] — private source atlib/tldr/src/formats/elf/metadata.zig:161in nearest public ownerlib.tldr.src.formats.elf.metadatalib.tldr.src.formats.elf.metadata.metadataLayout[function] — private source atlib/tldr/src/formats/elf/metadata.zig:126in nearest public ownerlib.tldr.src.formats.elf.metadatatiny.tldr.formats.elf.parser.parseObjectSelectionSummary[function] atlib/tldr/src/formats/elf/parser.zig:280tiny.tldr.formats.elf.parser.parseObjectWithOptions[function] atlib/tldr/src/formats/elf/parser.zig:397lib.tldr.src.formats.elf.parser.test_ELF_parser_rejects_string_table_without_zero_slot[function] — test source atlib/tldr/src/formats/elf/parser.zig:107in nearest public ownertiny.tldr.formats.elf.parserlib.tldr.src.formats.elf.payload.copyEhFrameSection[function] — private source atlib/tldr/src/formats/elf/payload.zig:427in nearest public ownertiny.tldr.formats.elf.payloadlib.tldr.src.formats.elf.payload.copyObjectAllocSectionsBatched[function] — private source atlib/tldr/src/formats/elf/payload.zig:386in nearest public ownertiny.tldr.formats.elf.payloadlib.tldr.src.formats.elf.payload.copySection[function] — private source atlib/tldr/src/formats/elf/payload.zig:342in nearest public ownertiny.tldr.formats.elf.payloadtiny.tldr.formats.elf.payload.verifyMergePieceBytes[function] atlib/tldr/src/formats/elf/payload.zig:138lib.tldr.src.formats.elf.relink.hashSections[function] — private source atlib/tldr/src/formats/elf/relink.zig:1277in nearest public ownertiny.tldr.formats.elf.relinklib.tldr.src.formats.elf.relink.relocatedPayloadAlloc[function] — private source atlib/tldr/src/formats/elf/relink.zig:296in nearest public ownertiny.tldr.formats.elf.relinklib.tldr.src.formats.elf.relink.replacementForContribution[function] — private source atlib/tldr/src/formats/elf/relink.zig:166in nearest public ownertiny.tldr.formats.elf.relinktiny.tldr.formats.elf.relocation.count.countRelocationsBySection[function] atlib/tldr/src/formats/elf/relocation/count.zig:37lib.tldr.src.formats.elf.relocation.decode.borrowSingleRelocationSection[function] — private source atlib/tldr/src/formats/elf/relocation/decode.zig:304in nearest public ownertiny.tldr.formats.elf.relocation.decodetiny.tldr.formats.elf.relocation.decode.parseRelocationsBySection[function] atlib/tldr/src/formats/elf/relocation/decode.zig:205
Audit
| Definitions | 12 |
|---|---|
| Public names | 23 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |