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

Fix runtime tests for aarch64 #3185

Merged
merged 2 commits into from
Jun 17, 2024
Merged

Conversation

ttreyer
Copy link
Contributor

@ttreyer ttreyer commented May 17, 2024

This PR fixes the following tests, that are failing when running on ARM:

  • Update CreateInteger to accept 128-bits integers.
    The ARM specific struct user_fpsimd_state has a 128-bits integers.
  • Update DWARF parser to consider arrays of unsigned char as strings.
    The chars from "tests/data/data_source.c"'s struct Arrays::char_arr have the Basic Type lldb::eBasicTypeUnsignedChar. Is this valid? Is there a bug in GCC for generating wrong DWARF?
  • Force frame pointers for each testprogs and testlibs.
    The compiler doesn't have to set-up a frame pointer for leaf functions. We enforce their generation with -fno-omit-frame-pointer AND -mno-omit-leaf-frame-pointer.
  • Ignore STT_NOTYPE symbols from the symbol table.
    ARM binaries might contain mapping symbols, which are not relevant to bpftrace. These symbols messes with symbolication, as they might have the same address as other symbols.
  • Fix runtime test other.positional ustack.
    The expected regex would not tolerate extra stack trace. By using the s flag with .*, we accept any number of extra lines, while being strict enough to validate that uprobeFunction1 is on top of the last stack trace.

After these fixes, the following runtime tests still fail:

  • probe.kprobe_offset_fail_size: the function AttachedProbe::resolve_offset_kprobe cannot locate vmlinux, because my machine only has vmlinuZ, and thus can't check the boundaries of vfs_read. The Kernel didn't reject the probe vfs_read+100000. Shouldn't this function use /proc/kallsyms instead?
  • call.path: The path builtin function returns path with the form /dev/pts/4, but never returns the expected path of the temporary file created for the test. Is this a Kernel bug?
  • call.strcontains: This test uses the path builtin function and fails because of the issue above.
Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@ttreyer ttreyer force-pushed the fix-aarch64-fedora40 branch 3 times, most recently from 97c1afb to 77ec3c0 Compare May 21, 2024 17:11
@ttreyer ttreyer changed the title Fix tests on aarch64 on Fedora 40 Fix runtime tests for aarch64 May 22, 2024
@ttreyer ttreyer marked this pull request as ready for review May 22, 2024 13:08
Copy link
Member

@ajor ajor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good but I have a worry that that relaxing the assertion to allow 128-bit integers could cause problems in other places not expecting it

src/types.cpp Outdated
@@ -256,7 +256,7 @@ SizedType CreateInteger(size_t bits, bool is_signed)
// enough information to figure out the exact size of the integer. Later
// passes infer the exact size.
assert(bits == 0 || bits == 1 || bits == 8 || bits == 16 || bits == 32 ||
bits == 64);
bits == 64 || bits == 128);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what happens in codegen if something tries to use a 128-bit integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a test and figure it out...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajor Following up on our chat, I modified SizedType to accept 128-bits integers. However, they get truncated down to only 64-bits with a warning to the user. The warning is done by the semantic_analyser, then the codegen_llvm insert the truncate for a FieldAccess on a user-defined type, if required.

@jordalgo
Copy link
Contributor

Confirmed that other.positional ustack works on my Arm VM with this change.

@ttreyer ttreyer force-pushed the fix-aarch64-fedora40 branch 2 times, most recently from aa3c233 to 6bd069d Compare May 24, 2024 15:55
Copy link
Member

@ajor ajor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's possible to get a 128-bit integer through to codegen and have it trigger a seg-fault:

void uprobeFunction3(__int128_t bigint) {}
uprobe:./build/tests/testprogs/uprobe_test:uprobeFunction3 {
  print(args.bigint);
}

I think for simplicity, codegen shouldn't know anything about 128-bit integers at all - they should get truncated in the type system before they reach that point.

src/types.h Show resolved Hide resolved
@ttreyer ttreyer force-pushed the fix-aarch64-fedora40 branch 2 times, most recently from 4a854de to 8028901 Compare June 10, 2024 19:57
__uint128_t y = 0xEFEFEFEFEFEFEFEF;
__uint128_t z = 0xCDCDCDCDCDCDCDCD;
__uint128_t w = 0xABABABABABABABAB;
uprobeFunctionUint128(x, y, z, w);

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect (because
uprobeFunctionUint128
has no external side effects).
tests/runtime/dwarf Outdated Show resolved Hide resolved
* Update `CreateInteger` to accept 128-bits integers.
  The ARM specific [`struct user_fpsimd_state`](https://elixir.bootlin.com/linux/latest/source/arch/arm64/include/uapi/asm/ptrace.h#L95) has a 128-bits integers.
* Update DWARF parser to consider arrays of `unsigned char` as strings.
  The `char`s from "tests/data/data_source.c"'s `struct Arrays::char_arr` have the Basic Type `lldb::eBasicTypeUnsignedChar`. Is this valid? Is there a bug in GCC for generating wrong DWARF?
* Force frame pointers for each `testprogs` and `testlibs`.
  The compiler doesn't have to set-up a frame pointer for leaf functions. We enforce their generation with `-fno-omit-frame-pointer` AND `-mno-omit-leaf-frame-pointer`.
* Ignore `STT_NOTYPE` symbols from the symbol table.
  ARM binaries might contain [mapping symbols](https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#mapping-symbols), which are not relevant to bpftrace. These symbols messes with symbolication, as they might have the same address as other symbols.
* Fix runtime test `other.positional ustack`.
  The expected regex would not tolerate extra stack trace. By using the `s` flag with `.*`, we accept any number of extra lines, while being strict enough to validate that `uprobeFunction1` is on top of the last stack trace.
* Fix `runner.py` to escape invalid characters comming from the test's stdout.

After these fixes, the following runtime tests still fail:
* `probe.kprobe_offset_fail_size`: the function `AttachedProbe::resolve_offset_kprobe` cannot locate `vmlinux`, because my machine only has `vmlinuZ`, and thus can't check the boundaries of `vfs_read`. The Kernel didn't reject the probe `vfs_read+100000`. Shouldn't this function use `/proc/kallsyms` instead?
* `call.path`: The `path` builtin function returns path with the form `/dev/pts/4`, but never returns the expected path of the temporary file created for the test. Is this a Kernel bug?
* `call.strcontains`: This test uses the `path` builtin function and fails because of the issue above.

f
Copy link
Member

@ajor ajor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ajor ajor merged commit 9f53abf into bpftrace:master Jun 17, 2024
17 checks passed
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

Successfully merging this pull request may close these issues.

None yet

3 participants