Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compactsnoop fails to compile on Fedora36/LLVM14 #4182

Closed
chantra opened this issue Aug 16, 2022 · 2 comments
Closed

compactsnoop fails to compile on Fedora36/LLVM14 #4182

chantra opened this issue Aug 16, 2022 · 2 comments

Comments

@chantra
Copy link
Contributor

chantra commented Aug 16, 2022

When trying to run the compactsnoop test on Fedora, it fails with:

$ docker run -ti \                     
                    --privileged \
                    --network=host \
                    --pid=host \
                    -v $(pwd):/bcc \
                    -v /sys/kernel/debug:/sys/kernel/debug:rw \
                    -v /lib/modules:/lib/modules:ro \
                    -v /usr/src:/usr/src:ro \
                    -e CTEST_OUTPUT_ON_FAILURE=1 \
                    bcc-docker-f36 \
                    /bin/bash -c \
                    '/bcc/build/tests/wrapper.sh \
                        "py_test_map_in_map" "sudo"  "/bcc/tools/compactsnoop.py"'
Error at line 82: Unsupport signed division for DAG: 0x55c28143eb00: i64 = sdiv exact 0x55c28143ea30, Constant:i64<1472>, /virtual/main.c:82:17 @[ /virtual/main.c:159:17 @[ /virtual/main.c:192:5 ] ]Please convert to unsigned div/mod.
LLVM ERROR: Cannot select: 0x55c28143eb00: i64 = sdiv exact 0x55c28143ea30, Constant:i64<1472>, /virtual/main.c:82:17 @[ /virtual/main.c:159:17 @[ /virtual/main.c:192:5 ] ]
  0x55c28143ea30: i64 = sub 0x55c281fb0290, 0x55c28143ec38, /virtual/main.c:82:17 @[ /virtual/main.c:159:17 @[ /virtual/main.c:192:5 ] ]
    0x55c281fb0290: i64,ch = CopyFromReg 0x55c281c492f8, Register:i64 %0, /virtual/main.c:168:25
      0x55c281fb0a48: i64 = Register %0
    0x55c28143ec38: i64,ch = load<(dereferenceable load (s64) from %ir.2, !tbaa !2015)> 0x55c28143e890, FrameIndex:i64<0>, undef:i64, /virtual/main.c:82:19 @[ /virtual/main.c:159:17 @[ /virtual/main.c:192:5 ] ]
      0x55c28143e3b0: i64 = FrameIndex<0>
      0x55c281fb0568: i64 = undef
  0x55c28143ea98: i64 = Constant<1472>
In function: raw_tracepoint__mm_compaction_suitable
/bcc/build/tests/wrapper.sh: line 39: 172116 Aborted                 sudo --preserve-env=PYTHON_TEST_LOGFILE env PYTHONIOENCODING=$PYTHONIOENCODING PYTHONPATH=$PYTHONPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH $cmd "$@"
Failed

LLVM/Clang:

# rpm -qa | egrep  '(clang|llvm)'
llvm-libs-14.0.0-1.fc36.x86_64
llvm-14.0.0-1.fc36.x86_64
clang-resource-filesystem-14.0.0-1.fc36.x86_64
llvm-test-14.0.0-1.fc36.x86_64
clang-libs-14.0.0-1.fc36.x86_64
clang-tools-extra-14.0.0-1.fc36.x86_64
llvm-static-14.0.0-1.fc36.x86_64
clang-14.0.0-1.fc36.x86_64
clang-devel-14.0.0-1.fc36.x86_64
llvm-devel-14.0.0-1.fc36.x86_64

The error message seems to be related to: https://bugs.llvm.org/show_bug.cgi?id=26976

The BPF program generated by:

$ docker run -ti \
                    --privileged \
                    --network=host \
                    --pid=host \
                    -v $(pwd):/bcc \
                    -v /sys/kernel/debug:/sys/kernel/debug:rw \
                    -v /lib/modules:/lib/modules:ro \
                    -v /usr/src:/usr/src:ro \
                    -e CTEST_OUTPUT_ON_FAILURE=1 \
                    bcc-docker-f36 \   
                    /bin/bash -c \
                    '/bcc/build/tests/wrapper.sh \
                        "py_test_map_in_map" "sudo"  "/bcc/tools/compactsnoop.py" "--ebpf"'

is
https://gist.github.com/chantra/af0c77d97faa4e4c59c5a19b079527a4

It is not clear to me where such division/modulo happens.

cc @yonghong-song

yonghong-song added a commit that referenced this issue Aug 26, 2022
Fix issue #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]>
@yonghong-song
Copy link
Collaborator

#4196 should fix the issue.

yonghong-song added a commit that referenced this issue Aug 27, 2022
Fix issue #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]>
@chantra
Copy link
Contributor Author

chantra commented Aug 27, 2022

confirmed! Thanks

@chantra chantra closed this as completed Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants