Wind River Support Network

HomeDefectsLIN1018-6482
Not to be fixed

LIN1018-6482 : GCC fails to perform byte swapping when compiling application with -O2 (works correctly for -O0 and -O1)

Created: Jul 20, 2020    Updated: Aug 12, 2021
Resolved Date: Aug 12, 2021
Found In Version: 10.18.44.17
Severity: Standard
Applicable for: Wind River Linux LTS 18
Component/s: Toolchain

Description

Customer reported a problems with GCC skipping an expected host-to-network byte swap when building with -O2. This does not happen with -O1 or -O0.

---We were able to reproduce with a simple testcode (see attached + Steps to reproduce) :

Make the project.
make OPT=N
• N = 0 -> All three tests pass
• N = 1 -> All three tests pass
• N = 2 -> First two tests pass, third test fails.

Run the app.
$ ./par_test Test 0: Passed Test 1: Passed Test 2: Failed

—

This test consists of a main program that invokes three very similar functions. All three functions use proper C++ standard code as far as I know. The functions are located in the file phase.cpp and when casting pointers of unlike types the cast is done to and from a char* variable so this should be acceptable based on alias rules.

There is a very odd failure in the last function.

The use of the variable LocalCDPDef in the call CalculateDataLocation(LocalCDPDef) causes an incorrect result in the if test above the CalculateDataLocation() call that also uses the variable LocalCDPDef!

Why?

Note that it appears the member ParamCode of LocalCDPDef is a class that should do byte swapping when used. In the third function, this byte swapping does not appear to occur.

Steps to Reproduce

{{.}}{{/wrlinux-x/setup}}{{.sh --machines xilinx-zynq --templates template}}{{/initramfs}}

{{Add 'cpio.gz'}}{{ to IMAGE_FSTYPES in local.conf}}

bitbake wrlinux-image-glibc-small  (or -std)

{{bitbake -c do_populate_sdk wrlinux-image-glibc-small  }}{{(or -std)}}

Extract the SDK :  ./tmp-glibc/deploy/sdk/wrlinux-small-10.18.44.17-glibc-x86_64-xilinx_zynq-wrlinux-image-glibc-small-sdk.sh

Source the SDK : source environment-setup-armv7at2hf-neon-wrs-linux-gnueabi

cd attached_testcode (gcc_defect)

compile application
 edit makefile, change SDK and ROOT accordingly (Where ROOT is the directory that has the sysroots folder in the SDK)

Change OPT to 0, 1 and 2 accordingly  : OPT ?= 0  

make  the project :

make OPT=N

• N = 0 -> All three tests pass

• N = 1 -> All three tests pass

• N = 2 -> First two tests pass, third test fails.

load the obj folder to the target and run the app.

$ ./par_test Test 0: Passed Test 1: Passed Test 2: Failed

 
Live chat
Online