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

            Bug ID: 119627
           Summary: arm-linux-gnueabihf-g++-12 on Intel generates
                    incorrect code
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc.gnu.org at pileofstuff dot org
  Target Milestone: ---

Created attachment 60996
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60996&action=edit
Cross- and locally-compiled .ii files

When cross-compiling on an Intel PC for a Raspberry Pi (armhf),
std::filesystem::directory_iterator generates many memory errors.
The same code works when compiled locally.

The steps below use `-O1`.  `-O2` causes the same problem,
but cross-compiling with `-O0` generates a binary that dies with:

./cross-compiled: symbol lookup error: ./cross-compiled: undefined symbol:
_ZNSt12__shared_ptrINSt10filesystem7__cxx114_DirELN9__gnu_cxx12_Lock_policyE2EEC1EOS5_,
version GLIBCXX_3.4.26

I assume that's an unrelated error, and it's easily worked around
by not cross-compiling with `-O0`.

The attached tarball contains `.ii` files generated on Intel and on the Pi.
Apologies for the bzip archive - each file is larger than the 1000KB limit.

# STEPS TO REPLICATE


1. cross-compile the following program on an Intel PC
   (I used a Debian pbuilder bookworm environment):

arm-linux-gnueabihf-g++-12 -Wall -Wextra -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_DEBUG
-save-temps -O1 -x c++ -o cross-compiled - <<EOF
#include <filesystem>
int main() {
  std::filesystem::directory_iterator di{"/tmp/test"};
  for (const auto& entry: di) {
    auto path = entry.path();
  }
  return 0;
}
EOF


2. Copy `cross-compiled` to a Raspberry Pi 3B+


3. compile the same program locally on the Pi:

arm-linux-gnueabihf-g++-12 -Wall -Wextra -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_DEBUG
-save-temps -O1 -x c++ -o locally-compiled - <<EOF
#include <filesystem>
int main() {
  std::filesystem::directory_iterator di{"/tmp/test"};
  for (const auto& entry: di) {
    auto path = entry.path();
  }
  return 0;
}
EOF


4. create a test environment:

rm -rf /tmp/test
mkdir /tmp/test
touch /tmp/test/path


5. run both commands in valgrind:

valgrind ./locally-compiled
valgrind ./cross-compiled


# OUTPUT

Expected: both commands print output like the following:

==6200== Memcheck, a memory error detector
==6200== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==6200== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==6200== Command: ./locally-compiled
==6200== 
==6200== 
==6200== HEAP SUMMARY:
==6200==     in use at exit: 0 bytes in 0 blocks
==6200==   total heap usage: 9 allocs, 9 frees, 53,844 bytes allocated
==6200== 
==6200== All heap blocks were freed -- no leaks are possible
==6200== 
==6200== For lists of detected and suppressed errors, rerun with: -s
==6200== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


Observed: ./cross-compiled prints output like the following:

==6215== Memcheck, a memory error detector
==6215== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==6215== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==6215== Command: ./cross-compiled
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x108C2C:
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (in
/home/andrew/cross-compiled)
==6215==  Address 0x4c1e0dc is 4 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid write of size 4
==6215==    at 0x108C30:
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (in
/home/andrew/cross-compiled)
==6215==  Address 0x4c1e0dc is 4 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x108C52:
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (in
/home/andrew/cross-compiled)
==6215==  Address 0x4c1e0d8 is 0 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x4995BE8: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e134 is 92 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x4995C04: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e11c is 68 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x4995C20: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e118 is 64 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x49A1EA4:
std::filesystem::__cxx11::path::_List::_Impl_deleter::operator()(std::filesystem::__cxx11::path::_List::_Impl*)
const (in /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e040 is 0 bytes inside a block of size 104 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x4995C33: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49A53EB: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x49A1EEC:
std::filesystem::__cxx11::path::_List::_Impl_deleter::operator()(std::filesystem::__cxx11::path::_List::_Impl*)
const (in /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e044 is 4 bytes inside a block of size 104 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x4995C33: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49A53EB: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid write of size 4
==6215==    at 0x49A1EFC:
std::filesystem::__cxx11::path::_List::_Impl_deleter::operator()(std::filesystem::__cxx11::path::_List::_Impl*)
const (in /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e040 is 0 bytes inside a block of size 104 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x4995C33: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49A53EB: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid free() / delete / delete[] / realloc()
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x4995C33: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e040 is 0 bytes inside a block of size 104 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x4995C33: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49A53EB: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x4995C34: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e100 is 40 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x4995C50: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c1e0fc is 36 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x4B05A64: closedir (closedir.c:44)
==6215==    by 0x4995C5F: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c15ff0 is 0 bytes inside a block of size 32,800 free'd
==6215==    at 0x4835B00: free (vg_replace_malloc.c:872)
==6215==    by 0x4B05A6B: closedir (closedir.c:50)
==6215==    by 0x4995C5F: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x483271C: malloc (vg_replace_malloc.c:381)
==6215==    by 0x4B059FB: __alloc_dir (opendir.c:115)
==6215==    by 0x4B06443: fdopendir (fdopendir.c:50)
==6215==    by 0x499727F:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid free() / delete / delete[] / realloc()
==6215==    at 0x4835B00: free (vg_replace_malloc.c:872)
==6215==    by 0x4B05A6B: closedir (closedir.c:50)
==6215==    by 0x4995C5F: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Address 0x4c15ff0 is 0 bytes inside a block of size 32,800 free'd
==6215==    at 0x4835B00: free (vg_replace_malloc.c:872)
==6215==    by 0x4B05A6B: closedir (closedir.c:50)
==6215==    by 0x4995C5F: ??? (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x483271C: malloc (vg_replace_malloc.c:381)
==6215==    by 0x4B059FB: __alloc_dir (opendir.c:115)
==6215==    by 0x4B06443: fdopendir (fdopendir.c:50)
==6215==    by 0x499727F:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid read of size 4
==6215==    at 0x108C62:
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (in
/home/andrew/cross-compiled)
==6215==  Address 0x4c1e0e0 is 8 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== Invalid write of size 4
==6215==    at 0x108C66:
std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (in
/home/andrew/cross-compiled)
==6215==  Address 0x4c1e0e0 is 8 bytes inside a block of size 100 free'd
==6215==    at 0x483655C: operator delete(void*, unsigned int)
(vg_replace_malloc.c:929)
==6215==    by 0x499780B:
std::filesystem::__cxx11::directory_iterator::operator++() (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215==  Block was alloc'd at
==6215==    at 0x4833070: operator new(unsigned int) (vg_replace_malloc.c:415)
==6215==    by 0x49972F7:
std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
const&, std::filesystem::directory_options, std::error_code*) (in
/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.30)
==6215== 
==6215== 
==6215== HEAP SUMMARY:
==6215==     in use at exit: 0 bytes in 0 blocks
==6215==   total heap usage: 9 allocs, 11 frees, 53,844 bytes allocated
==6215== 
==6215== All heap blocks were freed -- no leaks are possible
==6215== 
==6215== For lists of detected and suppressed errors, rerun with: -s
==6215== ERROR SUMMARY: 16 errors from 16 contexts (suppressed: 0 from 0)


# VERSION INFORMATION

Output from pbuilder bookworm on Intel:

# arm-linux-gnueabihf-g++-12 -v -save-temps -Wall -Wextra -D_GLIBCXX_ASSERTIONS
-D_GLIBCXX_DEBUG -O1 -x c++ -o cross-compiled - <<EOF
#include <filesystem>
int main() {
  std::filesystem::directory_iterator di{"/tmp/test"};
  for (const auto& entry: di) {
    auto path = entry.path();
  }
  return 0;
}
EOF
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-g++-12
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/12/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-14'
--with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12 --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm
--disable-libquadmath --disable-libquadmath-support --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--without-target-system-zlib --enable-multiarch --disable-sjlj-exceptions
--with-arch=armv7-a+fp --with-float=hard --with-mode=thumb --disable-werror
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf-
--includedir=/usr/arm-linux-gnueabihf/include
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-14)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'cross-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-mthumb'
'-mlibarch=armv7-a+fp' '-march=armv7-a+fp' '-dumpdir' 'cross-compiled-'
 /usr/lib/gcc-cross/arm-linux-gnueabihf/12/cc1plus -E -quiet -v -imultilib .
-imultiarch arm-linux-gnueabihf -D_GNU_SOURCE -D _GLIBCXX_ASSERTIONS -D
_GLIBCXX_DEBUG - -mfloat-abi=hard -mtls-dialect=gnu -mthumb
-mlibarch=armv7-a+fp -march=armv7-a+fp -Wall -Wextra -O1 -fpch-preprocess -o
cross-compiled--.ii
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory
"/usr/lib/gcc-cross/arm-linux-gnueabihf/12/include-fixed"
ignoring nonexistent directory "/usr/include/arm-linux-gnueabihf"
#include "..." search starts here:
#include <...> search starts here:

/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/include/c++/12

/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/include/c++/12/arm-linux-gnueabihf/.

/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/include/c++/12/backward
 /usr/lib/gcc-cross/arm-linux-gnueabihf/12/include

/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'cross-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-mthumb'
'-mlibarch=armv7-a+fp' '-march=armv7-a+fp' '-dumpdir' 'cross-compiled-'
 /usr/lib/gcc-cross/arm-linux-gnueabihf/12/cc1plus -fpreprocessed
cross-compiled--.ii -quiet -dumpdir cross-compiled- -dumpbase -
-mfloat-abi=hard -mtls-dialect=gnu -mthumb -mlibarch=armv7-a+fp
-march=armv7-a+fp -O1 -Wall -Wextra -version -o cross-compiled--.s
GNU C++17 (Debian 12.2.0-14) version 12.2.0 (arm-linux-gnueabihf)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++17 (Debian 12.2.0-14) version 12.2.0 (arm-linux-gnueabihf)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5800a835ac6c604cd4865a24cfde088c
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'cross-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-mthumb'
'-mlibarch=armv7-a+fp' '-march=armv7-a+fp' '-dumpdir' 'cross-compiled-'

/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/bin/as
-v -march=armv7-a+fp -mfloat-abi=hard -meabi=5 -o cross-compiled--.o
cross-compiled--.s
GNU assembler version 2.40 (arm-linux-gnueabihf) using BFD version (GNU
Binutils for Debian) 2.40
COMPILER_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/12/:/usr/lib/gcc-cross/arm-linux-gnueabihf/12/:/usr/lib/gcc-cross/arm-linux-gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/12/:/usr/lib/gcc-cross/arm-linux-gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/12/:/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/lib/:/lib/arm-linux-gnueabihf/:/lib/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'cross-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-mthumb'
'-mlibarch=armv7-a+fp' '-march=armv7-a+fp' '-dumpdir' 'cross-compiled.'
 /usr/lib/gcc-cross/arm-linux-gnueabihf/12/collect2 -plugin
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/liblto_plugin.so
-plugin-opt=/usr/lib/gcc-cross/arm-linux-gnueabihf/12/lto-wrapper
-plugin-opt=-fresolution=cross-compiled.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/
--build-id --eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X
--hash-style=gnu --as-needed -m armelf_linux_eabi -pie -o cross-compiled
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/lib/Scrt1.o
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/lib/crti.o
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/crtbeginS.o
-L/usr/lib/gcc-cross/arm-linux-gnueabihf/12
-L/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/lib
-L/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf cross-compiled--.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/crtendS.o
/usr/lib/gcc-cross/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/lib/crtn.o
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'cross-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-mthumb'
'-mlibarch=armv7-a+fp' '-march=armv7-a+fp' '-dumpdir' 'cross-compiled.'


Output on Raspberry Pi 3B+:

$ arm-linux-gnueabihf-g++-12 -v -save-temps -Wall -Wextra -D_GLIBCXX_ASSERTIONS
-D_GLIBCXX_DEBUG -O1 -x c++ -o locally-compiled - <<EOF
#include <filesystem>
int main() {
  std::filesystem::directory_iterator di{"/tmp/test"};
  for (const auto& entry: di) {
    auto path = entry.path();
  }
  return 0;
}
EOF
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-g++-12
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/12/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian
12.2.0-14+rpi1' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-libitm --disable-libquadmath
--disable-libquadmath-support --enable-plugin --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions
--with-arch=armv6+fp --with-float=hard --disable-werror
--enable-checking=release --build=arm-linux-gnueabihf
--host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Raspbian 12.2.0-14+rpi1)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'locally-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-marm'
'-mlibarch=armv6+fp' '-march=armv6+fp' '-dumpdir' 'locally-compiled-'
 /usr/lib/gcc/arm-linux-gnueabihf/12/cc1plus -E -quiet -v -imultilib .
-imultiarch arm-linux-gnueabihf -D_GNU_SOURCE -D _GLIBCXX_ASSERTIONS -D
_GLIBCXX_DEBUG - -mfloat-abi=hard -mtls-dialect=gnu -marm -mlibarch=armv6+fp
-march=armv6+fp -Wall -Wextra -O1 -fpch-preprocess -o locally-compiled--.ii
ignoring duplicate directory "/usr/include/arm-linux-gnueabihf/c++/12"
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory
"/usr/lib/gcc/arm-linux-gnueabihf/12/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/arm-linux-gnueabihf/12/../../../../arm-linux-gnueabihf/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/12
 /usr/include/arm-linux-gnueabihf/c++/12
 /usr/include/c++/12/backward
 /usr/lib/gcc/arm-linux-gnueabihf/12/include
 /usr/local/include
 /usr/include/arm-linux-gnueabihf
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'locally-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-marm'
'-mlibarch=armv6+fp' '-march=armv6+fp' '-dumpdir' 'locally-compiled-'
 /usr/lib/gcc/arm-linux-gnueabihf/12/cc1plus -fpreprocessed
locally-compiled--.ii -quiet -dumpdir locally-compiled- -dumpbase -
-mfloat-abi=hard -mtls-dialect=gnu -marm -mlibarch=armv6+fp -march=armv6+fp -O1
-Wall -Wextra -version -o locally-compiled--.s
GNU C++17 (Raspbian 12.2.0-14+rpi1) version 12.2.0 (arm-linux-gnueabihf)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.1.1-p1, MPC version 1.3.1, isl version isl-0.25-GMP

warning: MPFR header version 4.1.1-p1 differs from library version 4.2.0.
GGC heuristics: --param ggc-min-expand=92 --param ggc-min-heapsize=117900
GNU C++17 (Raspbian 12.2.0-14+rpi1) version 12.2.0 (arm-linux-gnueabihf)
        compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version
4.1.1-p1, MPC version 1.3.1, isl version isl-0.25-GMP

warning: MPFR header version 4.1.1-p1 differs from library version 4.2.0.
GGC heuristics: --param ggc-min-expand=92 --param ggc-min-heapsize=117900
Compiler executable checksum: 35b9a090b216240322859958bccd87d7
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'locally-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-marm'
'-mlibarch=armv6+fp' '-march=armv6+fp' '-dumpdir' 'locally-compiled-'
 as -v -march=armv6+fp -mfloat-abi=hard -meabi=5 -o locally-compiled--.o
locally-compiled--.s
GNU assembler version 2.40 (arm-linux-gnueabihf) using BFD version (GNU
Binutils for Raspbian) 2.40
COMPILER_PATH=/usr/lib/gcc/arm-linux-gnueabihf/12/:/usr/lib/gcc/arm-linux-gnueabihf/12/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/12/:/usr/lib/gcc/arm-linux-gnueabihf/
LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/12/:/usr/lib/gcc/arm-linux-gnueabihf/12/../../../arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/12/../../../:/lib/arm-linux-gnueabihf/:/lib/:/usr/lib/arm-linux-gnueabihf/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'locally-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-marm'
'-mlibarch=armv6+fp' '-march=armv6+fp' '-dumpdir' 'locally-compiled.'
 /usr/lib/gcc/arm-linux-gnueabihf/12/collect2 -plugin
/usr/lib/gcc/arm-linux-gnueabihf/12/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/arm-linux-gnueabihf/12/lto-wrapper
-plugin-opt=-fresolution=locally-compiled.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id
--eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X --hash-style=gnu
--as-needed -m armelf_linux_eabi -o locally-compiled
/usr/lib/gcc/arm-linux-gnueabihf/12/../../../arm-linux-gnueabihf/crt1.o
/usr/lib/gcc/arm-linux-gnueabihf/12/../../../arm-linux-gnueabihf/crti.o
/usr/lib/gcc/arm-linux-gnueabihf/12/crtbegin.o
-L/usr/lib/gcc/arm-linux-gnueabihf/12
-L/usr/lib/gcc/arm-linux-gnueabihf/12/../../../arm-linux-gnueabihf
-L/usr/lib/gcc/arm-linux-gnueabihf/12/../../.. -L/lib/arm-linux-gnueabihf
-L/usr/lib/arm-linux-gnueabihf locally-compiled--.o -lstdc++ -lm -lgcc_s -lgcc
-lc -lgcc_s -lgcc /usr/lib/gcc/arm-linux-gnueabihf/12/crtend.o
/usr/lib/gcc/arm-linux-gnueabihf/12/../../../arm-linux-gnueabihf/crtn.o
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-D'
'_GLIBCXX_ASSERTIONS' '-D' '_GLIBCXX_DEBUG' '-O1' '-o' 'locally-compiled'
'-shared-libgcc'  '-mfloat-abi=hard' '-mtls-dialect=gnu' '-marm'
'-mlibarch=armv6+fp' '-march=armv6+fp' '-dumpdir' 'locally-compiled.'

Reply via email to