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

[GraalVM] Static image with musl libc fails with error: ‘struct termios’ has no member named ‘c_ispeed’ #189

Closed
sureshg opened this issue Jul 27, 2024 · 3 comments · Fixed by #191

Comments

@sureshg
Copy link

sureshg commented Jul 27, 2024

I do have a sample GraalVM native image project to create a static image with musl libc. Recently the build started failing (not sure if it's because of any change in GH Action env or updating to the latest dependency 2.7.1) with the following error message (com.github.ajalt.mordant.internal.syscalls.nativeimage.LinuxLibC$termios.getC_ispeed())

[1/8] Initializing...                                                                                    (0.0s @ 0.11GB)
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:173: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 44:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:43:     }
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ispeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:45:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ispeed)));
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:45:169: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    method com.github.ajalt.mordant.internal.syscalls.nativeimage.LinuxLibC$termios.getC_ispeed()
    C file contents around line 45:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ispeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:45:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ispeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:46:     {
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:51:21: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 51:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:50:         memset(&fieldHolder, 0x0, sizeof(fieldHolder));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:51:         fieldHolder.c_ispeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:52:         is_unsigned = fieldHolder.c_ispeed > 0;
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-[137](https://github.com/sureshg/native-image-playground/actions/runs/10119212190/job/27987310517#step:4:138)69868978469610973/LinuxLibC_Directives.c:52:35: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 52:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:51:         fieldHolder.c_ispeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:52:         is_unsigned = fieldHolder.c_ispeed > 0;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:53:         printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:signedness=$%s$\n", (is_unsigned) ? "UNSIGNED" : "SIGNED");
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:88:173: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    C file contents around line 88:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:87:     }
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:88:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ospeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:89:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ospeed)));
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:89:169: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    method com.github.ajalt.mordant.internal.syscalls.nativeimage.LinuxLibC$termios.getC_ospeed()
    C file contents around line 89:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:88:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ospeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:89:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ospeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:90:     {
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:95:21: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    C file contents around line 95:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:94:         memset(&fieldHolder, 0x0, sizeof(fieldHolder));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:95:         fieldHolder.c_ospeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:96:         is_unsigned = fieldHolder.c_ospeed > 0;
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:96:35: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    C file contents around line 96:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:95:         fieldHolder.c_ospeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:96:         is_unsigned = fieldHolder.c_ospeed > 0;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:97:         printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:signedness=$%s$\n", (is_unsigned) ? "UNSIGNED" : "SIGNED");
Internal exception: com.oracle.svm.core.util.UserError$UserException: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:173: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 44:

Native image builds with mordant are working fine on all other platforms (Windows/Linux/Mac)

@sureshg sureshg changed the title [Graal Native Image] Static image with musl libc fails with error: ‘struct termios’ has no member named ‘c_ispeed’ [GraalVM] Static image with musl libc fails with error: ‘struct termios’ has no member named ‘c_ispeed’ Jul 27, 2024
@sureshg sureshg changed the title [GraalVM] Static image with musl libc fails with error: ‘struct termios’ has no member named ‘c_ispeed’ [GraalVM] Static image with musl libc fails with error: ‘struct termios’ has no member named ‘c_ispeed’ Jul 27, 2024
@ajalt
Copy link
Owner

ajalt commented Jul 27, 2024

Hm, is there a way to change the struct definition based on the linked libc? c_ispeed and c_ospeed are required on the standard gnu libc, so I don't think there's a single struct definition that works on both.

@sureshg
Copy link
Author

sureshg commented Jul 27, 2024

is there a way to change the struct definition based on the linked libc?

Sorry, I don't know how to do that. A quick search showed a similar issue on OpenJDK - https://bugs.openjdk.org/browse/JDK-8308544
As per this issue both c_ispeed and c_ospeed are not Posix standard and not available on musl - https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html

ajalt pushed a commit that referenced this issue Jul 28, 2024
When compiling a native image for linux with musl libc, the following
error was displayed:
`'struct termios' has no member named 'c_ispeed'`

On musl, it is named `__c_ispeed`

Since we don't really need those fields anyway,
we can remove them from the struct definition.

We then need to mark the struct definition as incomplete. The
documentation says:
If marked as incomplete, we will not try to determine the size of the
struct.

`StackValue.get(structType)` is actually a shortcut for
`StackValue.get(SizeOf.get(structType))`

We now simply need to pass the explicit size in bytes.

Fixes #189
@sureshg
Copy link
Author

sureshg commented Jul 29, 2024

@hubvd @ajalt You folks are awesome, and thanks for fixing the issue. Build is green on all platforms now 👍🏼

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

Successfully merging a pull request may close this issue.

2 participants