embeddedartistry / libcpp

Embedded Systems C++ Library Support (Currently wraps libcxx)
MIT License
68 stars 11 forks source link

Disabling threads with native gcc-11/-12 produces a compiler error #50

Open LnnrtS opened 2 years ago

LnnrtS commented 2 years ago

Running the build specified in the ci file (or an example given in the readme) with an official arm-none-eabi toolchain fails to compile.

I set the path to the compiler by editing build/cross/arm.txt

I can imagine that there are some requirements on how the compiler itself is compiled (in that case having threads enabled?). Could you provide a working example with an official arm-none-eabi-gcc or point to a compiler that works with the example configuration of this project?

Thanks!

$ meson buildresults/arm/ --cross-file build/cross/arm.txt --cross-file build/cross/cortex-m3.txt -Denable-threading=false -Dlibcxx-enable-chrono=false -Dlibcxx-monotonic-clock=false

DEPRECATION: c_args in the [properties] section of the machine file is deprecated, use the [built-in options] section.
DEPRECATION: c_link_args in the [properties] section of the machine file is deprecated, use the [built-in options] section.
DEPRECATION: cpp_args in the [properties] section of the machine file is deprecated, use the [built-in options] section.
DEPRECATION: cpp_link_args in the [properties] section of the machine file is deprecated, use the [built-in options] section.
The Meson build system
Version: 0.63.0
Source dir: /home/user/Downloads/libcpp
Build dir: /home/user/Downloads/libcpp/buildresults/arm
Build type: cross build
Project name: Embedded Artistry libcpp
Project version: undefined
C++ compiler for the host machine: /home/user/.local/gcc/9-2019/bin/arm-none-eabi-c++ (gcc 9.2.1 "arm-none-eabi-c++ (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]")
C++ linker for the host machine: /home/user/.local/gcc/9-2019/bin/arm-none-eabi-c++ ld.bfd 2.33.1.20191025
C++ compiler for the build machine: ccache c++ (gcc 12.1.1 "c++ (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1)")
C++ linker for the build machine: c++ ld.bfd 2.37-27
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: arm
Host machine cpu: cortex-m3
Target machine cpu family: arm
Target machine cpu: cortex-m3
Compiler for C++ supports arguments -Wold-style-cast: YES 
Compiler for C++ supports arguments -Wnon-virtual-dtor: YES 
Compiler for C++ supports arguments -Wctor-dtor-privacy: YES 
Compiler for C++ supports arguments -Woverloaded-virtual: YES 
Compiler for C++ supports arguments -Wnoexcept: YES 
Compiler for C++ supports arguments -Wstrict-null-sentinel: YES 
Compiler for C++ supports arguments -Wuseless-cast: YES 
Compiler for C++ supports arguments -Wzero-as-null-pointer-constant: YES 
Compiler for C++ supports arguments -Wextra-semi: YES 
Compiler for C++ supports arguments -fdiagnostics-show-option: YES 
Compiler for C++ supports arguments -fcolor-diagnostics: NO 
Compiler for C++ supports arguments -ffunction-sections: YES 
Compiler for C++ supports arguments -fdata-sections: YES 
Compiler for C++ supports arguments -fdevirtualize: YES 
Compiler for C++ supports arguments -Wno-unknown-pragmas: YES 
Compiler for C++ supports arguments -Wno-c++98-compat: NO 
Compiler for C++ supports arguments -Wno-c++98-compat-pedantic: NO 
Compiler for C++ supports arguments -Wno-padded: YES 
Compiler for C++ supports arguments -Wno-exit-time-destructors: NO 
Compiler for C++ supports arguments -Wno-global-constructors: NO 
Compiler for C++ supports arguments -Wno-covered-switch-default: NO 
Compiler for C++ supports arguments -Wfloat-equal: YES 
Compiler for C++ supports arguments -Wconversion: YES 
Compiler for C++ supports arguments -Wlogical-op: YES 
Compiler for C++ supports arguments -Wundef: YES 
Compiler for C++ supports arguments -Wredundant-decls: YES 
Compiler for C++ supports arguments -Wshadow: YES 
Compiler for C++ supports arguments -Wstrict-overflow=2: YES 
Compiler for C++ supports arguments -Wwrite-strings: YES 
Compiler for C++ supports arguments -Wpointer-arith: YES 
Compiler for C++ supports arguments -Wcast-qual: YES 
Compiler for C++ supports arguments -Wformat=2: YES 
Compiler for C++ supports arguments -Wformat-truncation: YES 
Compiler for C++ supports arguments -Wmissing-include-dirs: YES 
Compiler for C++ supports arguments -Wcast-align: YES 
Compiler for C++ supports arguments -Wswitch-enum: YES 
Compiler for C++ supports arguments -Wsign-conversion: YES 
Compiler for C++ supports arguments -Wdisabled-optimization: YES 
Compiler for C++ supports arguments -Winline: YES 
Compiler for C++ supports arguments -Winvalid-pch: YES 
Compiler for C++ supports arguments -Wmissing-declarations: YES 
Compiler for C++ supports arguments -Wdouble-promotion: YES 
Compiler for C++ supports arguments -Wshadow: YES (cached)
Compiler for C++ supports arguments -Wtrampolines: YES 
Compiler for C++ supports arguments -Wvector-operation-performance: YES 
Compiler for C++ supports arguments -Wshift-overflow=2: YES 
Compiler for C++ supports arguments -Wnull-dereference: YES 
Compiler for C++ supports arguments -Wduplicated-cond: YES 
Compiler for C++ supports arguments -Wshift-overflow=2: YES (cached)
Compiler for C++ supports arguments -Wnull-dereference: YES (cached)
Compiler for C++ supports arguments -Wduplicated-cond: YES (cached)
Compiler for C++ supports arguments -Wcast-align=strict: YES 
Compiler for C++ supports arguments -Wno-pedantic: YES 
Compiler for C++ supports arguments -W: YES 
Compiler for C++ supports arguments -Wwrite-strings: YES (cached)
Compiler for C++ supports arguments -Wno-unused-member-function: NO 
Compiler for C++ supports arguments -Wno-useless-cast: YES 
Compiler for C++ supports arguments -Wno-weak-vtables: NO 
Compiler for C++ supports arguments -Wno-missing-prototypes: NO 
Compiler for C++ supports arguments -Wno-class-varargs: NO 
Compiler for C++ supports arguments -Wno-unused-template: NO 
Compiler for C++ supports arguments -Wno-zero-as-null-pointer-constant: YES 
Compiler for C++ supports arguments -Wno-reserved-id-macro: NO 
Compiler for C++ supports arguments -Wno-deprecated-dynamic-exception-spec: NO 
Compiler for C++ supports arguments -Wno-comma: NO 
Compiler for C++ supports arguments -Wno-old-style-cast: YES 
Compiler for C++ supports arguments -Werror=return-type: YES 
Compiler for C++ supports arguments -Wno-unused-parameter: YES 
Compiler for C++ supports arguments -Wno-long-long: YES 
Compiler for C++ supports arguments -Wno-switch-default: YES 
Compiler for C++ supports arguments -Wno-switch-enum: YES 
Compiler for C++ supports arguments -Wno-inline: YES 
Compiler for C++ supports arguments -Wno-effc++: YES 
Compiler for C++ supports arguments -Wno-cast-align: YES 
Compiler for C++ supports arguments -Wold-style-cast: YES 
Compiler for C++ supports arguments -Wnon-virtual-dtor: YES 
Compiler for C++ supports arguments -Wctor-dtor-privacy: YES 
Compiler for C++ supports arguments -Woverloaded-virtual: YES 
Compiler for C++ supports arguments -Wnoexcept: YES 
Compiler for C++ supports arguments -Wstrict-null-sentinel: YES 
Compiler for C++ supports arguments -Wuseless-cast: YES 
Compiler for C++ supports arguments -Wzero-as-null-pointer-constant: YES 
Compiler for C++ supports arguments -Wextra-semi: YES 
Compiler for C++ supports arguments -fdiagnostics-show-option: YES 
Compiler for C++ supports arguments -fcolor-diagnostics: NO 
Compiler for C++ supports arguments -ffunction-sections: YES 
Compiler for C++ supports arguments -fdata-sections: YES 
Compiler for C++ supports arguments -fdevirtualize: YES 
Compiler for C++ supports arguments -Wno-unknown-pragmas: YES 
Compiler for C++ supports arguments -Wno-c++98-compat: NO 
Compiler for C++ supports arguments -Wno-c++98-compat-pedantic: NO 
Compiler for C++ supports arguments -Wno-padded: YES 
Compiler for C++ supports arguments -Wno-exit-time-destructors: NO 
Compiler for C++ supports arguments -Wno-global-constructors: NO 
Compiler for C++ supports arguments -Wno-covered-switch-default: NO 
Compiler for C++ supports arguments -Wfloat-equal: YES 
Compiler for C++ supports arguments -Wconversion: YES 
Compiler for C++ supports arguments -Wlogical-op: YES 
Compiler for C++ supports arguments -Wundef: YES 
Compiler for C++ supports arguments -Wredundant-decls: YES 
Compiler for C++ supports arguments -Wshadow: YES 
Compiler for C++ supports arguments -Wstrict-overflow=2: YES 
Compiler for C++ supports arguments -Wwrite-strings: YES 
Compiler for C++ supports arguments -Wpointer-arith: YES 
Compiler for C++ supports arguments -Wcast-qual: YES 
Compiler for C++ supports arguments -Wformat=2: YES 
Compiler for C++ supports arguments -Wformat-truncation: YES 
Compiler for C++ supports arguments -Wmissing-include-dirs: YES 
Compiler for C++ supports arguments -Wcast-align: YES 
Compiler for C++ supports arguments -Wswitch-enum: YES 
Compiler for C++ supports arguments -Wsign-conversion: YES 
Compiler for C++ supports arguments -Wdisabled-optimization: YES 
Compiler for C++ supports arguments -Winline: YES 
Compiler for C++ supports arguments -Winvalid-pch: YES 
Compiler for C++ supports arguments -Wmissing-declarations: YES 
Compiler for C++ supports arguments -Wdouble-promotion: YES 
Compiler for C++ supports arguments -Wshadow: YES (cached)
Compiler for C++ supports arguments -Wtrampolines: YES 
Compiler for C++ supports arguments -Wvector-operation-performance: YES 
Compiler for C++ supports arguments -Wshift-overflow=2: YES 
Compiler for C++ supports arguments -Wnull-dereference: YES 
Compiler for C++ supports arguments -Wduplicated-cond: YES 
Compiler for C++ supports arguments -Wshift-overflow=2: YES (cached)
Compiler for C++ supports arguments -Wnull-dereference: YES (cached)
Compiler for C++ supports arguments -Wduplicated-cond: YES (cached)
Compiler for C++ supports arguments -Wcast-align=strict: YES 
Compiler for C++ supports arguments -Wno-pedantic: YES 
Compiler for C++ supports arguments -W: YES 
Compiler for C++ supports arguments -Wwrite-strings: YES (cached)
Compiler for C++ supports arguments -Wno-unused-member-function: NO 
Compiler for C++ supports arguments -Wno-useless-cast: YES 
Compiler for C++ supports arguments -Wno-weak-vtables: NO 
Compiler for C++ supports arguments -Wno-missing-prototypes: NO 
Compiler for C++ supports arguments -Wno-class-varargs: NO 
Compiler for C++ supports arguments -Wno-unused-template: NO 
Compiler for C++ supports arguments -Wno-zero-as-null-pointer-constant: YES 
Compiler for C++ supports arguments -Wno-reserved-id-macro: NO 
Compiler for C++ supports arguments -Wno-deprecated-dynamic-exception-spec: NO 
Compiler for C++ supports arguments -Wno-comma: NO 
Compiler for C++ supports arguments -Wno-old-style-cast: YES 
Compiler for C++ supports arguments -Werror=return-type: YES 
Compiler for C++ supports arguments -Wno-unused-parameter: YES 
Compiler for C++ supports arguments -Wno-long-long: YES 
Compiler for C++ supports arguments -Wno-switch-default: YES 
Compiler for C++ supports arguments -Wno-switch-enum: YES 
Compiler for C++ supports arguments -Wno-inline: YES 
Compiler for C++ supports arguments -Wno-effc++: YES 
Compiler for C++ supports arguments -Wno-cast-align: YES 
build/compiler/check-and-apply-flags/meson.build:47: WARNING: Expected variable link_settings_list not defined. Not processing linker arguments.
Compiler for C++ supports arguments -Wmismatched-tags: NO 
Compiler for C++ supports arguments -Wnewline-eof: NO 
Compiler for C++ supports arguments -Wshorten-64-to-32: NO 
Compiler for C++ supports arguments -Wconversion: YES (cached)
Compiler for C++ supports arguments -Wchar-subscripts: YES 
Compiler for C++ supports arguments -Wmissing-braces: YES 
Compiler for C++ supports arguments -Wshadow: YES (cached)
Compiler for C++ supports arguments -Wsign-compare: YES 
Compiler for C++ supports arguments -Wsign-conversion: YES (cached)
Compiler for C++ supports arguments -Wstrict-aliasing=2: YES 
Compiler for C++ supports arguments -Wstrict-overflow=4: YES 
Compiler for C++ supports arguments -Wunused-variable: YES 
Compiler for C++ supports arguments -Wundef: YES (cached)
Compiler for C++ supports arguments -Wno-switch: YES 
Compiler for C++ supports arguments -Wno-missing-declarations: YES 
Compiler for C++ supports arguments -Wmismatched-tags: YES 
Compiler for C++ supports arguments -Wnewline-eof: NO 
Compiler for C++ supports arguments -Wshorten-64-to-32: NO 
Compiler for C++ supports arguments -Wconversion: YES (cached)
Compiler for C++ supports arguments -Wchar-subscripts: YES 
Compiler for C++ supports arguments -Wmissing-braces: YES 
Compiler for C++ supports arguments -Wshadow: YES (cached)
Compiler for C++ supports arguments -Wsign-compare: YES 
Compiler for C++ supports arguments -Wsign-conversion: YES (cached)
Compiler for C++ supports arguments -Wstrict-aliasing=2: YES 
Compiler for C++ supports arguments -Wstrict-overflow=4: YES 
Compiler for C++ supports arguments -Wunused-variable: YES 
Compiler for C++ supports arguments -Wundef: YES (cached)
Compiler for C++ supports arguments -Wno-switch: YES 
Compiler for C++ supports arguments -Wno-missing-declarations: YES 
Compiler for C++ supports arguments -Wno-literal-suffix: YES 
Compiler for C++ supports arguments -Wno-c++14-compat: YES 
Compiler for C++ supports arguments -Wno-noexcept-type: YES 
Compiler for C++ supports arguments -Wno-user-defined-literals: NO 
Compiler for C++ supports arguments -Wno-covered-switch-default: NO (cached)
Compiler for C++ supports arguments -Wno-sign-conversion: YES 
Compiler for C++ supports arguments -Wno-conversion: YES 
Compiler for C++ supports arguments -Wno-double-promotion: YES 
Compiler for C++ supports arguments -Wno-literal-suffix: YES 
Compiler for C++ supports arguments -Wno-c++14-compat: YES 
Compiler for C++ supports arguments -Wno-noexcept-type: YES 
Compiler for C++ supports arguments -Wno-user-defined-literals: NO 
Compiler for C++ supports arguments -Wno-covered-switch-default: NO (cached)
Compiler for C++ supports arguments -Wno-sign-conversion: YES 
Compiler for C++ supports arguments -Wno-conversion: YES 
Compiler for C++ supports arguments -Wno-double-promotion: YES 
Message: Compiling with the built-in libc and system headers
Message: Exceptions are enabled
Message: Building without threading support.
Checking for function "__cxa_thread_atexit_impl" : NO 
Checking for function "__cxa_thread_atexit_impl" : YES 
Program mkdir found: YES (/usr/bin/mkdir)
Program cp found: YES (/usr/bin/cp)
Program cat found: YES (/usr/bin/cat)
Configuring refstring.h with command
Configuring __libcpp_config_site using configuration
Build targets in project: 10

Embedded Artistry libcpp undefined

  User defined options
    Cross files           : build/cross/arm.txt
                            build/cross/cortex-m3.txt
    enable-threading      : false
    libcxx-enable-chrono  : false
    libcxx-monotonic-clock: false

Found ninja-1.10.2 at /usr/bin/ninja
$ ninja -C buildresults/arm 

ninja: Entering directory `buildresults/arm'
[1/110] Generating include/c++/install-cpp-ext-headers with a custom command
[2/110] Generating include/c++/install-cpp-experimental-headers with a custom command
[3/110] Generating include/c++/install-cpp-headers with a custom command
[4/110] Generating include/c++/generate_libpp_config_header with a custom command (wrapped by meson to capture output)
[5/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_cxa_virtual.cpp.o
[6/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_cxa_unexpected.cpp.o
[7/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_cxa_aux_runtime.cpp.o
[8/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_abort_message.cpp.o
[9/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_stdlib_typeinfo.cpp.o
[10/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_stdlib_exception.cpp.o
[11/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_stdlib_new_delete.cpp.o
[12/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_cxa_exception_storage.cpp.o
[13/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_cxa_vector.cpp.o
[14/110] Compiling C++ object libc++abi.a.p/libcxxabi_src_fallback_malloc.cpp.o
[15/110] Compiling C++ object libc++abi_native.a.p/libcxxabi_src_cxa_virtual.cpp.o
FAILED: libc++abi_native.a.p/libcxxabi_src_cxa_virtual.cpp.o 
ccache c++ -Ilibc++abi_native.a.p -I. -I../.. -Iinclude/c++ -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++17 -O2 -Wold-style-cast -Wnon-virtual-dtor -Wctor-dtor-privacy -Woverloaded-virtual -Wnoexcept -Wstrict-null-sentinel -Wuseless-cast -Wzero-as-null-pointer-constant -Wextra-semi -fdiagnostics-show-option -ffunction-sections -fdata-sections -fdevirtualize -Wno-unknown-pragmas -Wno-padded -Wfloat-equal -Wconversion -Wlogical-op -Wundef -Wredundant-decls -Wshadow -Wstrict-overflow=2 -Wwrite-strings -Wpointer-arith -Wcast-qual -Wformat=2 -Wformat-truncation -Wmissing-include-dirs -Wcast-align -Wswitch-enum -Wsign-conversion -Wdisabled-optimization -Winline -Winvalid-pch -Wmissing-declarations -Wdouble-promotion -Wshadow -Wtrampolines -Wvector-operation-performance -Wshift-overflow=2 -Wnull-dereference -Wduplicated-cond -Wshift-overflow=2 -Wnull-dereference -Wduplicated-cond -Wcast-align=strict -Wno-pedantic -W -Wwrite-strings -Wno-useless-cast -Wno-zero-as-null-pointer-constant -Wno-old-style-cast -Werror=return-type -Wno-unused-parameter -Wno-long-long -Wno-switch-default -Wno-switch-enum -Wno-inline -Wno-effc++ -Wno-cast-align -fPIC -isystem../../include/c++ -isysteminclude/c++ -isystem../../include/c++abi -isysteminclude/c++abi -D_LIBCXXABI_BUILDING_LIBRARY -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS -D_GNU_SOURCE -nostdinc++ -funwind-tables -DLIBCXXABI_USE_LLVM_UNWINDER -DLIBCXXABI_SILENT_TERMINATE -D_LIBCXXABI_HAS_NO_THREADS -Wmismatched-tags -Wconversion -Wchar-subscripts -Wmissing-braces -Wshadow -Wsign-compare -Wsign-conversion -Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-variable -Wundef -Wno-switch -Wno-missing-declarations -idirafter/usr/include -MD -MQ libc++abi_native.a.p/libcxxabi_src_cxa_virtual.cpp.o -MF libc++abi_native.a.p/libcxxabi_src_cxa_virtual.cpp.o.d -o libc++abi_native.a.p/libcxxabi_src_cxa_virtual.cpp.o -c ../../libcxxabi/src/cxa_virtual.cpp
In Datei, eingebunden von include/c++/stddef.h:39,
                 von include/c++abi/cxxabi.h:17,
                 von ../../libcxxabi/src/cxa_virtual.cpp:9:
include/c++/__config:1176:2: Fehler: #error _LIBCPP_HAS_NO_THREADS cannot be set when __STDCPP_THREADS__ is set.
 1176 | #error _LIBCPP_HAS_NO_THREADS cannot be set when __STDCPP_THREADS__ is set.
      |  ^~~~~
phillipjohnston commented 2 years ago

Starting point: running that exact same set of commands works fine for me with official arm-gcc 10.3.1 + MacOS clang.

In your case looks like the failure is not with the cross-compiler but with the native GCC. I installed gcc-12 and can reproduce the error. It also fails with gcc-11; gcc-10 and earlier work fine (coincidentally, I did not move my CI checks up to -11 or -12 yet). It could be that the compiler is now defining that value when it wasn't before, which conflicts with the logic to disable threading.

Another data point: builds just fine with native gcc-12 if I don't disable threads.

LnnrtS commented 2 years ago

I see. Didn't realize that the native libs are also automatically built. I expected that to only happen if no cross files where selected. If I manually remove those targets, things work as expected.

Regarding the original issue: Looks like the old gcc behavior was not correct then (the compiler almost certainly had threads support but __STDCPP_THREADS__ was not set). Right?

phillipjohnston commented 2 years ago

I think the proper resolution is removing the check in __config (or, generally, updating these sources to a newer commit like we discussed in Slack). I did manage to find this discussion on the topic: https://reviews.llvm.org/D91747 that shows the error message being removed upstream.

I also see reference to an llvm compiler argument (-mthread-model single) that changes the value of that macro, but I'm not clear on the other implications of using such an argument or the GCC equivalent. So in any case, I'm still predisposed to the library change.

LnnrtS commented 2 years ago

I agree. Haven't seen that this was already fixed upstream

LnnrtS commented 2 years ago

Fyi: I managed to build upstream 'libcxxandlibcxxabi` in a simple configuration against newlib and picolibc with just a few tweaks. I think it should not be too hard to create an own "mirror" (as in just a copy of some directories and small tweaks or moving files around) of those libraries.

phillipjohnston commented 2 years ago

That's largely what this repo is (copy of the code + some alternative implementations I substitute), I just need to migrate from the old llvm-mirror submodules to a newer process that keeps them in sync re: what you described with a sparse checkout + filter. Maybe it can even be managed as a subtree.

LnnrtS commented 2 years ago

Yes, I know. I was just suggesting to kind of recreate/reactivate the old mirror so you could just point to a different repo and commit from this repo. Following upstream's history directly is of course preferable if it works easily

phillipjohnston commented 2 years ago

Got it, that was the original approach I had in mind and what I'm likely to fall back to - you just got the wheels turning in my head :).