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

Closed
psumbera opened this issue Nov 22, 2024 · 12 comments

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.

@justsmth
Copy link
Contributor

justsmth commented Dec 4, 2024

Oh.. I just looked through that output again. There were a couple more errors.

  • This first one might likewise be resolved by defining _POSIX_C_SOURCE prior to including "time.h".
aws-lc/crypto/fipsmodule/rand/urandom.c:129:3: error: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration] 
  129 |   nanosleep(&sleep_time, &sleep_time);
      |   ^~~~~~~~~
aws-lc/crypto/fipsmodule/rand/urandom.c:350:19: error: ‘RNDGETENTCNT’ undeclared (first use in this function)                                                            
  350 |     if (ioctl(fd, RNDGETENTCNT, &entropy_bits)) {

Note that the second one only affects a FIPS build. As our FIPS build has a lot of custom logic for MacOS/Linux/Windows, it's possible that our FIPS build will never succeed for a Solaris target. I would recommend not enabling the "fips" feature when building for Solaris.

@justsmth
Copy link
Contributor

justsmth commented Dec 4, 2024

The Solaris man pages indicate that nanosleep should be available. It's defined in "time.h", which that source file includes. I'm wondering if some of these compile errors are specific to the AWS-LC-FIPS v2.0 module. (We will soon to releasing the v3.0 module, which should resolve a lot of failures for the FIPS build.)

Would you try a non-FIPS build for Solaris to see whether you get the same errors? You can post any build errors that occur here if you'd like. Thanks!

justsmth added a commit to aws/aws-lc that referenced this issue Dec 4, 2024
### Issues:
Addresses:
* aws/aws-lc-rs#610

### Description of changes: 
`strdup` was only officially [added to libc in
C23](https://en.cppreference.com/w/c/string/byte/strdup). Platforms we
support may require the `__STDC_WANT_LIB_EXT2__` or `_POSIX_C_SOURCE`
macros to be defined prior to the inclusion of the "string.h" header.

### Call-outs:
* Reference: https://en.cppreference.com/w/c/experimental/dynamic/strdup


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
@psumbera
Copy link
Author

psumbera commented Dec 4, 2024

Oh.. I just looked through that output again. There were a couple more errors.

* This first one might likewise be resolved by defining `_POSIX_C_SOURCE` prior to including "time.h".
aws-lc/crypto/fipsmodule/rand/urandom.c:129:3: error: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration] 
  129 |   nanosleep(&sleep_time, &sleep_time);
      |   ^~~~~~~~~

Yes, I have in my ws:

--- a/crypto/fipsmodule/bcm.c
+++ b/crypto/fipsmodule/bcm.c
@@ -12,6 +12,8 @@
  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

+#define _POSIX_C_SOURCE 199309L // needed for nanosleep() on Solaris (called from urandom.c)
+
 #if !defined(_GNU_SOURCE)
 #define _GNU_SOURCE  // needed for syscall() on Linux.
 #endif
* The second one might be resolved by updating [the preprocessor guard](https://github.com/aws/aws-lc/blob/main/crypto/fipsmodule/rand/urandom.c#L352-L353) around the affected logic:
aws-lc/crypto/fipsmodule/rand/urandom.c:350:19: error: ‘RNDGETENTCNT’ undeclared (first use in this function)                                                            
  350 |     if (ioctl(fd, RNDGETENTCNT, &entropy_bits)) {

Note that the second one only affects a FIPS build. As our FIPS build has a lot of custom logic for MacOS/Linux/Windows, it's possible that our FIPS build will never succeed for a Solaris target. I would recommend not enabling the "fips" feature when building for Solaris.

For this one. I have so far:

--- a/crypto/fipsmodule/rand/urandom.c
+++ b/crypto/fipsmodule/rand/urandom.c
@@ -350,7 +350,7 @@ static void wait_for_entropy(void) {
   }

 #if defined(BORINGSSL_FIPS) && !defined(URANDOM_BLOCKS_FOR_ENTROPY) && \
-    !(defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD)) // On MacOS, iOS, and OpenBSD we don't use /dev/urandom.
+    !(defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD) || defined(OPENSSL_SOLARIS))  // On MacOS, iOS, OpenBSD and Solaris we don't use /dev/urandom.

   // In FIPS mode on platforms where urandom doesn't block at startup, we ensure
   // that the kernel has sufficient entropy before continuing. This is

I have few more fixes but aws-lc still doesn't build for me. How can I disable FIPS build?

@justinwsmith
Copy link
Contributor

How can I disable FIPS build?

For typical consumers of aws-lc-rs, the FIPS build (i.e., the build for aws-lc-fips-sys) only occurs when the "fips" feature has been enabled for aws-lc-rs.

If you've cloned the aws-lc-rs git repo locally, then aws-lc-fips-sys will build as part of the build for the full workspace. You can build just the aws-lc-rs package (and its required dependencies) by changing into the "aws-lc-rs" subdirectory, or by specifying the package when building from the base directory of the workspace: cargo build -p aws-lc-rs )

@justinwsmith
Copy link
Contributor

+    !(defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD) || defined(OPENSSL_SOLARIS))  // On MacOS, iOS, OpenBSD and Solaris we don't use /dev/urandom.

For this, you also need to setup macros that define OPENSSL_SOLARIS when it detects that it's building for a Solaris system. You can see a few examples here: https://github.com/aws/aws-lc/blob/main/include/openssl/target.h#L167-L177

@psumbera
Copy link
Author

psumbera commented Dec 5, 2024

I have created following pull request: aws/aws-lc#2035

This allows build on Solaris. With these changes FIPS module isn't build.

@justsmth
Copy link
Contributor

Hello again! We just released aws-lc-rs v1.12.0. 🎉 We believe our latest release resolves the issue reported here. This issue will now be closed.

If you continue to see this or other problems after upgrading, feel free to re-open this issue or open a new one. Thanks for your help in improving our library!

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

3 participants