Skip to content

Commit

Permalink
Fix a llvm signed division error for compactsnoop tool
Browse files Browse the repository at this point in the history
Fix issue iovisor#4182.
llvm doesn't support signed division and an assertion error
will happen when the IR contains sdiv. The reason is
due to code
  zone - zone_pgdat->node_zones
where zone and zone_pgdat->node_zones are pointers to
struct zone (with size 1664). So effectively the above
is equivalent to
  ((void *)zone - (void *)zone_pgdat->node_zones)/sizeof(struct zone)
which is converted to sdiv insn.
llvm11 seems okay and I didn't investigate why. But llvm14 and
latest llvm16 failed with compiler fatal error.

To fix the issue let us replace the above '(void *)' as
'(u64)' and then the udiv will be used for the division.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed Aug 27, 2022
1 parent 382a332 commit ac43959
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/compactsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
{
struct pglist_data *zone_pgdat = NULL;
bpf_probe_read_kernel(&zone_pgdat, sizeof(zone_pgdat), &zone->zone_pgdat);
return zone - zone_pgdat->node_zones;
return ((u64)zone - (u64)zone_pgdat->node_zones)/sizeof(struct zone);
}
#ifdef EXTNEDED_FIELDS
Expand Down

0 comments on commit ac43959

Please sign in to comment.