fix(cmd): padding-aware ground-truth comparison
Assisted-by: GLM 5.3
This commit is contained in:
+32
-3
@@ -938,11 +938,40 @@ func compareGroundTruth(img *asm.Image, gt map[string][]byte) (matched, total, d
|
||||
goCmp[j] = 0
|
||||
}
|
||||
}
|
||||
if bytes.Equal(gasmCmp, goCmp) {
|
||||
// The toolchain pads text symbols to 16-byte boundaries with
|
||||
// zeros, so a function whose size is not a multiple of 16
|
||||
// carries trailing zeros in the ground truth that are not part
|
||||
// of the encoding. Compare up to the shorter side and require
|
||||
// the remainder of whichever is longer to be zero, so padding
|
||||
// never masks a real difference.
|
||||
cmpLen := min(len(gasmCmp), len(goCmp))
|
||||
equal := bytes.Equal(gasmCmp[:cmpLen], goCmp[:cmpLen])
|
||||
if equal {
|
||||
for _, b := range gasmCmp[cmpLen:] {
|
||||
if b != 0 {
|
||||
equal = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if equal {
|
||||
for _, b := range goCmp[cmpLen:] {
|
||||
if b != 0 {
|
||||
equal = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if equal {
|
||||
matched++
|
||||
if len(fn.Relocs) > 0 {
|
||||
switch {
|
||||
case len(fn.Relocs) > 0 && len(goCmp) > cmpLen:
|
||||
fmt.Printf(" %s: MATCH (%d bytes, %d relocs masked, %d padding)\n", fn.Name, fn.Size, len(fn.Relocs), len(goCmp)-cmpLen)
|
||||
case len(fn.Relocs) > 0:
|
||||
fmt.Printf(" %s: MATCH (%d bytes, %d relocs masked)\n", fn.Name, fn.Size, len(fn.Relocs))
|
||||
} else {
|
||||
case len(goCmp) > cmpLen:
|
||||
fmt.Printf(" %s: MATCH (%d bytes, %d padding)\n", fn.Name, fn.Size, len(goCmp)-cmpLen)
|
||||
default:
|
||||
fmt.Printf(" %s: MATCH (%d bytes)\n", fn.Name, fn.Size)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user