Skip to content

Commit

Permalink
fix: embed parse broken by external check
Browse files Browse the repository at this point in the history
Signed-off-by: Zxilly <zxilly@outlook.com>
  • Loading branch information
Zxilly committed Jun 22, 2024
1 parent 2f1ef21 commit 147c447
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
23 changes: 19 additions & 4 deletions internal/dwarf/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,21 @@ func EntryShouldIgnore(entry *dwarf.Entry) bool {

inline := entry.Val(dwarf.AttrInline)
if inline != nil {
val, ok := inline.(bool)
return !ok || val
val, ok := inline.(int64)
return !ok || val != 0
}

var boolIgnores = []dwarf.Attr{
dwarf.AttrCallAllCalls,
dwarf.AttrCallAllTailCalls,
dwarf.AttrExternal,
}

for _, ignore := range boolIgnores {
valAny := entry.Val(ignore)
if valAny != nil {
val, ok := valAny.(bool)
if !ok {
slog.Warn(fmt.Sprintf("Failed to load DWARF function as type unexpected %T: %s", valAny, EntryPrettyPrint(entry)))
slog.Warn(fmt.Sprintf("Failed to load DWARF function as bool field type unexpected %T: %s", valAny, EntryPrettyPrint(entry)))
return true
}
if val {
Expand All @@ -127,6 +126,22 @@ func EntryShouldIgnore(entry *dwarf.Entry) bool {
}
}

externalAny := entry.Val(dwarf.AttrExternal)
if externalAny != nil {
external, ok := externalAny.(bool)
if !ok {
slog.Debug(fmt.Sprintf("Failed to load DWARF function as dwarf.AttrExternal type unexpected %T: %s", externalAny, EntryPrettyPrint(entry)))
return true
}

if external {
if entry.Tag == dwarf.TagSubprogram {
// external function doesn't exist in this entry
return true
}
}
}

return false
}

Expand Down
33 changes: 21 additions & 12 deletions internal/dwarf/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,30 @@ func readEmbedFS(typ *dwarf.StructType, readMemory MemoryReader) ([]Content, err
dataLen := readUintTo64(data[offset+ptrSize*3 : offset+ptrSize*4])

hashAddr := offset + ptrSize*4
hashLen := 16

contents = append(contents, Content{
Name: utils.Deduplicate(fmt.Sprintf("%s.name", name)),
Addr: nameAddr,
Size: nameLen,
}, Content{
Name: utils.Deduplicate(fmt.Sprintf("%s.data", name)),
Addr: dataAddr,
Size: dataLen,
}, Content{
hashLen := uint64(16)

fileContent := make([]Content, 0, 3)
if nameLen > 0 {
fileContent = append(fileContent, Content{
Name: utils.Deduplicate(fmt.Sprintf("%s.name", name)),
Addr: nameAddr,
Size: nameLen,
})
}
if dataLen > 0 {
fileContent = append(fileContent, Content{
Name: utils.Deduplicate(fmt.Sprintf("%s.data", name)),
Addr: dataAddr,
Size: dataLen,
})
}
fileContent = append(fileContent, Content{
Name: utils.Deduplicate(fmt.Sprintf("%s.hash", name)),
Addr: uint64(hashAddr),
Size: uint64(hashLen),
Size: hashLen,
})

contents = append(contents, fileContent...)
}

return contents, nil
Expand Down

0 comments on commit 147c447

Please sign in to comment.