Wrong sha256 sum on ppc64el (compiled with -O3)

Bug #2033405 reported by Benjamin Drung
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
The Ubuntu-power-systems project
New
High
bugproxy
dcfldd (Ubuntu)
Fix Released
High
Unassigned
gcc-13 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

dcfldd 1.9.1-1 on ppc64el produces a wrong sha256 sum:

```
$ dpkg -s dcfldd | grep ^Version
$ dcfldd if=debian/tests/test.txt of=/tmp/test2.txt hash=md5,sha1,sha256,sha384,sha512

Total (md5): 92994b0ce292a217e3e3bc31b639e565

Total (sha1): bc0e4b74695142e0a0bdae87aea310d7078866cb

Total (sha256): b0041d27f7429be0d371dd1ff3eb5c7f4385f71e64757344631f84d15026ee5c

Total (sha384): 53b8374607a8258de4173265bfbfa6120093fd42090a92fd589cf2c6c16b4e421b5135777714976713f7949715720a83

Total (sha512): 969a39bf47b5f12d81121084f19cb5ae250e0c0ea5b7c6d82cf08131acde8e1955d137612c2f6b255e25b0e28f96f93586f90f06965cb8f719ed7fbdd95cc8d4

0+1 records in
0+1 records out
$ sha256sum /tmp/test2.txt
02fd428a4671925e4ca61541b9fac648f4ccdccad65602bfd3256ba14e59489c /tmp/test2.txt
```

dcfldd 1.7.1-1 creates the correct sha256 sum.

The package built on 2023-06-13 with gcc 12.3.0-1ubuntu1 and a local built on 2023-09-04 with gcc 13.2.0-2ubuntu1 are affected.

Revision history for this message
Benjamin Drung (bdrung) wrote :

* Rebuilding dcfldd 1.7.1-1 on mantic produces the same test failure.
* Building with "export CC=gcc-12" (instead of gcc-13) results in a test failure as well.
* Using the dcfldd 1.9.1-1 binary built on Debian worked.
* Rebuilding dcfldd 1.9.1-1 on a Debian ppc64el porter box worked there.

Changed in dcfldd (Ubuntu):
status: New → Triaged
importance: Undecided → High
Revision history for this message
Benjamin Drung (bdrung) wrote :

Tested different compiler flags. -O2 works correctly but -O3 fails:

```
./autogen.sh
./configure CFLAGS="-O3"
make
```

Benjamin Drung (bdrung)
summary: - Wrong sha256 sum on ppc64el
+ Wrong sha256 sum on ppc64el (compiled with -O3)
Revision history for this message
Matthias Klose (doko) wrote :

is this specific to the architecture, or -O2/-O3?

Revision history for this message
Benjamin Drung (bdrung) wrote :

I checked the build logs and only ppc64el is building dcfldd with -O3.

I modified debian/rules and built dcfldd 1.9.1-1 on amd64 mantic (gcc 13.2.0-3ubuntu1):

```
export DEB_CFLAGS_MAINT_APPEND = -O3
export DEB_CFLAGS_MAINT_STRIP = -O2
```

The autopkgtest on amd64 succeeded. This indicates that this bug in architecture specific.

Benjamin Drung (bdrung)
description: updated
Revision history for this message
Benjamin Drung (bdrung) wrote :

The autopkgtest on ppc64el still fails when disabling LTO and only using -O3 (add " optimize=-lto" to DEB_BUILD_MAINT_OPTIONS).

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

This bug was fixed in the package dcfldd - 1.9.1-1ubuntu1

---------------
dcfldd (1.9.1-1ubuntu1) noble; urgency=medium

  * Build with -O2 on ppc64el to avoid autopkgtest failure
    (LP: #2033405)

 -- Graham Inggs <email address hidden> Mon, 08 Jan 2024 11:34:00 +0000

Changed in dcfldd (Ubuntu):
status: Triaged → Fix Released
Frank Heimes (fheimes)
Changed in ubuntu-power-systems:
assignee: nobody → bugproxy (bugproxy)
tags: added: ppc64el
Changed in ubuntu-power-systems:
importance: Undecided → High
Revision history for this message
Benjamin Drung (bdrung) wrote :

Tested on Debian unstable on ppc64el (with gcc 13.2.0-9) with -O3 and it is affected as well:

```
ssh platti.debian.org
$ session=$(schroot -c sid -b)
$ dd-schroot-cmd -c $session apt-get update
$ dd-schroot-cmd -c $session apt-get build-dep dcfldd
$ schroot -c $session -r
sid_ppc64el-dchroot$ apt source dcfldd
sid_ppc64el-dchroot$ cd dcfldd-1.9.1/
sid_ppc64el-dchroot$ vim debian/rules
# add: export DEB_CFLAGS_MAINT_APPEND=-O3
sid_ppc64el-dchroot$ dpkg-buildpackage -b
sid_ppc64el-dchroot$ ./src/dcfldd if=debian/tests/test.txt of=/tmp/test2.txt hash=md5,sha1,sha256,sha384,sha512

Total (md5): 92994b0ce292a217e3e3bc31b639e565

Total (sha1): bc0e4b74695142e0a0bdae87aea310d7078866cb

Total (sha256): b0041d27f7429be0d371dd1ff3eb5c7f4385f71e64757344631f84d15026ee5c

Total (sha384): 53b8374607a8258de4173265bfbfa6120093fd42090a92fd589cf2c6c16b4e421b5135777714976713f7949715720a83

Total (sha512): 969a39bf47b5f12d81121084f19cb5ae250e0c0ea5b7c6d82cf08131acde8e1955d137612c2f6b255e25b0e28f96f93586f90f06965cb8f719ed7fbdd95cc8d4

0+1 records in
0+1 records out
```

Revision history for this message
Benjamin Drung (bdrung) wrote :

Verified that amd64 is not affected:

```
$ schroot-wrapper -p debhelper,bash-completion,vim -c noble
$ apt source dcfldd
$ cd dcfldd-1.9.1/
$ vim debian/rules
# add: export DEB_CFLAGS_MAINT_APPEND=-O3
$ dpkg-buildpackage -b
$ ./src/dcfldd if=debian/tests/test.txt of=/tmp/test2.txt hash=md5,sha1,sha256,sha384,sha512

Total (md5): 92994b0ce292a217e3e3bc31b639e565

Total (sha1): bc0e4b74695142e0a0bdae87aea310d7078866cb

Total (sha256): 02fd428a4671925e4ca61541b9fac648f4ccdccad65602bfd3256ba14e59489c

Total (sha384): 53b8374607a8258de4173265bfbfa6120093fd42090a92fd589cf2c6c16b4e421b5135777714976713f7949715720a83

Total (sha512): 969a39bf47b5f12d81121084f19cb5ae250e0c0ea5b7c6d82cf08131acde8e1955d137612c2f6b255e25b0e28f96f93586f90f06965cb8f719ed7fbdd95cc8d4

0+1 records in
0+1 records out
```

bugproxy (bugproxy)
tags: added: architecture-ppc64le bugnameltc-204601 severity-medium targetmilestone-inin---
bugproxy (bugproxy)
tags: added: targetmilestone-inin2404
removed: targetmilestone-inin---
Matthias Klose (doko)
tags: removed: update-excuse
Revision history for this message
bugproxy (bugproxy) wrote : Comment bridged from LTC Bugzilla

------- Comment From <email address hidden> 2024-04-10 16:19 EDT-------
Confirmed. This seems to fail for gcc12 and later and passes for gcc11 and earlier. I have confirmed that the source file that is mis-compiled is src/sha2.c.
Compiling the entire package with -O2 and sha2.c with -O3 shows the error, as well as compiling the entire package with -O3 and sha2.c with -O2 it passes.

Given we have a known good gcc version and a known bad version, we should be able to git bisect gcc to identify the commit that causes the failure.

Revision history for this message
bugproxy (bugproxy) wrote :

------- Comment From <email address hidden> 2024-04-10 18:42 EDT-------
Doing a git bisect, it identified the following GCC commit as causing the bug:

64f3e71c302b4a13e61656ee509e7050b9bce978 is the first bad commit
commit 64f3e71c302b4a13e61656ee509e7050b9bce978
Author: Jan Hubicka <email address hidden>
Date: Sun Nov 14 18:49:15 2021 +0100

Extend modref to track kills

This patch adds kill tracking to ipa-modref. This is representd by array
of accesses to memory locations that are known to be overwritten by the
function.

gcc/ChangeLog:

2021-11-14 Jan Hubicka <email address hidden>

* ipa-modref-tree.c (modref_access_node::update_for_kills): New
member function.
(modref_access_node::merge_for_kills): Likewise.
(modref_access_node::insert_kill): Likewise.
* ipa-modref-tree.h (modref_access_node::update_for_kills,
modref_access_node::merge_for_kills, modref_access_node::insert_kill):
Declare.
(modref_access_node::useful_for_kill): New member function.
* ipa-modref.c (modref_summary::useful_p): Release useless kills.
(lto_modref_summary): Add kills.
(modref_summary::dump): Dump kills.
(record_access): Add mdoref_access_node parameter.
(record_access_lto): Likewise.
(merge_call_side_effects): Merge kills.
(analyze_call): Add ALWAYS_EXECUTED param and pass it around.
(struct summary_ptrs): Add always_executed filed.
(analyze_load): Update.
(analyze_store): Update; record kills.
(analyze_stmt): Add always_executed; record kills in clobbers.
(analyze_function): Track always_executed.
(modref_summaries::duplicate): Duplicate kills.
(update_signature): Release kills.
* ipa-modref.h (struct modref_summary): Add kills.
* tree-ssa-alias.c (alias_stats): Add kill stats.
(dump_alias_stats): Dump kill stats.
(store_kills_ref_p): Break out from ...
(stmt_kills_ref_p): Use it; handle modref info based kills.

gcc/testsuite/ChangeLog:

2021-11-14 Jan Hubicka <email address hidden>

* gcc.dg/tree-ssa/modref-dse-3.c: New test.

gcc/ipa-modref-tree.c | 179 +++++++++++++++++++++++
gcc/ipa-modref-tree.h | 15 ++
gcc/ipa-modref.c | 126 +++++++++++++---
gcc/ipa-modref.h | 1 +
gcc/testsuite/gcc.dg/tree-ssa/modref-dse-3.c | 22 +++
gcc/tree-ssa-alias.c | 207 +++++++++++++++++++--------
6 files changed, 471 insertions(+), 79 deletions(-)

Revision history for this message
bugproxy (bugproxy) wrote :

------- Comment From <email address hidden> 2024-04-11 14:47 EDT-------
This has been reported in the FSF GCC bugzilla here:

https://gcc.gnu.org/PR114698

Revision history for this message
bugproxy (bugproxy) wrote :

------- Comment From <email address hidden> 2024-04-11 15:57 EDT-------
The upstream bugzilla has been closed as INVALID (ie, not a GCC bug). The problem was tracked down to an aliasing violation in the sha2.c source file. It seems the sha2.c file from dcfldd is shared among many different software packages and some of those packages have already detected the bug and fixed it. I verified the same patch fixes the issue reported here.

There are links to the sha2.c fix mentioned in the GCC bugzilla that the dcfldd project should pick up.

Talking with Sam James from Gentoo on IRC, he said he would work with the dcfldd project to get the fix picked up there.

------- Comment From <email address hidden> 2024-04-11 15:57 EDT-------
Closing as not a GCC bug.

Revision history for this message
Peter Bergner (pbergner) wrote :

A pull request of an upstream fix to the dcfldd project has been submitted:

  https://github.com/resurrecting-open-source-projects/dcfldd/pull/24

Revision history for this message
Benjamin Drung (bdrung) wrote :

Thanks. I have taken the patch from https://github.com/resurrecting-open-source-projects/dcfldd/pull/24 and applied it to the Ubuntu package.

Changed in gcc-13 (Ubuntu):
status: New → Invalid
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.