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: Fix the build for zig binding #2493

Merged
merged 6 commits into from
Jun 19, 2023
Merged

fix: Fix the build for zig binding #2493

merged 6 commits into from
Jun 19, 2023

Conversation

Xuanwo
Copy link
Member

@Xuanwo Xuanwo commented Jun 19, 2023

Fix #2491


cc @Ji-Xinyou, zig test will failed for Segmentation fault while calling binding/c:

make: Leaving directory '/home/xuanwo/Code/apache/incubator-opendal/bindings/c'
run test: error: Segmentation fault at address 0x0
???:?:?: 0x7feeb69f3c5e in ??? (???)
/usr/lib/zig/lib/test_runner.zig:99:29: 0x6661a3 in mainServer (test)
                test_fn.func() catch |err| switch (err) {
                            ^
/usr/lib/zig/lib/test_runner.zig:33:26: 0x65f232 in main (test)
        return mainServer() catch @panic("internal test runner failure");
                         ^
/usr/lib/zig/lib/std/start.zig:598:22: 0x65ebdb in main (test)
            root.main();
                     ^
run test: error: while executing test 'test.Opendal BDD test', the following command terminated with signal 6 (expected exited with code 0):
/home/xuanwo/Code/apache/incubator-opendal/bindings/zig/zig-cache/o/1a1e2be5538563916c07b51d1a461b59/test --listen=- 
Build Summary: 2/4 steps succeeded; 1 failed; 2/2 tests passed
test transitive failure
├─ run make success 1s MaxRSS:613M
└─ run test failure
   └─ zig test Debug native success 1s MaxRSS:809M
error: the following build command failed with exit code 1:
/home/xuanwo/Code/apache/incubator-opendal/bindings/zig/zig-cache/o/dc33acb09b4053acb8601d537eefdc66/build /usr/lib/zig/zig /home/xuanwo/Code/apache/incubator-opendal/bindings/zig /home/xuanwo/Code/apache/incubator-opendal/bindings/zig/zig-cache /home/xuanwo/.cache/zig test --summary all
zig build test --summary all  7.78s user 3.16s system 101% cpu 10.734 total

This can also reproduced by make test under binding/c:

The test itself is unstable, 10% percent to trigger:

rget/debug -lopendal_c -lgtest -lpthread
./build/bdd
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from OpendalBddTest
[ RUN      ] OpendalBddTest.FeatureTest
thread '<unnamed>' panicked at 'misaligned pointer dereference: address must be a multiple of 0x8 but is 0x1', bindings/c/src/types.rs:192:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'panic in a function that cannot unwind', library/core/src/panicking.rs:126:5
stack backtrace:
   0:     0x7f28863fe06a - std::backtrace_rs::backtrace::libunwind::trace::h9a6b80bbf328ba5d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f28863fe06a - std::backtrace_rs::backtrace::trace_unsynchronized::hd162ec543a11886b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f28863fe06a - std::sys_common::backtrace::_print_fmt::h78a5099be12f51a6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f28863fe06a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha1c5390454d74f71
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f288642302f - core::fmt::write::h9ffde816c577717b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:     0x7f28863fa675 - std::io::Write::write_fmt::h88186074961638e4
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:     0x7f28863fde35 - std::sys_common::backtrace::_print::h184198273ed08d59
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f28863fde35 - std::sys_common::backtrace::print::h1b4d8e7add699453
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f28863ff4de - std::panicking::default_hook::{{closure}}::h393bcea75423915a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:     0x7f28863ff285 - std::panicking::default_hook::h48c64f31d8b3fd03
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:     0x7f28863ffa9e - std::panicking::rust_panic_with_hook::hafdc493a79370062
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:691:13
  11:     0x7f28863ff952 - std::panicking::begin_panic_handler::{{closure}}::h0a64bc82e36bedc7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:580:13
  12:     0x7f28863fe4d6 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x7f28863ff6f2 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:     0x7f2886420e33 - core::panicking::panic_nounwind_fmt::hd4fea0bcbbc9daea
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:96:14
  15:     0x7f2886420ee1 - core::panicking::panic_nounwind::h07db722b03cd9dbd
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:126:5
  16:     0x7f2886421073 - core::panicking::panic_cannot_unwind::hfaa00866a3a05433
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:188:5
  17:     0x7f288540ba1c - opendal_metadata_is_file
                               at /home/xuanwo/Code/apache/incubator-opendal/bindings/c/src/types.rs:189:5
  18:     0x55b7a7a36844 - _ZN31OpendalBddTest_FeatureTest_Test8TestBodyEv
  19:     0x7f2884de0b3c - <unknown>
  20:     0x7f2884dcd198 - _ZN7testing4Test3RunEv
  21:     0x7f2884dcd3a7 - _ZN7testing8TestInfo3RunEv
  22:     0x7f2884dcd504 - _ZN7testing9TestSuite3RunEv
  23:     0x7f2884dd9a6f - _ZN7testing8internal12UnitTestImpl11RunAllTestsEv
  24:     0x7f2884dd86a9 - _ZN7testing8UnitTest3RunEv
  25:     0x55b7a7a3797e - _Z13RUN_ALL_TESTSv
  26:     0x55b7a7a375cc - main
  27:     0x7f2884839850 - <unknown>
  28:     0x7f288483990a - __libc_start_main
  29:     0x55b7a7a36365 - _start
  30:                0x0 - <unknown>
thread caused non-unwinding panic. aborting.
make: *** [Makefile:44: test] Aborted (core dumped)

And there also a case for Segmentation fault (core dumped):

g++ tests/bdd.cpp -o ./build/bdd -I./include -std=c++14 -L/home/xuanwo/Code/apache/incubator-opendal/bindings/c/../../target/debug -Wl,-rpath,/home/xuanwo/Code/apache/incubator-opendal/bindings/c/../../target/debug -lopendal_c -lgtest -lpthread
./build/bdd
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from OpendalBddTest
[ RUN      ] OpendalBddTest.FeatureTest
tests/bdd.cpp:73: Failure
Value of: opendal_metadata_is_file(meta)
  Actual: false
Expected: true
tests/bdd.cpp:76: Failure
Expected equality of these values:
  opendal_metadata_content_length(meta)
    Which is: 140723506084224
  13
make: *** [Makefile:44: test] Segmentation fault (core dumped)

Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo Xuanwo marked this pull request as draft June 19, 2023 05:28
Signed-off-by: Xuanwo <github@xuanwo.io>
@xyjixyjixyji
Copy link
Contributor

I ran 1000 times of make test on my aarch64 mac machine and cannot reproduce the segfault in C binding test, can you tell me more information about how to trigger it (steps, your environment, etc.)?

@Xuanwo
Copy link
Member Author

Xuanwo commented Jun 19, 2023

can you tell me more information about how to trigger it (steps, your environment, etc.)?

Archlinux with x86_64. Maybe related to the alignment.

@xyjixyjixyji
Copy link
Contributor

can you tell me more information about how to trigger it (steps, your environment, etc.)?

Archlinux with x86_64. Maybe related to the alignment.

I have a manjaro x86_64 machine, I will try to reproduce as soon as I get my hands on it.

Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo
Copy link
Member Author

Xuanwo commented Jun 19, 2023

cc @Ji-Xinyou, I have fixed this, PTAL.

Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo Xuanwo marked this pull request as ready for review June 19, 2023 10:26
@Xuanwo Xuanwo requested a review from xyjixyjixyji June 19, 2023 10:27
bindings/c/src/lib.rs Show resolved Hide resolved
bindings/c/src/types.rs Show resolved Hide resolved
@xyjixyjixyji
Copy link
Contributor

I think the memory management thing in C binding is really an error-prone thing to do. To avoid this, we could add valgrind memory test on Linux machine in the future.

Signed-off-by: Xuanwo <github@xuanwo.io>
Copy link
Contributor

@xyjixyjixyji xyjixyjixyji left a comment

Choose a reason for hiding this comment

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

Nice work, thanks!

Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo Xuanwo merged commit 26deb25 into main Jun 19, 2023
18 checks passed
@Xuanwo Xuanwo deleted the try-fix-zig branch June 19, 2023 11:17
@PsiACE PsiACE mentioned this pull request Jun 27, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bindings/zig: Test failed for binding/c API changes
2 participants