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

Segfault when calling out to C from a parapoly context #4285

Closed
Drvi opened this issue Sep 21, 2024 · 1 comment
Closed

Segfault when calling out to C from a parapoly context #4285

Drvi opened this issue Sep 21, 2024 · 1 comment

Comments

@Drvi
Copy link

Drvi commented Sep 21, 2024

Context

odin report

        Odin:    dev-2024-09:c1264c2a7
        OS:      Pop!_OS 22.04 LTS, Linux 6.9.3-76060903-generic
        CPU:     AMD Ryzen 9 7900 12-Core Processor             
        RAM:     63428 MiB
        Backend: LLVM 18.1.8

I'm getting a segfault when calling to a C library but only when the call happens in a parapoly context. This is my first time trying this, so maybe I screwed something up.

Steps to Reproduce

On Linux:

git clone https://github.com/Drvi/blis-odin
cd blis-odin
./repro.sh

You might need to tweak the path to the generated library in bindings/blis.odin

Failure Information (for bugs)

This here is the meat of the reproducer:

    N := 8
    m := make([]f64, N*N)
    defer delete(m)

    // works with a slice
    fmt.println(m) // all zeroes
    alpha := 1.0
    blis.bli_dsetm( // the external call, that sets all the values in `m` to `alpha`
        blis.conj.BLIS_NO_CONJUGATE,
        blis.doff(0),
        blis.diag.BLIS_NONUNIT_DIAG,
        blis.uplo.BLIS_DENSE,
        blis.dim(N),
        blis.dim(N),
        &alpha,
        raw_data(m),
        blis.inc(N),
        blis.inc(1),
    )
    fmt.println(m) // all ones, as expected
    fmt.println()

    // Wrap the slice that we just used
    // Symmetric :: struct($T: typeid) { // defined in the blis module
    //     data: []T,
    //     m: int,
    // }
    t: blis.Symmetric(f64)
    t.data = m
    t.m = N

    fmt.println(t)
    // setsym :: proc(s: Symmetric($E), alpha: E) { // defined in the blis module
    //     alpha := alpha
    //     bli_dsetm(
    //         conj.BLIS_NO_CONJUGATE,
    //         doff(0),
    //         diag.BLIS_NONUNIT_DIAG,
    //         uplo.BLIS_DENSE,
    //         dim(s.m),
    //         dim(s.m),
    //         &alpha,
    //         raw_data(s.data),
    //         inc(s.m),
    //         inc(1),
    //     )
    //     return
    // }
    blis.setsym(t, 2.0) // segfaults
    fmt.println(t)

I'm getting segfaults / SEGV with -sanitize:address in the setsym call, which just wraps a call that succeed earlier on the same allocated slice.

Failure Logs

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

Symmetric($T=f64){data = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], m = 8}
AddressSanitizer:DEADLYSIGNAL
=================================================================
==122712==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x000000586aa0 bp 0x000000000002 sp 0x7fff46901588 T0)
==122712==The signal is caused by a READ memory access.
==122712==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
    #0 0x586aa0 in bli_dsetv_zen_int (/home/tomasd/_proj/odin-blis/example+0x586aa0) (BuildId: bba148f0cedc1196da3facd3a9c125793ba88b60)
    #1 0x569ace in bli_dsetm_unb_var1 (/home/tomasd/_proj/odin-blis/example+0x569ace) (BuildId: bba148f0cedc1196da3facd3a9c125793ba88b60)
    #2 0x5575d3 in bli_dsetm (/home/tomasd/_proj/odin-blis/example+0x5575d3) (BuildId: bba148f0cedc1196da3facd3a9c125793ba88b60)
    #3 0x50aa9f in blis.setsym-898 /home/tomasd/_proj/odin-blis/bindings/blis.odin:104:5
    #4 0x5031b9 in main.main /home/tomasd/_proj/odin-blis/example.odin:51:5
    #5 0x5076d4 in main /home/tomasd/_proj/Odin/base/runtime/entry_unix.odin:57:4
    #6 0x76ecde429d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #7 0x76ecde429e3f in __libc_start_main csu/../csu/libc-start.c:392:3
    #8 0x42a7b4 in _start (/home/tomasd/_proj/odin-blis/example+0x42a7b4) (BuildId: bba148f0cedc1196da3facd3a9c125793ba88b60)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/tomasd/_proj/odin-blis/example+0x586aa0) (BuildId: bba148f0cedc1196da3facd3a9c125793ba88b60) in bli_dsetv_zen_int
==122712==ABORTING
@Drvi
Copy link
Author

Drvi commented Sep 22, 2024

There was a bug in the program -- I used c.int (4 bytes) instead of an int (8 bytes) which caused a wrong value was passed in to the procedure. Not sure why this only happened when I used parapoly, but I think I can close this now. Sorry for the noise!

@Drvi Drvi closed this as completed Sep 22, 2024
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

1 participant