[graalvm-users] Trying to run pgbouncer on GraalVM/Sulong

Roland Schatz roland.schatz at oracle.com
Mon Jul 2 07:28:45 PDT 2018


Hi Álvaro,

Thanks for the bug report. This is indeed a problem in Sulong. The 
problem is that the `SYS_getrandom` syscall is not implemented in Sulong.
Supporting this syscall should be easy (at least on Linux). I'll look 
into that.


I have no idea how a direct syscall invocation ended up in the code, 
normally this goes through the `getrandom` libc function. There may be 
some explicit inlining going on. But regardless of how the syscall got 
there, we should of course support it.


- Roland

On 06/30/2018 10:19 PM, Alvaro Hernandez wrote:
>       Hi!
>
>       I'm experimenting with running C programs on GraalVM (via Sulong,
> of course). I was trying to run pgbouncer (https://urldefense.proofpoint.com/v2/url?u=https-3A__pgbouncer.github.io_&d=DwIDaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=Gco5cPtfzG1KXkzFZMUjdOvz53gzbxvOhpXBb2y49D8&s=eVSVV9UdDIAoukIzhGBU-o8Xehp5evajYYa9iMvVW88&e=)
> a PostgreSQL's connection pooler written in C.
>
>       Following indications from
> https://urldefense.proofpoint.com/v2/url?u=http-3A__gbalats.github.io_2015_12_10_compiling-2Dautotooled-2Dprojects-2Dto-2DLLVM-2Dbitcode.html&d=DwIDaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=Gco5cPtfzG1KXkzFZMUjdOvz53gzbxvOhpXBb2y49D8&s=cZZKamlG5JPUfuURIAaIi5I6EYBVX-IGHvZ3ia_4Ni0&e=
> I have been able to compile it to IR. More precisely, the steps taken
> have been:
>
>
> export CC=clang
> export CXX=clang++
> export RANLIB=llvm-ranlib-6.0
> export CFLAGS=" -flto -std=gnu99 "
> export LDFLAGS=" -flto -fuse-ld=gold  -Wl,-plugin-opt=save-temps "
>
> ./configure --without-openssl
> make
>
>       I'm using clang 6.0. Build is fine (I had problems when building
> with SSL, so I disabled it, that's fine for now). pgbouncer starts OK
> when I provided the linked libraries (in .so), but throws
> RuntimeException when trying to establish a connection through the proxy:
>
> graalvm-ce-1.0.0-rc2/bin/lli --lib
> /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5
> /tmp/pgbouncer-1.8.1/pgbouncer.0.5.precodegen.bc
> /tmp/pgbouncer-1.8.1/etc/pgbouncer.ini
> 2018-06-30 23:01:50.132 31696 LOG File descriptor limit: 65536
> (H:65536), max_client_conn: 100, max fds possible: 190
> 2018-06-30 23:01:50.145 31696 LOG Stale pidfile, removing
> 2018-06-30 23:01:50.165 31696 LOG listening on 127.0.0.1:6432
> 2018-06-30 23:01:50.167 31696 LOG listening on unix:/tmp/.s.PGSQL.6432
> 2018-06-30 23:01:50.170 31696 LOG process up: pgbouncer 1.8.1, libevent
> 2.0.21-stable (epoll), adns: evdns2, tls: unsupported
> 2018-06-30 23:01:51.443 31696 LOG C-0x44e13e0: aht/aht at unix(31703):6432
> login attempt: db=aht user=aht
> tls=no                                       <----- connection attempted
> 2018-06-30 23:01:51.464 31696 LOG S-0x44e68c0: aht/aht at unix:5432 new
> connection to server
> java.lang.RuntimeException: unknown syscall 318
>
>
>       RC1 provided more info:
>
> graalvm-1.0.0-rc1/bin/lli --lib
> /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5
> /tmp/pgbouncer-1.8.1/pgbouncer.0.5.precodegen.bc
> /tmp/pgbouncer-1.8.1/etc/pgbouncer.ini
> 2018-06-30 23:02:35.600 31804 LOG File descriptor limit: 65536
> (H:65536), max_client_conn: 100, max fds possible: 190
> 2018-06-30 23:02:35.617 31804 LOG Stale pidfile, removing
> 2018-06-30 23:02:35.648 31804 LOG listening on 127.0.0.1:6432
> 2018-06-30 23:02:35.654 31804 LOG listening on unix:/tmp/.s.PGSQL.6432
> 2018-06-30 23:02:35.659 31804 LOG process up: pgbouncer 1.8.1, libevent
> 2.0.21-stable (epoll), adns: evdns2, tls: unsupported
> 2018-06-30 23:02:36.784 31804 LOG C-0x4ac2bc0: aht/aht at unix(31811):6432
> login attempt: db=aht user=aht tls=no
> 2018-06-30 23:02:36.805 31804 LOG S-0x4ac7b90: aht/aht at unix:5432 new
> connection to server
> com.oracle.truffle.llvm.runtime.SulongRuntimeException: RuntimeException
> unknown syscall 318
>
> C stack trace:
>            LLVM IR Function @getrandom in pgbouncer.0.5.precodegen.bc in
> Block {id: 0 name: %2}
>            LLVM IR Function @getentropy_getrandom in
> pgbouncer.0.5.precodegen.bc in Block {id: 1 name: %7}
>            LLVM IR Function @usual_getentropy in
> pgbouncer.0.5.precodegen.bc in Block {id: 3 name: %17}
>            LLVM IR Function @impl_init.1436 in
> pgbouncer.0.5.precodegen.bc in Block {id: 0 name: %0}
>            LLVM IR Function @prng_check_and_lock in
> pgbouncer.0.5.precodegen.bc in Block {id: 3 name: %12}
>            LLVM IR Function @csrandom_bytes in
> pgbouncer.0.5.precodegen.bc in Block {id: 0 name: %2}
>            LLVM IR Function @get_random_bytes in
> pgbouncer.0.5.precodegen.bc in Block {id: 0 name: %2}
>            LLVM IR Function @welcome_client in
> pgbouncer.0.5.precodegen.bc in Block {id: 4 name: %26}
>            LLVM IR Function @finish_client_login in
> pgbouncer.0.5.precodegen.bc in Block {id: 13 name: %59}
>            LLVM IR Function @handle_client_startup in
> pgbouncer.0.5.precodegen.bc in Block {id: 4 name: %37}
>            LLVM IR Function @client_proto in pgbouncer.0.5.precodegen.bc
> in Block {id: 20 name: %96}
>            LLVM IR Function @sbuf_call_proto in
> pgbouncer.0.5.precodegen.bc in Block {id: 8 name: %28}
>            LLVM IR Function @sbuf_process_pending in
> pgbouncer.0.5.precodegen.bc in Block {id: 10 name: %36}
>            LLVM IR Function @sbuf_main_loop in
> pgbouncer.0.5.precodegen.bc in Block {id: 25 name: %88}
>            LLVM IR Function @sbuf_continue in pgbouncer.0.5.precodegen.bc
> in Block {id: 6 name: %17}
>            LLVM IR Function @activate_client in
> pgbouncer.0.5.precodegen.bc in Block {id: 4 name: %27}
>            LLVM IR Function @reuse_on_release in
> pgbouncer.0.5.precodegen.bc in Block {id: 1 name: %14}
>            LLVM IR Function @release_server in
> pgbouncer.0.5.precodegen.bc in Block {id: 24 name: %103}
>            LLVM IR Function @handle_server_startup in
> pgbouncer.0.5.precodegen.bc in Block {id: 39 name: %171}
>            LLVM IR Function @server_proto in pgbouncer.0.5.precodegen.bc
> in Block {id: 20 name: %98}
>            LLVM IR Function @sbuf_call_proto in
> pgbouncer.0.5.precodegen.bc in Block {id: 8 name: %28}
>            LLVM IR Function @sbuf_process_pending in
> pgbouncer.0.5.precodegen.bc in Block {id: 10 name: %36}
>            LLVM IR Function @sbuf_main_loop in
> pgbouncer.0.5.precodegen.bc in Block {id: 25 name: %88}
>            LLVM IR Function @sbuf_recv_cb in pgbouncer.0.5.precodegen.bc
> in Block {id: 0 name: %3}
>
>
>       pgbouncer is dynamically linked to:
>
> ldd /tmp/pgbouncer-1.8.1/pgbouncer
>           linux-vdso.so.1 =>  (0x00007ffcb05d9000)
>           libevent-2.0.so.5 =>
> /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5 (0x00007f682b70e000)
>           libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f682b344000)
>           libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
> (0x00007f682b127000)
>           /lib64/ld-linux-x86-64.so.2 (0x00007f682b954000)
>
>
>       Even though I understood it was not necessary, I tried adding --lib
> to all the libraries above that are on the system path, but result is
> still the same.
>
>       Any hint on how I can continue? I also tried using --lib with the
> IR version of libevent, but that fails even before, while loading the IR
> version of libevent:
>
> org.graalvm.launcher.Launcher$AbortException
> Caused by: org.graalvm.polyglot.PolyglotException:
> java.lang.IllegalArgumentException: load
> "/tmp/libevent-2.1.8-stable/.libs/libevent-2.1.so.6.0.2.0.5.precodegen.bc"
>
> even though it is LLVM IR code:
>
> file
> /tmp/libevent-2.1.8-stable/.libs/libevent-2.1.so.6.0.2.0.5.precodegen.bc
> /tmp/libevent-2.1.8-stable/.libs/libevent-2.1.so.6.0.2.0.5.precodegen.bc:
> LLVM IR bitcode
>
>
>       I'm not C or IR expert. I understand getrandom function is somehow
> missing, but I don't see who should be providing it. Ideas are much
> appreciated! Thank you,
>
>
>       Álvaro
>
>




More information about the GraalVM-Users mailing list