Skip to content

Commit

Permalink
reloc
Browse files Browse the repository at this point in the history
  • Loading branch information
achevuru committed Jan 18, 2023
1 parent aec28a9 commit 6d47ea8
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions pkg/elfparser/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,7 @@ func (c *ELFContext) loadElfMapsSection(mapsShndx int, dataMaps *elf.Section, el
for _, sym := range symbols {
if int(sym.Section) == mapsShndx && int(sym.Value) == offset {
mapName := path.Base(sym.Name)
log.Infof("mapData name: %s", mapName)
mapData.Name = mapName
log.Infof("mapData name: %s", mapData.Name)
/*
cstr := C.CString(mapName)
b := C.GoBytes(unsafe.Pointer(cstr), C.int(unsafe.Sizeof(cstr)))
str := string(b)
mapData.Name = str
C.free(unsafe.Pointer(cstr))
break
*/
}
}
log.Infof("Found map name %s", mapData.Name)
Expand Down Expand Up @@ -323,12 +313,15 @@ func (c *ELFContext) loadElfProgSection(dataProg *elf.Section, reloSection *elf.
}
// Patch instruction to use proper map fd
mapName := relocationEntry.symbol.Name
immOffset := make([]byte, 4)
log.Infof("Map to be relocated; Name: %s", mapName)
if progMap, ok := c.Maps[mapName]; ok {
log.Infof("Map found. Replace the offset with corresponding Map FD: %v", progMap.MapFD)
bpfInstruction.srcReg = 1
bpfInstruction.imm = int32(progMap.MapFD)
copy(data[relocationEntry.offset:], bpfInstruction.update())
//bpfInstruction.srcReg = 1
//bpfInstruction.imm = int32(progMap.MapFD)
binary.LittleEndian.PutUint32(immOffset, uint32(progMap.MapFD))
copy(data[relocationEntry.offset+4:relocationEntry.offset+8], immOffset)
//copy(data[relocationEntry.offset:], bpfInstruction.update())
log.Infof("BPF Instruction code: %s; offset: %d; imm: %d", bpfInstruction.code, bpfInstruction.off, bpfInstruction.imm)
} else {
return fmt.Errorf("map '%s' doesn't exist", mapName)
Expand Down

0 comments on commit 6d47ea8

Please sign in to comment.