Forwarding this message to the linaro toolchain list instead. I am not the person who should be supporting the Linaro ODP project with GCC questiosn; the toolchain team inside Linaro should be instead.
Thanks,
Andrew Pinski
________________________________________
From: Ola Liljedahl <ola.liljedahl(a)linaro.org>
Sent: Monday, November 24, 2014 2:31 PM
To: lng-odp(a)lists.linaro.org; Pinski, Andrew
Subject: strange behavior in GCC for use of uninitialized variables
Consider the following code fragment (from real life):
#include <stdint.h>
typedef volatile uint32_t odp_atomic_u32_t;
static inline uint32_t odp_atomic_fetch_inc_u32(odp_atomic_u32_t *ptr)
{
return __sync_fetch_and_add(ptr, 1);
}
static inline void odp_spin(void)
{
#ifdef __SSE2__
__asm__ __volatile__ ("pause");
#else
__asm__ __volatile__ ("rep; nop");
#endif
}
typedef struct {
int count;
odp_atomic_u32_t bar;
} odp_barrier_t;
void odp_barrier_wait(odp_barrier_t *barrier)
{
uint32_t count;
int wasless;
// wasless = barrier->bar < barrier->count; <<<lost on git add -p
__atomic_thread_fence(__ATOMIC_SEQ_CST);
count = odp_atomic_fetch_inc_u32(&barrier->bar);
if (count == 2*barrier->count-1) {
barrier->bar = 0;
} else {
while ((barrier->bar < barrier->count) == wasless)
odp_spin();
}
__atomic_thread_fence(__ATOMIC_SEQ_CST);
}
While fixing and cleaning up this code, the indicated line that
initializes 'wasless' was dropped (because it reappears in a later
patch in the patch set after the odp_atomic_fetch_inc call). To my
surprise, GCC did not complain when compiling this file (using -O2
-Wall). But it does complain when compiling with -O0 -Wall. With some
investigation, it seems like GCC understands that if a statement does
not have any side effects so it can optimize away everything,
including the usage of the uninitialized variable and thus also the
corresponding warning.
olli@macmini:~/hacking/gcc-wunit$ gcc -O2 -Wall -c odp_barrier.c
olli@macmini:~/hacking/gcc-wunit$ gcc -O0 -Wall -c odp_barrier.c
odp_barrier.c: In function ‘odp_barrier_wait’:
odp_barrier.c:42:9: warning: ‘wasless’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
while ((barrier->bar < barrier->count) == wasless)
^
However the proper code seems to be generated in both cases (there is
a "pause" instruction inlined or a call to odp_spin). So odp_spin() is
not without side effects and is not optimized away. This contradicts
my hypothesis.
Consider this minimalistic example:
olli@macmini:~/hacking/gcc-wunit$ cat wunit.c
#include <stdlib.h>
void test(void)
{
int wasless;
int wasmore;
if (wasless) (void)0;
if (wasmore) abort();
}
olli@macmini:~/hacking/gcc-wunit$ gcc -O0 -Wall -c wunit.c
wunit.c: In function ‘test’:
wunit.c:9:5: warning: ‘wasmore’ is used uninitialized in this function
[-Wuninitialized]
if (wasmore) abort();
^
olli@macmini:~/hacking/gcc-wunit$ gcc -O2 -Wall -c wunit.c
wunit.c: In function ‘test’:
wunit.c:9:5: warning: ‘wasmore’ is used uninitialized in this function
[-Wuninitialized]
if (wasmore) abort();
^
Here GCC warns when used with both -O0 and -O2 but only for the usage
where there is a side effect. The use of 'wasless' that does not lead
to any side-effects is ignored (and possibly rightly so, I can imagine
this is undefined behavior, fortunately I did not attempt to run this
program or my computer could have melted).
It is a bit worrying to me that instances of use of initialized
variables is sometimes missed by GCC. Both because of lack of
diagnostics for what is most likely a bug but also because I don't
understand why GCC does this and the implications of that (at least it
is a known unknown now).
-- Ola
cbuild2/ABE benchmarking - TCWG-360 [1/10]
* Attempted to use LAVA for benchmarks
** Fell over on lack of TCWG machines in same network
libm exercising - TCWG-558 [6/10]
* Much fiddling with chroots
* Some fiddling with benchfft
* Little actual progress
Meetings/mail/etc - [3/10]
=Plan=
libm exercising
* Run benchfft in chroots
* Investigate Graph500
* Validate existing results with consistent methodology
** Hopefully this is reaching the point of handle-turning
ABE benchmarking
* Port 'cbuild2' benchmarking to ABE repository
* Test ABE benchmarking in TCWG lab (and LAVA?)
* Test repeatability (assuming the above go well)
* Get storage/automation started, if Rob has time
Holiday *next* week (Tuesday and Wednesday, perhaps Monday as well)
== Progress ==
* Building an ILP32 toolchain for AArch64 (4/10, TCWG-559)
- Applied a few simple ILP32 patches to glibc
- Rebasing and reworking existing ILP32 glibc patches
* LLD for ARM and AArch64 (5/10)
- Submit first set of reloc cleanups for LLVM
* Email, meetings, etc. (1/10)
== Issues ==
* None
== Plan ==
* Submit more ILP32 patches for glibc
* Further LLVM/LLD changes
--
Will Newton
Toolchain Working Group, Linaro
The Linaro Toolchain and Platform Working Groups are pleased to
announce the 2013.07 release of the Linaro Toolchain Binaries, a
pre-built version of Linaro GCC and Linaro GDB that runs on generic
Linux or Windows and targets the glibc Linaro Evaluation Build.
Uses include:
* Cross compiling ARM applications from your laptop
* Remote debugging
* Build the Linux kernel for your board
What's included:
* Linaro GCC 4.8 2013.07-1
* Linaro Newlib 2.0 2013.06
* Linaro Binutils 2.23 2013.06
* Linaro Eglibc 2.17-2013.07-2
* Linaro GDB 7.6 2013.05
* A statically linked gdbserver
* A system root
* Manuals under share/doc/
The system root contains the basic header files and libraries to link
your programs against.
Interesting changes include:
* The sysroot is based on Linaro versions of Eglibc. About details of
Linaro Eglibc, please refer
https://releases.linaro.org/13.07/components/toolchain/eglibc-linaro.
The Linux version is supported on Ubuntu 10.04.3 and 12.04, Debian
6.0.2, Fedora 16, openSUSE 12.1, Red Hat Enterprise Linux Workstation
5.7 and later, and should run on any Linux Standard Base 3.0
compatible distribution. Please see the README about running on x86_64
hosts.
The Windows version is supported on Windows XP Pro SP3, Windows Vista
Business SP2, and Windows 7 Pro SP1.
The binaries and build scripts are available from:
https://launchpad.net/linaro-toolchain-binaries/trunk/2013.07
Need help? Ask a question on https://ask.linaro.org/
Already on Launchpad? Submit a bug at
https://bugs.launchpad.net/linaro-toolchain-binaries
On IRC? See us on #linaro on Freenode.
Other ways that you can contact us or get involved are listed at
https://wiki.linaro.org/GettingInvolved.
Know issues:
* Some version information in README are incorrect.
* gdb can not backtrace into libc.
Notes:
* To use all of the features of Linaro eglibc, the sysroot in 32-bit
toolchain release is updated to Linaro eglibc, which is 2.17. If you
get runtime errors about libc version, please get the sysroot from the
release tarball
(gcc-linaro-arm-linux-gnueabihf-4.8-2013.07-1_linux/arm-linux-gnueabihf/libc/)
or download from launchpad
https://launchpad.net/linaro-toolchain-binaries/support/01/+download/linaro…
If you do not want to use Linaro sysroot, you'd add option to gcc to
find your sysroot:
--sysroot=<directory>
* To run 32-bit application built from arm-linux-gnueabihf toolchain
in aarch64 system, you'd copy sysroot and runtime from release package
to your root of aarch64 system. i,e.
scp -r gcc-linaro-arm-linux-gnueabihf-4.8-2013.07-1_linux/arm-linux-gnueabihf/libc/*
AARCH64-SYSTEM:/
scp -r gcc-linaro-arm-linux-gnueabihf-4.8-2013.07-1_runtime/* AARCH64-SYSTEM:/
== Issues ==
* none.
== Progress ==
* GCC 4.9 2014.12 (2/10)
- Back on Backports.
- Around 30 revisions backported are under review.
* AArch64 libunwind/ptrace (6/10)
- Remote unwinding is not working because of a wrong ptrace invocation.
- Implement registers access with PTRACE_GETREGSET
* Misc: (2/10)
- GCC git mirror migration.
- Various meetings.
== Plan ==
* Backports
* Libunwind
== This week ==
* GCC Modularization Project (7/10)
- Flattening header files
- Submitted gimple-streamer.h, tree-streamer.h, lto-streamer.h
patches to gcc-patches list
- tree-core.h
- Several rounds of changes based on review and bootstraps
- final fifty target bootstrap in progress
- df.h
- Initial round of changes
- cfgloop.h
- Initial patch created by Parthamesh
* Bug fixing (2/10)
- Investigation of bug 539 - .LTHUNK symbols are surviving
* Misc (1/10)
- Conference calls
- Worked with Prathamesh to bootstrap him on GCC modularization project
== Next week ==
- Submit tree-core.h patches
- Complete df.h pathces
- Review Prathamesh's patches to cfgloop.h
- Thanksgiving holiday, November 27-28
== Progress ==
* Zero/sign extension elimination with widening types (2/10)
- Addressing comments from the review
* Improve block memory operations by GCC (TCWG-142 - 3/10)
-Looked at ARM vs AArch64
* BUG #880 (3/10)
- Analysed tree dumps.
- Updated bug report with the findings.
* MISC (2/10)
- Looked at git and stg documents
== Plan ==
* Continue with Zero/sign extension.
== Planned Leave ==
* 27/11/2014 to 28/11/2014 - 2 days
* 11/12/2014 to 24/12/2014 - 10 days
== Progress ==
Environment setup, installations, board setup etc [4/10]
-- Prepared a local dev machine to work with in absence of lab.
-- Prepare panda board for gdb on android testing.
-- Figure out SSH failure issues with gdb testsuite runs.
-- Try out foundation model for android testing.
-- Getting to know CBuildv2 tried to set it up locally.
On travel to submit Hong Kong visa application [5/10]
Miscellaneous [1/10]
-- Meetings, Emails etc
== Plan ==
Try android boot with foundation model some more and hope that it works.
Resume AArch64 work with lab availability.
Review and update GDB related cards.
== Progress ==
bug #403/418 [5/10]
. submitted partial patch to list for core fix for Aarch64
. needs reworking of expansion for a bunch of builtins + corresponding patterns
. discussion/review of related upstream patches
bug #868 - brief investigation [1/10]
Misc [4/10]
== Plan ==
On holiday on Friday and following Monday morning