Skip to content

Commit 4267cbc

Browse files
committed
btf: return an error if type has no signedness
Refuse to create a fixup for reloFieldSigned if the type isn't an Int or an Enum. On clang-14 it's not even possible to create such a relocation, so no need to be extra lenient. Add a unit test since we can't get clang to emit a wonky relocation. Signed-off-by: Lorenz Bauer <[email protected]>
1 parent 9faf24e commit 4267cbc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

btf/core.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ func coreCalculateFixups(relos []*CORERelocation, targetSpec *Spec, targets []Ty
303303
return bestFixups, nil
304304
}
305305

306+
var errNoSignedness = errors.New("no signedness")
307+
306308
// coreCalculateFixup calculates the fixup for a single local type, target type
307309
// and relocation.
308310
func coreCalculateFixup(relo *CORERelocation, target Type, targetID TypeID, bo binary.ByteOrder) (COREFixup, error) {
@@ -461,7 +463,7 @@ func coreCalculateFixup(relo *CORERelocation, target Type, targetID TypeID, bo b
461463
uint32(target.Encoding&Signed),
462464
)
463465
default:
464-
return fixupWithoutValidation(0, 0)
466+
return zero, fmt.Errorf("type %T: %w", local, errNoSignedness)
465467
}
466468
}
467469
}

btf/core_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,14 @@ func TestCOREReloFieldSigned(t *testing.T) {
673673
qt.Assert(t, err, qt.IsNil)
674674
})
675675
}
676+
677+
t.Run("type without signedness", func(t *testing.T) {
678+
relo := &CORERelocation{
679+
&Array{}, coreAccessor{0}, reloFieldSigned, 0,
680+
}
681+
_, err := coreCalculateFixup(relo, &Array{}, 0, internal.NativeEndian)
682+
qt.Assert(t, err, qt.ErrorIs, errNoSignedness)
683+
})
676684
}
677685

678686
func TestCOREReloFieldShiftU64(t *testing.T) {

0 commit comments

Comments
 (0)