https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
q

Quang Luong

10/17/2018, 10:27 AM
I am trying to make a Kotlin/Native wrapper for
lwan
web framework. But after cinterop and stuff, I always run into this issue ---- To compile normal app in C with lwan, this command would work clang runApp.c -o samplelwan -Wl,-whole-archive -I../src/lib ../build/src/lib/liblwan.a -Wl,-no-whole-archive -lz -lpthread -llua5.1 -lm
Copy code
headers = lwan.h
package = lwan
staticLibraries = liblwan.a
libraryPaths = lwan/build/src/lib
compilerOpts = -I/lwan/src/lib
linkerOpts = -lz -lpthread -lm
My
def
file
o

olonho

10/17/2018, 11:05 AM
What if you compile lwan with
-Wa,--mrelax-relocations=no
?
m

msink

10/17/2018, 11:20 AM
Weird, but I too see this in https://github.com/msink/kotlin-libui
Copy code
/home/msink/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included8451408511226662848/libui.a(main.c.o): unsupported reloc 42 against global symbol g_direct_equal
/home/msink/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included8451408511226662848/libui.a(main.c.o): unsupported reloc 42 against global symbol g_direct_hash
/home/msink/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included8451408511226662848/libui.a(main.c.o): unsupported reloc 42 against global symbol gtk_main_iteration_do
/home/msink/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included8451408511226662848/libui.a(menu.c.o): unsupported reloc 42 against global symbol g_direct_equal
/home/msink/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included8451408511226662848/libui.a(menu.c.o): unsupported reloc 42 against global symbol g_direct_hash
/home/msink/kotlin-libui/libui/src/unix/main.c:21: error: unsupported reloc 42
/home/msink/kotlin-libui/libui/src/unix/main.c:21: error: unsupported reloc 42
/home/msink/kotlin-libui/libui/src/unix/main.c:49: error: unsupported reloc 42
/home/msink/kotlin-libui/libui/src/unix/menu.c:181: error: unsupported reloc 42
/home/msink/kotlin-libui/libui/src/unix/menu.c:181: error: unsupported reloc 42
error: /home/msink/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold invocation reported errors
It appeared after commit https://github.com/andlabs/libui/commit/6891017cbe07dc3d0826977a825022c45210dae9 in libui library.
o

olonho

10/17/2018, 11:34 AM
BTW, which Linux distro is it? Looks like linker in K/N toolchain doesn't know about binaries produced by new compilers
m

msink

10/17/2018, 11:37 AM
It's Ubuntu 16-04, gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
q

Quang Luong

10/17/2018, 11:41 AM
Copy code
/home/quangio/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included1868694664208704531/liblwan.a(lwan-request.c.o): unsupported reloc 41 against global symbol __assert_fail
/home/quangio/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included1868694664208704531/liblwan.a(lwan-request.c.o): unsupported reloc 41 against global symbol __assert_fail
/home/quangio/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: error: /tmp/included1868694664208704531/liblwan.a(murmur3.c.o): unsupported reloc 41 against global symbol strlen
/home/quangio/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold: internal error in read_header_prolog, at /home/user/ct/toolchain/.build/src/binutils-2.24/gold/dwarf_reader.cc:1618
After adding -Wa,--mrelax-relocations=no ---- I am using Arch Linux, gcc 8
o

olonho

10/17/2018, 11:41 AM
where did you add
-Wa,--mrelax-relocations=no
?
q

Quang Luong

10/17/2018, 11:46 AM
I added it to the CMake file as below
and
make verbose=1
May be it is because of different binutils versions?
o

olonho

10/17/2018, 12:07 PM
q

Quang Luong

10/17/2018, 12:22 PM
Copy code
ln -sf /home/quangio/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld /home/quangio/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold

logging: using Kotlin home directory /usr/lib/kotlin-native/konan
lld is a generic driver.
Invoke ld.lld (Unix), ld (macOS) or lld-link (Windows) instead.
I will try to build the git version when I have time
o

olonho

10/17/2018, 12:30 PM
hmm, locally changing to ld.lld (as in PR) works for me
q

Quang Luong

10/17/2018, 12:39 PM
I am using the binary version, so i don't know how to change it, symlink does not work for some reason (kotlin-native-bin). I will try to run it tmr and report back.
@olonho That see to fix the reloc problem but I still run into error: undefined symbol: __start_lwan_module problem
Copy code
/home/quangio/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld: error: undefined symbol: __start_lwan_module
>>> referenced by lwan.c:91 (/home/quangio/dev/lwan/src/lib/lwan.c:91)
>>>               lwan.c.o:(find_module) in archive /tmp/included7935789285329667150/liblwan.a

/home/quangio/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld: error: undefined symbol: __stop_lwan_module
>>> referenced by lwan.c:91 (/home/quangio/dev/lwan/src/lib/lwan.c:91)
>>>               lwan.c.o:(find_module) in archive /tmp/included7935789285329667150/liblwan.a
Oh sorry, I fixed that thing, but not the
error: undefined symbol: reallocarray
and
error: undefined symbol: fcntl64
o

olonho

10/17/2018, 5:51 PM
that’s likely a problem with how you use LWAN
those two missing symbols shall come from libc
q

Quang Luong

10/17/2018, 5:58 PM
Thanks, that is what I think,
linkerOpts = -lz -ldl -lc -lpthread -lm -L/usr/lib/ -L/home/quangio/dev/lwan/build/src/lib -l:liblwan.so -lc -lgcc -lc
I am using this but it does not work
May be it is the problem with my path, i will investigate it.
o

olonho

10/17/2018, 5:59 PM
you can quickly stub those functions if they aren’t used on your machine with smth like
Copy code
---
void reallocarray() {}
void fcntl64() {}
in the .def file
linkerOpts
looks excessive, K/N provides similar flags, following shall be enough
Copy code
-L/home/quangio/dev/lwan/build/src/lib -llwan
q

Quang Luong

10/17/2018, 6:13 PM
Copy code
headers = lwan.h
package = lwan
staticLibraries = liblwan.a
libraryPaths = /home/quangio/dev/lwan/build/src/lib
compilerOpts = -I/home/quangio/dev/lwan/src/lib -I/usr/lib/
linkerOpts = -L/home/quangio/dev/lwan/build/src/lib -llwan
---
void reallocarray() {}
void fcntl64() {}
Still not working, it is quite weird tho Edit: nvm, i will correct the function signature
The errors look like this
Copy code
/home/quangio/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld: error: undefined symbol: fcntl64
>>> referenced by sd-daemon.c:82 (/home/quangio/dev/lwan/src/lib/sd-daemon.c:82)
>>>               sd-daemon.c.o:(sd_listen_fds) in archive /tmp/included3681342467167857011/liblwan.a

/home/quangio/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld: error: undefined symbol: fcntl64
>>> referenced by sd-daemon.c:91 (/home/quangio/dev/lwan/src/lib/sd-daemon.c:91)
>>>               sd-daemon.c.o:(sd_listen_fds) in archive /tmp/included3681342467167857011/liblwan.a
m

msink

10/18/2018, 10:18 AM
My usecase fixed by
lld
patch. So it will be in next release?
q

Quang Luong

10/18/2018, 1:13 PM
@olonho Thanks a lot for your help. it is working now. I disabled
-D_FILE_OFFSET_BITS=64
flag (fcntl works), and added
-L/usr/lib/ -lbsd
👍 1
40 Views