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

Cannot use hash library within a library function #4273

Open
kosmios1 opened this issue Sep 19, 2024 · 2 comments
Open

Cannot use hash library within a library function #4273

kosmios1 opened this issue Sep 19, 2024 · 2 comments

Comments

@kosmios1
Copy link

Context

I'm encountering an issue when using the hash method within a library function. The setup is as follows:

Library Code

// ./lib/lib.odin
package lib

import "core:crypto/hash"

@(export)
foo :: proc() {
    hash.hash(hash.Algorithm.SHA256, "hello, world")
    return
}

Executable Code

// ./main.odin
package main

foreign import lib "lib.so"

foreign lib {
	foo :: proc() ---
}

main :: proc() {
	foo()
	return
}

Build Commands

  • Library: odin build lib -debug -build-mode:shared.
  • Executable: odin build main.odin -file

Error on Execution

When running the built executable, the following error is produced:

/usr/lib/odin/core/crypto/hash/low_level.odin(171:17) Invalid type assertion from union {Blake2b_Context, Blake2s_Context, Context_256, Context_512, Context, Context, Context, Context, Context} to Context_256
zsh: illegal hardware instruction (core dumped)  ./main

Additional Information

Output of odin report

	Odin:    dev-2024-09-nightly:dd1f151
	OS:      Arch Linux, Linux 6.10.10-arch1-1
	CPU:     AMD Ryzen 7 PRO 6850U with Radeon Graphics
	RAM:     14747 MiB
	Backend: LLVM 18.1.8
@laytan
Copy link
Sponsor Collaborator

laytan commented Sep 19, 2024

That should either be

@(default_calling_convention="odin")
foreign lib {
	foo :: proc() ---
}

Or

@(export)
foo :: proc "c" () {
    ...
}

The reason being that foreign blocks default to the c calling convention.

@kosmios1
Copy link
Author

Same issue also with setting the calling convention

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