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

Unable to run tests in libc-test using musl (Alpine Linux 3.18.2) #3305

Closed
CuriouslyCurious opened this issue Jul 17, 2023 · 8 comments
Closed
Labels
C-bug Category: bug

Comments

@CuriouslyCurious
Copy link

CuriouslyCurious commented Jul 17, 2023

I am unable to run the tests in libc-test using musl on Alpine Linux.

To reproduce:

  1. Clone the libc repo.
  2. cd libc-test && cargo test

This fails with:

  ...
  cargo:rerun-if-changed=../src/lib.rs
  cargo:rerun-if-changed=../src/macros.rs
  cargo:rerun-if-changed=../src/fixed_width_ints.rs
  cargo:rerun-if-changed=../src/unix/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/musl/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/musl/lfs64.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/musl/b64/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/musl/b64/x86_64/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/arch/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/arch/generic/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/align.rs
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-musl")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-musl
  CC_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_musl
  CC_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-musl
  CFLAGS_x86_64-unknown-linux-musl = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_musl
  CFLAGS_x86_64_unknown_linux_musl = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-unknown-warning-option" "-Wno-deprecated-declarations" "-D_GNU_SOURCE" "-D__GLIBC_USE_DEPRECATED_SCANF" "-o" "/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/9e1282f7293605d7-main.o" "-c" "/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c"
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c: In function '__test_fsize_af_alg_iv_iv':
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c:22283:34: error: invalid application of 'sizeof' to incomplete type '__u8[]' {aka 'unsigned char[]'}
  cargo:warning=22283 |                     return sizeof(foo->iv);
  cargo:warning=      |                                  ^
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c: In function '__test_roundtrip_af_alg_iv':
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c:22299:13: note: the ABI of passing struct with a flexible array member has changed in GCC 4.4
  cargo:warning=22299 |             ) {
  cargo:warning=      |             ^
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c: In function '__test_field_type_utmpx_ut_session':
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c:38937:28: error: returning 'int *' from a function with incompatible return type 'long int *' [-Werror=incompatible-pointer-types]
  cargo:warning=38937 |                     return &b->ut_session;
  cargo:warning=      |                            ^~~~~~~~~~~~~~
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c: In function '__test_fsize_af_alg_iv_iv':
  cargo:warning=/home/curious/dev/rust/forks/libc/target/debug/build/libc-test-37e96ea7152d2cd4/out/main.c:22284:17: error: control reaches end of non-void function [-Werror=return-type]
  cargo:warning=22284 |                 }
  cargo:warning=      |                 ^
  cargo:warning=At top level:
  cargo:warning=cc1: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics
  cargo:warning=cc1: all warnings being treated as errors
  exit status: 1
  ...

I've looked into the build scripts but have been unable to locate where this sizeof call gets made.

Extra info that may or may not help:

Kernel: 6.1.38-7-lts
rustc: 1.71.0

❯ rustc --version
rustc 1.71.0 (8ede3aae2 2023-07-12)

Architecture: Intel i7-3520M (4) @ 3.600GHz
OS: Alpine Linux 3.18.2

❯ bat -n /etc/os-release 
   1 NAME="Alpine Linux"
   2 ID=alpine
   3 VERSION_ID=3.18.2
   4 PRETTY_NAME="Alpine Linux v3.18"
   5 HOME_URL="https://alpinelinux.org/"
   6 BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

cc: 13.1.1

❯ cc --version
cc (Alpine 13.1.1_git20230715) 13.1.1 20230715
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

clang: 16.0.6

❯ clang --version
Alpine clang version 16.0.6
Target: x86_64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang16/x86_64-alpine-linux-musl.cfg

Full log:
log.txt

@devnexen
Copy link
Contributor

Would this PR work for you ?

@CuriouslyCurious
Copy link
Author

Would this PR work for you ?

Unfortunately it does not seem to work for me:

  ...
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-unknown-warning-option" "-Wno-deprecated-declarations" "-D_GNU_SOURCE" "-D__GLIBC_USE_DEPRECATED_SCANF" "-o" "/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/3a1bc9cc9021a524-main.o" "-c" "/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c"
  cargo:warning=/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c: In function '__test_fsize_af_alg_iv_iv':
  cargo:warning=/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c:22283:34: error: invalid application of 'sizeof' to incomplete type '__u8[]' {aka 'unsigned char[]'}
  cargo:warning=22283 |                     return sizeof(foo->iv);
  cargo:warning=      |                                  ^
  cargo:warning=/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c: In function '__test_roundtrip_af_alg_iv':
  cargo:warning=/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c:22299:13: note: the ABI of passing struct with a flexible array member has changed in GCC 4.4
  cargo:warning=22299 |             ) {
  cargo:warning=      |             ^
  cargo:warning=/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c: In function '__test_fsize_af_alg_iv_iv':
  cargo:warning=/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c:22284:17: error: control reaches end of non-void function [-Werror=return-type]
  cargo:warning=22284 |                 }
  cargo:warning=      |                 ^
  cargo:warning=At top level:
  cargo:warning=cc1: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics
  cargo:warning=cc1: all warnings being treated as errors
  exit status: 1

  --- stderr
  rust version: 1.71.0


  error occurred: Command "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-unknown-warning-option" "-Wno-deprecated-declarations" "-D_GNU_SOURCE" "-D__GLIBC_USE_DEPRECATED_SCANF" "-o" "/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/3a1bc9cc9021a524-main.o" "-c" "/home/curious/dev/rust/forks/utmpx_linux_musl/target/debug/build/libc-test-3c72df52c5a5615e/out/main.c" with args "cc" did not execute successfully (status code exit status: 1).
  ...

log.txt

@devnexen
Copy link
Contributor

devnexen commented Jul 22, 2023

I wanted to see if the utmpx type was fixed, it seems the case. is it the same failure with clang ?

@CuriouslyCurious
Copy link
Author

I wanted to see if the utmpx type was fixed, it seems the case. is it the same failure with clang ?

Looks like I'd need to rewrite the build.rs file to not use cc if I am understanding it correctly, which is a whole different kind of pain.

@jcajka
Copy link

jcajka commented Aug 3, 2023

For the record I have hit what seems as this issue in Fedora.

git clone https://github.com/rust-lang/libc
pushd libc/libc-test
cargo test

snip
.
.
.
 cargo:rerun-if-changed=../src/lib.rs
  cargo:rerun-if-changed=../src/macros.rs
  cargo:rerun-if-changed=../src/fixed_width_ints.rs
  cargo:rerun-if-changed=../src/unix/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/gnu/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/gnu/b64/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/arch/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/arch/generic/mod.rs
  cargo:rerun-if-changed=../src/unix/linux_like/linux/align.rs
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-unknown-warning-option" "-Wno-deprecated-declarations" "-D_GNU_SOURCE" "-D__GLIBC_USE_DEPRECATED_SCANF" "-o" "/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/b0f3d9471b1ba493-main.o" "-c" "/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c"
  cargo:warning=/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c: In function ‘__test_fsize_af_alg_iv_iv’:

  cargo:warning=/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c:25438:34: error: invalid application of ‘sizeof’ to incomplete type ‘__u8[]’ {aka ‘unsigned char[]’}

  cargo:warning=25438 |                     return sizeof(foo->iv);

  cargo:warning=      |                                  ^

  cargo:warning=/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c: In function ‘__test_roundtrip_af_alg_iv’:

  cargo:warning=/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c:25454:13: note: the ABI of passing struct with a flexible array member has changed in GCC 4.4

  cargo:warning=25454 |             ) {

  cargo:warning=      |             ^

  cargo:warning=/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c: In function ‘__test_fsize_af_alg_iv_iv’:

  cargo:warning=/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c:25439:17: error: control reaches end of non-void function [-Werror=return-type]

  cargo:warning=25439 |                 }

  cargo:warning=      |                 ^

  cargo:warning=At top level:

  cargo:warning=cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics

  cargo:warning=cc1: all warnings being treated as errors

  exit status: 1

  --- stderr
  rust version: 1.71.0


  error occurred: Command "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-unknown-warning-option" "-Wno-deprecated-declarations" "-D_GNU_SOURCE" "-D__GLIBC_USE_DEPRECATED_SCANF" "-o" "/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/b0f3d9471b1ba493-main.o" "-c" "/root/libc/target/debug/build/libc-test-0e2fcb5e7316ed69/out/main.c" with args "cc" did not execute successfully (status code exit status: 1).

Same/similar issue is happening across all architectures supported by Fedora(x86_64 log^^,s390x, ppc64le and aarch64).
This is with rust-1.71, glibc-2.37, gcc-13.2.1 and binutils-2.40.

@JohnTitor
Copy link
Member

I believe the cause is y'all use different versions for toolchains, e.g. musl, GCC, clang, etc. Since the current test cannot change type/value according to user system version, I'd recommend running the test via Docker, like CI.

bors added a commit that referenced this issue Sep 29, 2023
Add secure_getenv function for Linux variants

This adds the [`secure_getenv`](https://www.gnu.org/software/libc/manual/html_node/Environment-Access.html#index-secure_005fgetenv) function for Linux variants as it is supported in both GNU libc (2.17+) and musl ([1.1.24+](https://git.musl-libc.org/cgit/musl/commit/?h=v1.1.24&id=ea9525c8bcf6170df59364c4bcd616de1acf8703)).

It is recommended to be used over the regular `getenv`, and there is a [standing issue](rust-lang/rust#92558) for the Rust library to use it instead.

I can't properly test it on my machine as there is some funky stuff going on with musl. I'll open up a [separate issue](#3305) with the output as it doesn't concern this fairly simple change.
@jcajka
Copy link

jcajka commented Oct 2, 2023

@JohnTitor Could you please list what versions of the respective, relevant tools that are supported by this rust crate?

@jcajka
Copy link

jcajka commented Oct 2, 2023

And for the record, if I run it in Fedora container I get the same results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants