simple C++ program exhibits data corruption when compiled with -fstrict-aliasing

Bug #1383334 reported by Miklos Reiter
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
gcc-4.8-armhf-cross (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

When cross-compiled using the command line:
$ arm-linux-gnueabihf-g++-4.8 -fPIC -o armGccBugTest armGccBugTest.cpp -std=c++11 -Wall -O2
the attached program generates the incorrect output:
# clobbered_pair: 0x00000000, 0x00000000
# clobbered_pair: 0x88888888, 0x44444444

The correct output is:
# clobbered_pair: 0x00000000, 0x00000000
# clobbered_pair: 0x00000000, 0x00000000
This is produced as expected when compiling with:
$ arm-linux-gnueabihf-g++-4.8 -fPIC -o armGccBugTest armGccBugTest.cpp -std=c++11 -Wall -O2 -fno-strict-aliasing
(Also, compiling to the native x86-64 architecture using g++-4.8 produces correct output using either optimization settings.)

The data from the ticks_t instance created on line 33 ends up overwriting the temporary pair_t() passed in the fourth argument to print_clobbered_pair(). Inspecting the disassembled code of the main function, it seems that the compiler attempts to re-use the temporary default-constructed pair_t() created on line 31 for the second call to print_clobbered_pair() on line 34. However, the memory location on the stack has been overwritten with the ticks_t instance created on line 33.

(We have reduced the problem to the attached minimal test case from a much more complicated system. Details such as the seemingly unnecessary user-defined copy constructor of the struct ticks_t or the unused arguments of the function print_clobbered_pair() are essential to reproducing the problem.)

ProblemType: Bug
DistroRelease: Ubuntu 14.04
Package: g++-4.8-arm-linux-gnueabihf 4.8.2-16ubuntu4cross0.11
ProcVersionSignature: Ubuntu 3.13.0-37.64-generic 3.13.11.7
Uname: Linux 3.13.0-37-generic x86_64
ApportVersion: 2.14.1-0ubuntu3.5
Architecture: amd64
CurrentDesktop: X-Cinnamon
Date: Mon Oct 20 15:15:20 2014
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_GB.UTF-8
 SHELL=/bin/bash
SourcePackage: gcc-4.8-armhf-cross
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Miklos Reiter (miklos-reiter) wrote :
Revision history for this message
Miklos Reiter (miklos-reiter) wrote :

I have re-submitted this bug report to the Linaro bug tracker:
https://bugs.linaro.org/show_bug.cgi?id=933

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gcc-4.8-armhf-cross (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.