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

aws-lc/crypto/err/err.c:186:17: error: implicit declaration of function ‘strdup’; #610

Open
psumbera opened this issue Nov 22, 2024 · 5 comments
Labels
build problem Build failure

Comments

@psumbera
Copy link

Problem:

Build on Solaris fails:

$ LIBCLANG_PATH=/usr/lib/64/libclang.so cargo build
..
   Compiling aws-lc-sys v0.23.0 (/builds/psumbera/aws-lc-rs/aws-lc-sys)
   Compiling aws-lc-fips-sys v0.12.14 (/builds/psumbera/aws-lc-rs/aws-lc-fips-sys)
The following warnings were emitted during compilation:

warning: [email protected]: Building with: CMake
warning: [email protected]: Symbol Prefix: Some("aws_lc_fips_0_12_14")
warning: [email protected]: Clang version: clang version 13.0.1
warning: [email protected]: Generating bindings - internal bindgen. Platform: x86_64-pc-solaris

error: failed to run custom build command for `aws-lc-fips-sys v0.12.14 (/builds/psumbera/aws-lc-rs/aws-lc-fips-sys)`

Caused by:
  process didn't exit successfully: `/builds/psumbera/aws-lc-rs/target/debug/build/aws-lc-fips-sys-b53e4ffe6fb1194b/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=AWS_LC_FIPS_SYS_NO_PREFIX
  cargo:rerun-if-env-changed=AWS_LC_FIPS_SYS_PREGENERATING_BINDINGS
  cargo:rerun-if-env-changed=AWS_LC_FIPS_SYS_EXTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_FIPS_SYS_NO_ASM
  cargo:rerun-if-env-changed=AWS_LC_FIPS_SYS_STATIC
  cargo:warning=Building with: CMake
  cargo:warning=Symbol Prefix: Some("aws_lc_fips_0_12_14")
  cargo:rerun-if-env-changed=CMAKE
  cargo:warning=Clang version: clang version 13.0.1
  cargo:warning=Generating bindings - internal bindgen. Platform: x86_64-pc-solaris
  cargo:rerun-if-env-changed=AWS_LC_FIPS_SYS_INCLUDES

  --- stderr
  /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/include/rust_wrapper.h:9:10: fatal error: 'openssl/is_awslc.h' file not found
  thread 'main' panicked at aws-lc-fips-sys/builder/sys_bindgen.rs:105:10:
  Unable to generate bindings.: ClangDiagnostic("/builds/psumbera/aws-lc-rs/aws-lc-fips-sys/include/rust_wrapper.h:9:10: fatal error: 'openssl/is_awslc.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
The following warnings were emitted during compilation:

warning: [email protected]: Building with: CMake
warning: [email protected]: Symbol Prefix: Some("aws_lc_0_23_0")
warning: [email protected]: CMAKE environment variable set: cmake
warning: [email protected]: Clang version: clang version 13.0.1
warning: [email protected]: Generating bindings - internal bindgen. Platform: x86_64-pc-solaris

error: failed to run custom build command for `aws-lc-sys v0.23.0 (/builds/psumbera/aws-lc-rs/aws-lc-sys)`

Caused by:
  process didn't exit successfully: `/builds/psumbera/aws-lc-rs/target/debug/build/aws-lc-sys-7a74670ccd16180a/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX
  cargo:rerun-if-env-changed=AWS_LC_SYS_PREGENERATING_BINDINGS
  cargo:rerun-if-env-changed=AWS_LC_SYS_EXTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_ASM
  cargo:rerun-if-env-changed=AWS_LC_SYS_CFLAGS
  cargo:rerun-if-env-changed=AWS_LC_SYS_PREBUILT_NASM
  cargo:rerun-if-env-changed=AWS_LC_SYS_C_STD
  cargo:rerun-if-env-changed=AWS_LC_SYS_CMAKE_BUILDER
  cargo:rerun-if-env-changed=AWS_LC_SYS_STATIC
  cargo:rerun-if-env-changed=CMAKE
  cargo:warning=Building with: CMake
  cargo:warning=Symbol Prefix: Some("aws_lc_0_23_0")
  cargo:rerun-if-env-changed=CMAKE
  cargo:warning=CMAKE environment variable set: cmake
  cargo:warning=Clang version: clang version 13.0.1
  cargo:warning=Generating bindings - internal bindgen. Platform: x86_64-pc-solaris
  cargo:rerun-if-env-changed=AWS_LC_SYS_INCLUDES

  --- stderr
  /builds/psumbera/aws-lc-rs/aws-lc-sys/include/rust_wrapper.h:9:10: fatal error: 'openssl/is_awslc.h' file not found
  thread 'main' panicked at aws-lc-sys/builder/sys_bindgen.rs:106:10:
  Unable to generate bindings.: ClangDiagnostic("/builds/psumbera/aws-lc-rs/aws-lc-sys/include/rust_wrapper.h:9:10: fatal error: 'openssl/is_awslc.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

rustc 1.82.0 (f6e511eec 2024-10-15) (built from a source tarball)
SunOS 5.11 11.4.78.184.0 i86pc i386 i86pc non-virtualized

@psumbera
Copy link
Author

For context why I'm trying this: rust-lang/rustup#4094

@justsmth
Copy link
Contributor

justsmth commented Nov 22, 2024

Hello!

/builds/psumbera/aws-lc-rs/aws-lc-sys/include/rust_wrapper.h:9:10: fatal error: 'openssl/is_awslc.h' file not found

This looks like an error that occurs when the git submodules are not initialized. Are you building directly from the git repository? If so, you can initialize the submodules like this:

git submodule update --init --recursive

(The Makefile in the root of our repo has a useful target for this operation.)

I'm not sure what else might cause an error like this.

I don't think we have any tests setup specifically for Solaris. I might need to spin up a Solaris host to investigate.

@psumbera
Copy link
Author

Thank you!

git submodule update --init --recursive resolved original issue.

Now it fails like:

  [ 46%] Building C object aws-lc/crypto/CMakeFiles/crypto_objects.dir/evp_extra/scrypt.c.o                                                                                                                                                                                                                                                                                                                                           --- stderr
  In file included from /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/fipsmodule/bcm.c:129:
  /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/fipsmodule/rand/urandom.c: In function ‘handle_rare_urandom_error’:                                                                                      /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/fipsmodule/rand/urandom.c:129:3: error: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]                                     129 |   nanosleep(&sleep_time, &sleep_time);                                                                                                                                                                          |   ^~~~~~~~~                                                                                                                                                                                               /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/fipsmodule/rand/urandom.c: In function ‘wait_for_entropy’:                                                                                               /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/fipsmodule/rand/urandom.c:350:19: error: ‘RNDGETENTCNT’ undeclared (first use in this function)                                                            350 |     if (ioctl(fd, RNDGETENTCNT, &entropy_bits)) {                                                                                                                                                               |                   ^~~~~~~~~~~~                                                                                                                                                                            /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/fipsmodule/rand/urandom.c:350:19: note: each undeclared identifier is reported only once for each function it appears in                                 gmake[2]: *** [aws-lc/crypto/fipsmodule/CMakeFiles/bcm_library.dir/build.make:208: aws-lc/crypto/fipsmodule/CMakeFiles/bcm_library.dir/bcm.c.o] Error 1                                                           gmake[1]: *** [CMakeFiles/Makefile2:363: aws-lc/crypto/fipsmodule/CMakeFiles/bcm_library.dir/all] Error 2                                                                                                         gmake[1]: *** Waiting for unfinished jobs....
  /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/err/err.c: In function ‘err_copy’:
  /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/err/err.c:186:17: error: implicit declaration of function ‘strdup’; did you mean ‘strcmp’? [-Wimplicit-function-declaration]
    186 |     dst->data = strdup(src->data);                                                                                                                                                                              |                 ^~~~~~                                                                                                                                                                                          |                 strcmp
  /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/err/err.c:186:15: error: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
    186 |     dst->data = strdup(src->data);
        |               ^
  /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/err/err.c: In function ‘aws_lc_fips_0_12_14_ERR_set_error_data’:
  /builds/psumbera/aws-lc-rs/aws-lc-fips-sys/aws-lc/crypto/err/err.c:763:16: error: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]                                763 |   char *copy = strdup(data);                                                                                                                                                                                    |                ^~~~~~                                                                                                                                                                                     gmake[2]: *** [aws-lc/crypto/CMakeFiles/crypto_objects.dir/build.make:1206: aws-lc/crypto/CMakeFiles/crypto_objects.dir/err/err.c.o] Error 1                                                                      gmake[2]: *** Waiting for unfinished jobs....                                                                                                                                                                     gmake[1]: *** [CMakeFiles/Makefile2:278: aws-lc/crypto/CMakeFiles/crypto_objects.dir/all] Error 2                                                                                                                 gmake: *** [Makefile:136: all] Error 2                                                                                                                                                                            thread 'main' panicked at /builds/psumbera/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.51/src/lib.rs:1100:5:                                                                                                                                                                                                                                                                                                     command did not execute successfully, got: exit status: 2                                                                                                                                                                                                                                                                                                                                                                           build script failed, must exit now                                                                                                                                                                                note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace                           

And if I rerun it I get undefined symbols as I reported here: rust-lang/rustup#4094 (comment)

I will try to look at this closely next week..

@justsmth
Copy link
Contributor

justsmth commented Nov 22, 2024

.../aws-lc/crypto/err/err.c:186:17: error: implicit declaration of function ‘strdup’; did you mean ‘strcmp’? [-Wimplicit-function-declaration]
    186 |     dst->data = strdup(src->data);  

This is interesting. The code it's complaining about is here.

I didn't realize that strdup is not a C99 function, and has only officially been available since C23. 🤯

The proper way to use this in C99 code (assuming the compiler supports it at all) is apparently to define a macro prior to including "string.h". (I found this here: https://en.cppreference.com/w/c/experimental/dynamic/strdup)

#ifdef __STDC_ALLOC_LIB__
#define __STDC_WANT_LIB_EXT2__ 1
#else
#define _POSIX_C_SOURCE 200809L
#endif

As a workaround, you might be able to fix this by setting AWS_LC_SYS_CFLAGS in your environment:

export AWS_LC_SYS_CFLAGS="-D_POSIX_C_SOURCE=200809L"

I'm a little surprised that this issue had not been fixed previously. We'll take a look at what changes we need to make upstream for this.

Thanks for the report!

@justsmth justsmth changed the title aws-lc-rs/aws-lc-sys/include/rust_wrapper.h:9:10: fatal error: 'openssl/is_awslc.h' file not found aws-lc/crypto/err/err.c:186:17: error: implicit declaration of function ‘strdup’; Nov 22, 2024
@justsmth
Copy link
Contributor

FYI -- I updated the title of the issue to indicate the problem that needs to be addressed.

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

No branches or pull requests

2 participants