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

The build fails out of the box with GCC 4 #3631

Closed
gilles-peskine-arm opened this issue Sep 2, 2020 · 2 comments · Fixed by #3641
Closed

The build fails out of the box with GCC 4 #3631

gilles-peskine-arm opened this issue Sep 2, 2020 · 2 comments · Fixed by #3641
Labels
bug component-platform Portability layer and build scripts help-wanted This issue is not being actively worked on, but PRs welcome.

Comments

@gilles-peskine-arm
Copy link
Contributor

gilles-peskine-arm commented Sep 2, 2020

Older versions of GCC (before 5.0) default to C89, and the build fails with -Wall -Wextra -Werror with some C99 constructs. In particular, the Travis build is failing in Mbed TLS 2.24.0 (example) in tests/scripts/all.sh -k build_arm_none_eabi_gcc_arm5vte build_arm_none_eabi_gcc_m0plus:

ssl_msg.c: In function 'mbedtls_ssl_cf_memcpy_if_eq':
ssl_msg.c:1085:5: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
     for( size_t i = 0; i < len; i++ )
     ^
ssl_msg.c:1085:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
Makefile:263: recipe for target 'ssl_msg.o' failed

We deliberately allow the use of most C99 features in recent versions of Mbed TLS, but not in the currently existing LTS branches (2.7 and 2.16 stick to C89).

We plan to support GCC 4.x as long as it's in a maintained RHEL version. So we should modify CMakeLists.txt to pass -std=c99 if the compiler is GCC (it shouldn't hurt for newer GCC). And we should either do it in Makefile (but there we can't customize the flags per compiler version) or in the all.sh jobs that call an older compiler.

Goals, which we may want to do separately:

@gilles-peskine-arm gilles-peskine-arm added bug component-platform Portability layer and build scripts labels Sep 2, 2020
@daverodgman daverodgman removed this from the September 2020 Sprint milestone Sep 2, 2020
@gilles-peskine-arm gilles-peskine-arm added the help-wanted This issue is not being actively worked on, but PRs welcome. label Sep 2, 2020
okhowang added a commit to okhowang/mbedtls that referenced this issue Sep 3, 2020
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
@okhowang okhowang mentioned this issue Sep 3, 2020
4 tasks
@edsiper
Copy link

edsiper commented Sep 25, 2020

Facing the same issue here when compiling for Centos 7.

The quick and easiest fix is just to declare the variable outside of the for loop:

diff --git a/mbedtls-2.24.0/library/ssl_msg.c b/mbedtls-2.24.0/library/ssl_msg.c
index 2ea35808..537e7609 100644
--- a/mbedtls-2.24.0/library/ssl_msg.c
+++ b/mbedtls-2.24.0/library/ssl_msg.c
@@ -1082,7 +1082,8 @@ static void mbedtls_ssl_cf_memcpy_if_eq( unsigned char *dst,
 #endif
 
     /* dst[i] = c1 != c2 ? dst[i] : src[i] */
-    for( size_t i = 0; i < len; i++ )
+    size_t i;
+    for( i = 0; i < len; i++ )
         dst[i] = ( dst[i] & mask ) | ( src[i] & ~mask );
 }

@gilles-peskine-arm
Copy link
Contributor Author

@edsiper Depending on your configuration, there may be a lot to patch. Mbed TLS is written in C99, and we aren't going to move back to C89. You need to invoke the compiler in C99 mode. For GCC 4.x, this means gcc -std=c99; for GCC ≥5.x it's the default.

okhowang added a commit to okhowang/mbedtls that referenced this issue Sep 25, 2020
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Sep 25, 2020
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Oct 9, 2020
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Dec 30, 2020
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Apr 30, 2021
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Jul 27, 2021
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Aug 2, 2021
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Aug 2, 2021
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Aug 3, 2021
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
okhowang added a commit to okhowang/mbedtls that referenced this issue Aug 9, 2021
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
daverodgman pushed a commit to okhowang/mbedtls that referenced this issue May 11, 2022
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
daverodgman pushed a commit to okhowang/mbedtls that referenced this issue May 11, 2022
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
daverodgman pushed a commit to okhowang/mbedtls that referenced this issue May 11, 2022
Fixes Mbed-TLS#3631

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component-platform Portability layer and build scripts help-wanted This issue is not being actively worked on, but PRs welcome.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants