Bug 1668631 - -march=native is broken on aarch64
Summary: -march=native is broken on aarch64
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-01-23 08:38 UTC by Elliott Sales de Andrade
Modified: 2019-02-13 10:13 UTC (History)
11 users (show)

Fixed In Version: gcc-9.0.1-0.1.fc30
Clone Of:
Environment:
Last Closed: 2019-01-24 15:38:54 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 89014 0 None None None 2019-02-13 09:47:36 UTC

Description Elliott Sales de Andrade 2019-01-23 08:38:08 UTC
Description of problem:
Building xtl on aarch64 [1] fails because of some kind of issue with gcc's handling of -march=native; there seems to be a buffer overflow.



Version-Release number of selected component (if applicable):
9.0.0-0.4.fc30.aarch64


Actual results:
/usr/bin/c++  -DHAVE_NLOHMANN_JSON -I/builddir/build/BUILD/xtl-0.5.3/include  -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fasynchronous-unwind-tables -fstack-clash-protection -DNDEBUG   -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion -march=native -std=gnu++14 -o CMakeFiles/test_xcomplex_sequence.dir/test_xcomplex_sequence.cpp.o -c /builddir/build/BUILD/xtl-0.5.3/test/test_xcomplex_sequence.cpp
BUILDSTDERR: Assembler messages:
BUILDSTDERR: Error: unknown architecture `armv8-a�^&'
BUILDSTDERR: Error: unrecognized option -march=armv8-a�^&
BUILDSTDERR: cc1plus: error: unknown value 'armv8-\xf0^\x17' for -march
BUILDSTDERR: cc1plus: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a native; did you mean 'armv8-a'?


Expected results:
Should compile.


Additional info:
[1] https://koji.fedoraproject.org/koji/taskinfo?taskID=32203946

Comment 1 Jakub Jelinek 2019-01-23 08:41:27 UTC
Will try to have a look if I manage to reproduce, for these issues one needs the same CPU...

Anyway, using -march=native in the distro is an extremely bad idea, native is when you want to optimize and target your own CPU.
We have different builders in koji, and then different sets of CPUs we do support as the distro, so if the code depends on whatever builder was choosen and will not run on earlier CPUs or will not be optimized for earlier CPUs, it is a major bug.

Comment 2 Elliott Sales de Andrade 2019-01-23 08:43:20 UTC
It's a header-only library and this is just building tests, so I don't really care about native build in the package.

For this package, there's also something broken with the string code tests on ppc64le and armv7hl [1]. It doesn't occur on Fedora 29 [2]. I'm not yet sure if it's a bug related to this buffer overflow or something wrong in the package itself.

[1] https://koji.fedoraproject.org/koji/taskinfo?taskID=32203917
[2] https://koji.fedoraproject.org/koji/buildinfo?buildID=1181587

Comment 3 Jonathan Wakely 2019-01-23 11:02:04 UTC
(In reply to Elliott Sales de Andrade from comment #2)
> It's a header-only library and this is just building tests, so I don't
> really care about native build in the package.

Why bother using -march=native at all then?

Comment 4 Dave Malcolm 2019-01-23 14:00:50 UTC
I haven't tried to reproduce on actual hardware, but this code in driver-aarch64.c looks suspicious to me:

   351	  ext_string
   352	    = aarch64_get_extension_string_for_isa_flags (extension_flags,
   353							  default_flags).c_str ();
   354	
   355	  res = concat (res, ext_string, NULL);

as presumably the underlying std::string returned by aarch64_get_extension_string_for_isa_flags only lives until after the call to c_str, and thus is destroyed, and so the buffer pointed to by const char *ext_string has become invalid at line 355.

Comment 5 Jakub Jelinek 2019-01-23 14:08:59 UTC
Yeah.  So
  {
    std::string extension
      = aarch64_get_extension_string_for_isa_flags (extension_flags, default_flags);
    res = concat (res, extension.c_str (), NULL);
  }
?  Anyway, David, can you please file an upstream PR, attach your patch for it there and submit?

Comment 6 Dave Malcolm 2019-01-23 15:43:21 UTC
Reproduced and filed upstream as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89014

Comment 7 Dave Malcolm 2019-01-23 16:26:12 UTC
I've posted a patch upstream:
  https://gcc.gnu.org/ml/gcc-patches/2019-01/msg01381.html
though note that it appears to also need:
  https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01302.html

Reassigning this downstream bug.

Comment 8 Jakub Jelinek 2019-01-24 15:38:54 UTC
Should be fixed in rawhide.

Comment 9 Elliott Sales de Andrade 2019-02-13 10:13:54 UTC
(In reply to Jonathan Wakely from comment #3)
> (In reply to Elliott Sales de Andrade from comment #2)
> > It's a header-only library and this is just building tests, so I don't
> > really care about native build in the package.
> 
> Why bother using -march=native at all then?

Because it's in upstream and there's been no reason to patch it. And for the record, the tests still fail on Rawhide, but not 28/29, even without -march=native: https://koji.fedoraproject.org/koji/taskinfo?taskID=32773832


Note You need to log in before you can comment on or make changes to this bug.