Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › debug › ElfFile › buildSymbolSearchTable Private Function buildSymbolSearchTable Doc Source Private Function std.debug.ElfFile.buildSymbolSearchTable
fn buildSymbolSearchTable (gpa : Allocator , endian : Endian , comptime Sym : type , symbols : []align (1 ) const Sym ) error Params File debug/ElfFile.zig: 305
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344 fn buildSymbolSearchTable (gpa : Allocator , endian : Endian , comptime Sym : type , symbols : []align (1 ) const Sym ) error {
OutOfMemory ,
BadSymtab ,
}![]usize {
var result : std .ArrayList (usize ) = .empty ;
defer result .deinit (gpa );
const swap_endian = endian != @import ("builtin " ).cpu .arch .endian ();
for (symbols , 0 ..) |sym_orig , sym_index | {
var sym = sym_orig ;
if (swap_endian ) std .mem .byteSwapAllFields (Sym , &sym );
if (sym .st_name == 0 ) continue ;
if (sym .st_shndx == elf .SHN_UNDEF ) continue ;
try result .append (gpa , sym_index );
}
const SortContext = struct {
swap_endian : bool ,
symbols : []align (1 ) const Sym ,
fn lessThan (ctx : @This (), lhs_sym_index : usize , rhs_sym_index : usize ) bool {
// We sort by *end* address, not start address. This matches up with logic in `searchSymtab`.
var lhs_sym = ctx .symbols [lhs_sym_index ];
var rhs_sym = ctx .symbols [rhs_sym_index ];
if (ctx .swap_endian ) {
std .mem .byteSwapAllFields (Sym , &lhs_sym );
std .mem .byteSwapAllFields (Sym , &rhs_sym );
}
const lhs_val = lhs_sym .st_value + lhs_sym .st_size ;
const rhs_val = rhs_sym .st_value + rhs_sym .st_size ;
return lhs_val < rhs_val ;
}
};
std .mem .sort (usize , result .items , @as (SortContext , .{
.swap_endian = swap_endian ,
.symbols = symbols ,
}), SortContext .lessThan );
return result .toOwnedSlice (gpa );
}