public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/62259] New: atomic class doesn't enforce required alignment on powerpc64
@ 2014-08-25 20:06 saugustine at google dot com
  2014-09-03 12:25 ` [Bug libstdc++/62259] " uweigand at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: saugustine at google dot com @ 2014-08-25 20:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62259

            Bug ID: 62259
           Summary: atomic class doesn't enforce required alignment on
                    powerpc64
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: saugustine at google dot com

Created attachment 33396
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33396&action=edit
small reproducer

The attached short program results in a bus error on powerpc64 top of trunk at
-O0, but I believe is a bug that would be exposed on many targets, going back
at least to 4.9. 

It succeeds--probably by luck--on 4.8.

The key is that the atomic struct is eight-bytes in size, but only four byte
aligned, and gcc takes no care to subsequently align it. GCC chooses an ldarx
instruction, which requires eight-byte alignment.

Although https://gcc.gnu.org/wiki/Atomic/GCCMM/UnalignedPolicy doesn't directly
address this case, a careful reading leads me to believe that this is intended
to work.

My uneducated guess is that the template at <atomic>:189 should either use
&_M_i in calls to __atomic_is_lock_free (instead of nullptr) or should add
alignment as necessary. Not sure how that is intended to be done. If I fix
<atomic> to pass the pointer, then gcc chooses to call out to an atomic library
function, which gcc doesn't provide.

google ref b/17136920

g++ -std=c++11 t.cc -O0

#include <atomic>

struct twoints {
int a;
int b;
};

int main() {
  // unalign subsequent variables
  char b0 = 'a';
  twoints one = { 1 };
  twoints two = { 2 };
  std::atomic<twoints> a(one);
  twoints e = { 0 };

  a.compare_exchange_strong(e, two, std::memory_order_acq_rel);
  return 0;
}


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-04-03  3:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-25 20:06 [Bug libstdc++/62259] New: atomic class doesn't enforce required alignment on powerpc64 saugustine at google dot com
2014-09-03 12:25 ` [Bug libstdc++/62259] " uweigand at gcc dot gnu.org
2014-09-03 13:08 ` dje at gcc dot gnu.org
2014-09-03 15:50 ` redi at gcc dot gnu.org
2014-09-03 16:09 ` amacleod at redhat dot com
2015-02-24 18:27 ` ebotcazou at gcc dot gnu.org
2015-03-26 19:59 ` redi at gcc dot gnu.org
2015-03-26 20:19 ` redi at gcc dot gnu.org
2015-04-03  3:01 ` hp at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).