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

AArch64: Compile error in trclog.c with strncpy() #4486

Closed
knn-k opened this issue Jan 29, 2019 · 8 comments · Fixed by #5508
Closed

AArch64: Compile error in trclog.c with strncpy() #4486

knn-k opened this issue Jan 29, 2019 · 8 comments · Fixed by #5508

Comments

@knn-k
Copy link
Contributor

knn-k commented Jan 29, 2019

I got the following error while I was compiling for linux_aarch64. It is similar to Issue #3242.

aarch64-linux-gnu-gcc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DOPENJ9_BUILD -O -fgnu89-inline -g -DLINUX -D_REENTRANT -D_FILE_OFFSET_BITS=64 -fpic -DIPv6_FUNCTION_SUPPORT -DJ9AARCH64 -Wimplicit -Wreturn-type -Werror -Wall -I. -I../include -I../oti -I../gc_include -I../omr/gc/include -I../nls -I../omr/include_core    -DUT_DIRECT_TRACE_REGISTRATION -DTR_HOST_ARM64 -c -o trclog.o trclog.c
In file included from /root/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/usr/include/string.h:639:0,
                 from ../omr/include_core/omrstdarg.h:27,
                 from trclog.c:26:
In function 'strncpy',
    inlined from 'getTrcBuf' at trclog.c:1063:3:
/root/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/usr/include/bits/string3.h:125:10: error: '__builtin_strncpy' writing 512 bytes into a region of size 1 overflows the destination [-Werror=stringop-overflow=]
   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
../makelib/targets.mk:272: recipe for target 'trclog.o' failed

# aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (Linaro GCC 7.3-2018.05) 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701]

It compiles without the error when I remove -D_FORTIFY_SOURCE=1 from the command-line option.

@knn-k knn-k changed the title AArch64: AArch64: Compile error in trclog.c with strncpy() Jan 29, 2019
@gacholio
Copy link
Contributor

gacholio commented Feb 5, 2019

I suspect a cast of the dest to void* in the caller would fix this.

@knn-k
Copy link
Contributor Author

knn-k commented Feb 6, 2019

No, casting the destination to void * does not change the error.
I will use --disable-warnings-as-errors-openj9 in configure for the time being.

@dnakamura
Copy link
Contributor

interesting. On other linux platforms this only shows up when _FORTIFY_SOURCE >=2. I believe the only way to deal with it (other than modifying _FORTIFY_SOURCE) is to avoid strncpy

@sxa
Copy link
Contributor

sxa commented Apr 15, 2019

@dnakamura What are the implications of modifying _FORTIFY_SOURCE?

@dnakamura
Copy link
Contributor

It adds extra checks to c string manipulation functions.

http://man7.org/linux/man-pages/man7/feature_test_macros.7.html :

_FORTIFY_SOURCE (since glibc 2.3.4)

Defining this macro causes some lightweight checks to be per formed to detect some buffer overflow errors when employing various string and memory manipulation functions (for example, memcpy(3),memset(3), stpcpy(3), strcpy(3), strncpy(3),strcat(3), strncat(3), sprintf(3), snprintf(3), vsprintf(3),vsnprintf(3), gets(3), and wide character variants thereof). For some functions, argument consistency is checked; for example, a check is made that open(2) has been supplied with a mode argument when the specified flags include O_CREAT. Not all problems are detected, just some common cases.

If _FORTIFY_SOURCE is set to 1, with compiler optimization level 1 (gcc -O1) and above, checks that shouldn't change the behavior of conforming programs are performed. With _FORTIFY_SOURCE set to 2, some more checking is added, but some conforming programs might fail.
Some of the checks can be performed at compile time (via macros logic implemented in header files), and result in compiler warnings; other checks take place at run time, and result in a run-time error if the check fails.

Use of this macro requires compiler support, available with gcc(1) since version 4.0.

@knn-k
Copy link
Contributor Author

knn-k commented Apr 16, 2019

Is it possible to add or change compiler options only for trclog.c?

@dnakamura
Copy link
Contributor

@knn-k

Is it possible to add or change compiler options only for trclog.c?

I think so, yes. I think this should work (although I haven't tested)

<makefilestubs>
    <makefilestub data="trclog.o: CFLAGS+=-U_FORTIFY_SOURCE"/>
</makefilestubs>

@knn-k
Copy link
Contributor Author

knn-k commented Apr 17, 2019

@dnakamura Thank you, it works. I apply it to #5508.

knn-k added a commit to knn-k/openj9 that referenced this issue Apr 17, 2019
This commit stops adding "-D_FORTIFY_SOURCE=1" to CFLAGS in
runtime/rastrace when the target platform is AArch64, in order to avoid
compile error with trclog.c.
With this change, "--disable-warnings-as-errors-openj9" can be removed
from the options for configure.

Fixes: eclipse-openj9#4486

Signed-off-by: knn-k <konno@jp.ibm.com>
LinHu2016 pushed a commit to LinHu2016/openj9 that referenced this issue Apr 22, 2019
This commit stops adding "-D_FORTIFY_SOURCE=1" to CFLAGS in
runtime/rastrace when the target platform is AArch64, in order to avoid
compile error with trclog.c.
With this change, "--disable-warnings-as-errors-openj9" can be removed
from the options for configure.

Fixes: eclipse-openj9#4486

Signed-off-by: knn-k <konno@jp.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants