public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65255] New: std::thread does not work for cross compiling on ARM
@ 2015-02-28 22:54 yyc1992 at gmail dot com
  2015-02-28 23:49 ` [Bug c++/65255] " yyc1992 at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: yyc1992 at gmail dot com @ 2015-02-28 22:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65255
           Summary: std::thread does not work for cross compiling on ARM
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yyc1992 at gmail dot com

Created attachment 34903
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34903&action=edit
PKGBUILD used to compile the cross compiling version of gcc

Duplicate of the problem reported in the comment of #42734. However, IMHO, that
bug was tracking a different issue and it should be better to open a new bug
for this one although the error message produced at runtime are very similar.

See attached file for the script used to compile the cross-compiler
(CHOST=x86_64-unknown-linux-gnu).

Minimum source that produces the problem
```
#include <thread>

int
main()
{
    std::thread([] {}).join();
    return 0;
}
```

When compiling with `arm-linux-gnueabihf-g++` on x86_64 and run on arm, it
throws an runtime error

```
pure virtual method called
terminate called without an active exception
Aborted (core dumped)
```

However, the error disappeared if run with gdb....

The same source works on the host machine (x86_64), with clang cross compiling
on ARM and with both clang and gcc natively compiled on ARM. Adding `-latomic`
as suggested in #42734 does not help either and is also not needed using the
native compiler on arm.

Command line option used to compile:
gcc cross compile:
    arm-linux-gnueabihf-g++ -pthread -std=c++14 -Os -Wall -Wextra thread.cpp -o
thread-arm
clang cross compile:
    clang++ --target=arm-linux-gnueabihf -pthread -std=c++14 -Os -Wall -Wextra
thread.cpp -o thread-arm_clang -I
/usr/arm-linux-gnueabihf/include/c++/4.9.2/arm-linux-gnueabihf
gcc native compile (on ARM):
    g++ -pthread -std=c++14 -Os -Wall -Wextra thread.cpp -o thread-arm_native
clang native compile (on ARM):
    clang++ -pthread -std=c++14 -Os -Wall -Wextra thread.cpp -o
thread-arm_native_clang

I'll try to upload the binaries (if they are allowed) or the output of `objdump
-S` (if I cannot upload binaries).


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

* [Bug c++/65255] std::thread does not work for cross compiling on ARM
  2015-02-28 22:54 [Bug c++/65255] New: std::thread does not work for cross compiling on ARM yyc1992 at gmail dot com
@ 2015-02-28 23:49 ` yyc1992 at gmail dot com
  2015-08-11  7:13 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: yyc1992 at gmail dot com @ 2015-02-28 23:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Yichao Yu <yyc1992 at gmail dot com> ---
Created attachment 34904
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34904&action=edit
Source and output programs


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

* [Bug c++/65255] std::thread does not work for cross compiling on ARM
  2015-02-28 22:54 [Bug c++/65255] New: std::thread does not work for cross compiling on ARM yyc1992 at gmail dot com
  2015-02-28 23:49 ` [Bug c++/65255] " yyc1992 at gmail dot com
@ 2015-08-11  7:13 ` pinskia at gcc dot gnu.org
  2015-08-11 12:11 ` yyc1992 at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-08-11  7:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
arm-* defaults to earlier arm than v7 which does not have atomics in the ISA.

Your native compiler most likely defaulted to armv7 which uses the atomic
instructions directly.

Can you provide the output of gcc -v that you are running natively and most
likely see the default cpu/arch that is being selected.


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

* [Bug c++/65255] std::thread does not work for cross compiling on ARM
  2015-02-28 22:54 [Bug c++/65255] New: std::thread does not work for cross compiling on ARM yyc1992 at gmail dot com
  2015-02-28 23:49 ` [Bug c++/65255] " yyc1992 at gmail dot com
  2015-08-11  7:13 ` pinskia at gcc dot gnu.org
@ 2015-08-11 12:11 ` yyc1992 at gmail dot com
  2015-08-11 17:56 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: yyc1992 at gmail dot com @ 2015-08-11 12:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Yichao Yu <yyc1992 at gmail dot com> ---
Adding `-march=armv7-a` indeed fixes the issue. Thanks.

Does this mean that `std::thread` is not supported on armv6? Would be nice to
have a warning/error if it is possible to detect this.

FWIW, `clang -march=armv6` doesn't have this issue...


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

* [Bug c++/65255] std::thread does not work for cross compiling on ARM
  2015-02-28 22:54 [Bug c++/65255] New: std::thread does not work for cross compiling on ARM yyc1992 at gmail dot com
                   ` (2 preceding siblings ...)
  2015-08-11 12:11 ` yyc1992 at gmail dot com
@ 2015-08-11 17:56 ` redi at gcc dot gnu.org
  2015-08-11 18:00 ` redi at gcc dot gnu.org
  2015-08-11 18:04 ` yyc1992 at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2015-08-11 17:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's supported fine, but you need to compile your code that uses std::thread so
it is compatible with the libstdc++.so library you link to.

If libstdc++ is compiled to use atomic operations in shared_ptr then you need
to compile your code so it also uses atomics. If libstdc++ is compiled to use
mutexes in shared_ptr then you need to compile your code the same way.


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

* [Bug c++/65255] std::thread does not work for cross compiling on ARM
  2015-02-28 22:54 [Bug c++/65255] New: std::thread does not work for cross compiling on ARM yyc1992 at gmail dot com
                   ` (3 preceding siblings ...)
  2015-08-11 17:56 ` redi at gcc dot gnu.org
@ 2015-08-11 18:00 ` redi at gcc dot gnu.org
  2015-08-11 18:04 ` yyc1992 at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2015-08-11 18:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I have a patch for std::thread which would mean it doesn't use shared_ptr, so
this wouldn't be a problem even if you don't use the same arm version.


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

* [Bug c++/65255] std::thread does not work for cross compiling on ARM
  2015-02-28 22:54 [Bug c++/65255] New: std::thread does not work for cross compiling on ARM yyc1992 at gmail dot com
                   ` (4 preceding siblings ...)
  2015-08-11 18:00 ` redi at gcc dot gnu.org
@ 2015-08-11 18:04 ` yyc1992 at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: yyc1992 at gmail dot com @ 2015-08-11 18:04 UTC (permalink / raw)
  To: gcc-bugs

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

Yichao Yu <yyc1992 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #9 from Yichao Yu <yyc1992 at gmail dot com> ---
Thanks for the explaination.

> I have a patch for std::thread which would mean it doesn't use shared_ptr, so this wouldn't be a problem even if you don't use the same arm version.

I guess this might be the implementation detail that causes this to not happen
for clang but I agree in general finding the right version of library at
runtime is more of a distribution / system manager problem.


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

end of thread, other threads:[~2015-08-11 18:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-28 22:54 [Bug c++/65255] New: std::thread does not work for cross compiling on ARM yyc1992 at gmail dot com
2015-02-28 23:49 ` [Bug c++/65255] " yyc1992 at gmail dot com
2015-08-11  7:13 ` pinskia at gcc dot gnu.org
2015-08-11 12:11 ` yyc1992 at gmail dot com
2015-08-11 17:56 ` redi at gcc dot gnu.org
2015-08-11 18:00 ` redi at gcc dot gnu.org
2015-08-11 18:04 ` yyc1992 at gmail dot com

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).