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

build error with c lib #72

Closed
ghost opened this issue Mar 23, 2020 · 11 comments
Closed

build error with c lib #72

ghost opened this issue Mar 23, 2020 · 11 comments

Comments

@ghost
Copy link

ghost commented Mar 23, 2020

gcc -shared -O3 -o libblake3.so blake3.c blake3_dispatch.c blake3_portable.c \
>     blake3_sse41_x86-64_unix.S blake3_avx2_x86-64_unix.S blake3_avx512_x86-64_unix.S
/usr/bin/ld: /tmp/ccoz9HaM.o: relocation R_X86_64_PC32 against symbol `blake3_simd_degree' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

I'm getting the error above when trying to compile the share library. including -fPIC solves it, but not sure if that will result in intended behavior. a small clarification on this would be good

@sneves
Copy link
Collaborator

sneves commented Mar 23, 2020

You'll need to specify the particular system (Linux (?) distribution, GCC version, at least) this is happening on. I cannot reproduce this.

@ghost
Copy link
Author

ghost commented Mar 24, 2020

Sorry about that

NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

GCC is

ost=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)

This in Windows WSL btw

@ghost
Copy link
Author

ghost commented Mar 24, 2020

also now that i have your attention

x86_64-w64-mingw32-gcc -I/usr/lib/jvm/default-java/include -shared \
-o ../blake3.dll blake3.c blake3_dispatch.c blake3_portable.c blake3_sse41_x86-64_windows_gnu.S \ 
blake3_avx512_x86-64_windows_gnu.S

this should build a working dll for windows 64 right? I'm working on JNI bindings for the c api. so thats why i need to build the project in different platforms while appending the Java bindings

Thanks!

@sergeevabc
Copy link

Could mere Windows users without compilers try this bleeding-edge stuff? Give us a binary, please.

@sneves
Copy link
Collaborator

sneves commented Mar 24, 2020

It would appear that on this GCC version, either -fPIC is not a default or -shared does not activate it automatically for the selected input files, even though it's necessary for linking to work. Adding -fPIC manually is an appropriate solution.

Regarding Windows, I am not too familiar with the MinGW toolchain, but you might need dllexport and dllimport annotations, like shown here. A DLL library was not something we explicitly targeted.

@sergeevabc
Copy link

sergeevabc commented Mar 24, 2020

@sneves, what library? I talk about .exe, generated as less dependent as possible. Like @Cyan4973 does with xxHash. Wider audience uses, as you know, Windows. And we’re still patiently waiting for a SHA2/3 replacement that BLAKE2 never became (that is, it screwed because of being too diverse).

@ghost
Copy link
Author

ghost commented Mar 24, 2020

@sneves i just tried it with gcc 7.4 and it resulted in the same error btw. strange

@ghost
Copy link
Author

ghost commented Mar 24, 2020

@sneves i got it to compile a working dll with the following

x86_64-w64-mingw32-gcc -I/usr/lib/jvm/default-java/include -static -shared -o ../../../natives/windows_64/blake3.dll blake3.c blake3_dispatch.c blake3_portable.c blake3_sse41_x86-64_win
dows_gnu.S blake3_avx2_x86-64_windows_gnu.S blake3_avx512_x86-64_windows_gnu.S org_scash_NativeBLAKE3.c

it works with either -static or -static-libgcc without either of these the dll is trying to find libgcc_s_seh-1.dll which is the dll in charge of handling and throwing exceptions. I'm not very familiar with c, I found this by exploring the dll dependencies with the Dependency Checker for dlls.

It works now as in the library is successfully loaded into jvm. Testing the actually bindings is next.

https://github.com/sken77/BLAKE3jni

here is a link of the project

@oconnor663
Copy link
Member

oconnor663 commented Mar 24, 2020

@sergeevabc, this issue is discussing a specific set of compiler errors. If you'd like to discuss pre-compiled binaries, please open a separate issue. (If you want to try out BLAKE3, I recommend taking a look at the b3sum CLI tool, by installing the Rust toolchain and running cargo install b3sum. But if that doesn't work for you, again, please open a separate issue, to avoid taking this one off-topic.)

@oconnor663
Copy link
Member

@sken77 tweeted :)

@oconnor663
Copy link
Member

It looks like the questions here have been answered, so I'm going to close this one. I've opened #78 about pre-compiled binaries.

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

3 participants