Created
October 4, 2020 12:15
-
-
Save mattnite/62bc6ac10a0327503ea47f71cd43d7ae to your computer and use it in GitHub Desktop.
Relocating BPF map fds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (self.progs.items) |*prog| { | |
const rel_name = try std.mem.join(self.allocator, "", &[_][]const u8{ ".rel", prog.name }); | |
defer self.allocator.free(rel_name); | |
const rel_section: *Elf.Section = for (self.elf.relos.items) |relo| { | |
if (mem.eql(u8, self.elf.get_section_name(relo), rel_name)) { | |
break relo; | |
} | |
} else continue; | |
for (std.mem.bytesAsSlice(Elf64_Rel, rel_section.data)) |relo| { | |
const insn_idx = relo.r_offset / @sizeOf(BPF.Insn); | |
const symbol = self.elf.get_sym_idx(@truncate(u32, relo.r_info >> 32)); | |
const map_name = self.elf.get_str(symbol.st_name); | |
const map_fd = for (self.maps.items) |m| { | |
if (mem.eql(u8, m.name, map_name)) { | |
break m.fd.?; | |
} | |
} else continue; | |
prog.insns[insn_idx].src = BPF.PSEUDO_MAP_FD; | |
prog.insns[insn_idx].imm = map_fd; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment