GCC 12: Target specific option mismatch when inlining memcpy call
While trying to install the Haskell Text package using cabal I ran into the following error:
In file included from /usr/include/c++/12.1.1/cstring:42,
from simdutf.h:7,
from simdutf.cpp:4:
/usr/include/fortify/string.h: In function 'size_t simdutf::scalar::{anonymous}::utf16_to_utf8::convert_valid(const char16_t*, size_t, char*)':
/usr/include/fortify/string.h:39:27: error: inlining failed in call to 'always_inline' 'void* memcpy(void*, const void*, size_t)': target specific option mismatch
39 | _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n)
| ^~~~~~
simdutf.cpp:8578:15: note: called from here
8578 | ::memcpy(&v, data + pos, sizeof(uint64_t));
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This can be reproduced outside cabal with the following commands:
$ git clone https://github.com/haskell/text
$ git checkout 8f3c3fb577ba3d06849edfa4b92af0e36f0ec00f
$ cd simdutf
$ g++ -O2 -std=c++17 -c simdutf.cpp
Observations:
- This seems to be a regression introduced with the GCC 12 upgrade since the code compiled fine prior to that
- The issues disappears when compiling the code with
-march=native
, e.g.g++ -O2 -march=native -std=c++17 -c simdutf.cpp
Reporting this here to gather more information.
Furthermore, since Text is a popular Haskell package, this will cause us issues when rebuilding software like pandoc
in the future.
Potentially related: #13735
Edited by Sören Tempel