On Fri, 28 Apr 2023 18:16:07 GMT, Erik Joelsson <[email protected]> wrote:
> I pulled this PR and had a go at building it. For me it failed with errors
> like this:
>
> ```
> /home/erik/git/jdk/build/linux-x64/images/static-libs/lib/libjvm.a(os_linux.o):os_linux.cpp:function
> os::Linux::fast_thread_clock_init(): error: undefined reference to
> 'clock_getres'
> /home/erik/git/jdk/build/linux-x64/images/static-libs/lib/libjvm.a(os_linux.o):os_linux.cpp:function
> os::Linux::fast_thread_cpu_time(int): error: undefined reference to
> 'clock_gettime'
> /home/erik/git/jdk/build/linux-x64/images/static-libs/lib/libjvm.a(os_linux.o):os_linux.cpp:function
> os::current_thread_cpu_time(): error: undefined reference to 'clock_gettime'
> /home/erik/git/jdk/build/linux-x64/images/static-libs/lib/libjvm.a(os_linux.o):os_linux.cpp:function
> os::thread_cpu_time(Thread*): error: undefined reference to 'clock_gettime'
> /home/erik/git/jdk/build/linux-x64/images/static-libs/lib/libjvm.a(os_linux.o):os_linux.cpp:function
> os::current_thread_cpu_time(bool): error: undefined reference to
> 'clock_gettime'
> /home/erik/git/jdk/build/linux-x64/images/static-libs/lib/libjvm.a(os_linux.o):os_linux.cpp:function
> os::init_2(): error: undefined reference to 'clock_getres'
> ```
>
> I haven't dug any deeper to try to figure this out. Is this something you
> recognize?
Erik, could you please share your
`support/native/java.base/java/BUILD_LAUNCHER_javastatic_static_link.cmdline`?
This generated .cmdline file contains the static linking command. Here is the
linking command from my build:
/usr/bin/gcc -Wl,-z,defs -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
-Wl,--hash-style=gnu -m64 -static-libstdc++ -static-libgcc -Wl,-rpath,$ORIGIN/.
-Wl,--export-dynamic -o
/.../build/linux-x86_64-server-slowdebug/jdk/bin/javastatic
/.../linux-x86_64-server-slowdebug/support/native/java.base/java/main.o
-Wl,--whole-archive
/.../linux-x86_64-server-slowdebug/images/static-libs/lib/libattach.a ...
/.../linux-x86_64-server-slowdebug/images/static-libs/lib/libjvm.a
-Wl,--no-whole-archive -lpthread -ldl -lm -l:libstdc++.a
`clock_getres` and the other related symbols are provided by `libc`. For
`libc`, we don't static link with. We still use `libc.so`.
$ ldd jdk/bin/javastatic
linux-vdso.so.1 (0x00007fff8b17a000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0845321000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0845140000)
/lib64/ld-linux-x86-64.so.2 (0x00007f084888d000)
$ objdump -Tw /lib/x86_64-linux-gnu/libc.so.6 | grep clock_getres
00000000000cf260 g DF .text 0000000000000069 GLIBC_2.17 clock_getres
00000000000cf260 g DF .text 0000000000000069 (GLIBC_2.2.5) clock_getres
$ nm jdk/bin/javastatic | grep clock_gettime
U clock_gettime@GLIBC_2.17
$ nm jdk/bin/javastatic | grep clock_getres
U clock_getres@GLIBC_2.17
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13709#issuecomment-1528158982