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

--static opposite behavior #2691

Closed
aleksmelnikov opened this issue Jul 19, 2020 · 6 comments
Closed

--static opposite behavior #2691

aleksmelnikov opened this issue Jul 19, 2020 · 6 comments
Assignees

Comments

@aleksmelnikov
Copy link

Describe the issue
I have --static opposite behavior. Why?

Steps to reproduce the issue

On the firts host.

$ cat /etc/os-release | grep PRETTY_NAME
PRETTY_NAME="Ubuntu 20.04 LTS"

$ ldd --version
ldd (Ubuntu GLIBC 2.31-0ubuntu9) 2.31

$ java --version
openjdk 11.0.7 2020-04-14
OpenJDK Runtime Environment 18.9 (build 11.0.7+10)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.7+10, mixed mode)

$ gu list
ComponentId              Version             Component name      Origin
--------------------------------------------------------------------------------
graalvm                  20.1.0              GraalVM Core
R                        20.1.0              FastR               github.com
llvm-toolchain           20.1.0              LLVM.org toolchain  github.com
native-image             20.1.0              Native Image        github.com
python                   20.1.0              Graal.Python        github.com
wasm                     20.1.0              GraalWasm           github.com

$ pwd
/at/micronaut

$ mn create-app t --lang=java
| Application created at /at/micronaut/t

$ cd t

$ ./gradlew assemble
BUILD SUCCESSFUL in 7s
10 actionable tasks: 10 executed

$ native-image --no-server -cp build/libs/t-0.1-all.jar t.Application
[t.application:308480]    classlist:   7,169.17 ms,  0.96 GB
[t.application:308480]        (cap):     967.05 ms,  0.96 GB
[t.application:308480]        setup:   2,909.42 ms,  0.96 GB
WARNING GR-10238: VarHandle for static field is currently not fully supported. Static field private static volatile java.lang.System$Logger jdk.internal.event.EventHelper.securityLogger is not properly marked for Unsafe access!
[t.application:308480]     (clinit):   1,704.73 ms,  2.21 GB
[t.application:308480]   (typeflow):  32,958.99 ms,  2.21 GB
[t.application:308480]    (objects):  29,922.01 ms,  2.21 GB
[t.application:308480]   (features):   3,911.02 ms,  2.21 GB
[t.application:308480]     analysis:  71,747.43 ms,  2.21 GB
[t.application:308480]     universe:   2,348.82 ms,  2.30 GB
[t.application:308480]      (parse):   7,831.36 ms,  2.20 GB
[t.application:308480]     (inline):  10,616.73 ms,  2.92 GB
[t.application:308480]    (compile):  32,756.90 ms,  3.04 GB
[t.application:308480]      compile:  54,994.37 ms,  3.04 GB
[t.application:308480]        image:   6,718.85 ms,  3.05 GB
[t.application:308480]        write:   1,372.84 ms,  3.05 GB
[t.application:308480]      [total]: 147,633.03 ms,  3.05 GB

$ mv t.application t.application-no-static

$ native-image --static --no-server -cp build/libs/t-0.1-all.jar t.Application
[t.application:308666]    classlist:   6,968.48 ms,  0.96 GB
[t.application:308666]        (cap):     982.89 ms,  0.96 GB
[t.application:308666]        setup:  76,542.32 ms,  0.96 GB
WARNING GR-10238: VarHandle for static field is currently not fully supported. Static field private static volatile java.lang.System$Logger jdk.internal.event.EventHelper.securityLogger is not properly marked for Unsafe access!
[t.application:308666]     (clinit):   1,565.35 ms,  2.42 GB
[t.application:308666]   (typeflow):  34,392.06 ms,  2.42 GB
[t.application:308666]    (objects):  29,067.35 ms,  2.42 GB
[t.application:308666]   (features):   4,038.58 ms,  2.42 GB
[t.application:308666]     analysis:  72,240.97 ms,  2.42 GB
[t.application:308666]     universe:   2,334.27 ms,  2.41 GB
[t.application:308666]      (parse):   8,640.45 ms,  2.38 GB
[t.application:308666]     (inline):   7,129.87 ms,  2.95 GB
[t.application:308666]    (compile):  34,871.48 ms,  3.15 GB
[t.application:308666]      compile:  54,539.95 ms,  3.15 GB
[t.application:308666]        image:   6,988.06 ms,  3.13 GB
[t.application:308666]        write:   1,440.66 ms,  3.13 GB
[t.application:308666]      [total]: 221,423.40 ms,  3.13 GB

$ mv t.application t.application-static

$ ls -Qs --block-size=K | grep t.application
55388K "t.application-no-static"
55224K "t.application-static"

Copy both binaries to the second host with OEL Linux 7.4 x64 GLIBC 2.17

$ ./t.application-no-static
20:08:18.657 [main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 44ms. Server Running: http://host.example.com:8080
^C

$ ./t.application-static
Segmentation fault (core dumped)
@radeusgd
Copy link
Contributor

This may be related to #2486 and #571.

@gradinac
Copy link
Contributor

gradinac commented Aug 6, 2020

Hey @aleksmelnikov!
By default, --static will statically link your native-image against your host libc (glibc). Static linking against glibc is a bad idea - for that reason, on Java 11, we support statically linking against musl.
Since you are running on GraalVM 20.1, you can add -H:UseMuslC=<path> to link against musl, where the is a path to a library bundle that contains musl, zlib and libstdc++. You can download an example bundle from here: https://github.com/gradinac/musl-bundle-example/releases/download/v1.0/musl.tar.gz.

On GraalVM 20.2, this works a bit differently, as described in https://github.com/oracle/graal/blob/master/substratevm/STATIC-IMAGES.md

Let me know if linking against musl fixes your issue.

@ilopmar
Copy link

ilopmar commented Aug 7, 2020

@aleksmelnikov we discourage the use of --static for Micronaut applications. We used to have that flag enabled by default but sometime ago we changed that.

@aleksmelnikov
Copy link
Author

@gradinac , yes linking against musl works for me. Thank you.

@gradinac
Copy link
Contributor

@aleksmelnikov I'm glad that solved it! No problem at all :)
@ilopmar Static had some issues in the past when statically linking against glibc, it is possible to create a fully static native-image by linking against musl (for 20.2+, see https://github.com/oracle/graal/blob/master/substratevm/STATIC-IMAGES.md). For 20.2+, we also support linking everything but libc statically in order to support distroless deployments (-H:+StaticExecutableWithDynamicLibC)

@ilopmar
Copy link

ilopmar commented Aug 17, 2020

@gradinac Thanks for the explanation and the links. We can't switch to that in Micronaut because that approach needs JDK11 (and only Linux, although that is probably not a very big deal for us) and we still allow JDK8. We will keep that in mind for the future when we switch Micronaut itself to JDK11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants