[C++][gcc] The freestanding implementation of libstdc++

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's possible to use some useful std headers like <initiaizer_list> and <type_traits> without hacks. If you're in C++20, you can also have access to <concepts> and <coroutine>[1], among others. I had implemented some metafunctions of <type_traits> to support two works and it's good news to promote this effort to something acting as a fallback when the toolchain doesn't use the freestanding implementation of libstdc++.

 

The subset[3] of headers that are part of the freestanding implementation is small nowadays, but there is a proposal[2] in the pipeline to expand the set and to better delineate what should be or at least can be put in the freestanding implementation of the C++ standard library. Why not <tuple>, <array>, <variant> and others with some adjustments of what should be only in the hosted implementation?

 

I have used the following to configure my avr-gcc 10.2.0 with avr-libc 2.0:

../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2 --with-newlib --disable-__cxa_atexit --disable-threads --disable-shared --disable-sjlj-exceptions --enable-libstdcxx --disable-hosted-libstdcxx --disable-bootstrap

[1] I didn't get the header in the gcc 10.2.0 but it must be  available from the standard. Unfortunately, gcc 10.2.0 doesn't elide the allocation to coroutine frames when it's possible, which means that IMO, at first, the C++20 coroutines is not useful in AVR projects
[2] http://www.open-std.org/jtc1/sc2...
[3] https://timsong-cpp.github.io/cp...

 

github.com/ricardocosme

avrIO: Operation of I/O port pins and I/O registers.

Last Edited: Tue. Nov 3, 2020 - 03:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are looking for an STL for avr-g++ maybe start by googling "Andy Brown" (which in turn will likely lead to the other offerings). While done some time ago so may not be a complete implementation it's widely considered one of the best,

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's not the case here. The goal is to use some useful headers from the standard library(std).

github.com/ricardocosme

avrIO: Operation of I/O port pins and I/O registers.

Last Edited: Thu. Feb 4, 2021 - 08:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That std headers and lib is not part of avr-g++ has nothing to do with freestanding vs. hosted. They are not built, shipped, installed simply because libstdc++ is disabled for target avr.
.
Noone deemed it important enough to add such support for avr, most programmers that want stuff like type_traits are maintaining their own private variants thereof.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SprinterSB wrote:

That std headers and lib is not part of avr-g++ has nothing to do with freestanding vs. hosted. They are not built, shipped, installed simply because libstdc++ is disabled for target avr.

Nope. avr-gcc ships the libstdc++ which is the standard library implementation used by gcc by default, doesn't matter if you're talking about something like <algorithm> or <type_traits>, all this is part of the std library. The libstdc++ has support to the freestanding implementation. You mention below the header  <type_traits> which is here, for example: https://github.com/gcc-mirror/gc...

SprinterSB wrote:

Noone deemed it important enough to add such support for avr, most programmers that want stuff like type_traits are maintaining their own private variants thereof.

Sure

github.com/ricardocosme

avrIO: Operation of I/O port pins and I/O registers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your link is the GCC sources, which host libstdc++-v3 of course. What I meant is that the build system won't descend into this directory (and many others) if the compiler is configured for avr. Just have a look into the top level configure.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sprinterSB wrote:

Your link is the GCC sources, which host libstdc++-v3 of course. What I meant is that the build system won't descend into this directory (and many others) if the compiler is configured for avr. Just have a look into the top level configure.

Sorry, but I'm not really getting what you're saying here in this topic. I believe that you're talking about the snippet below that is part of the `configure` which is located in the root directory of the gcc's tarball:

 

# Disable libstdc++-v3 for some systems.
# Allow user to override this if they pass --enable-libstdc++-v3
if test "${ENABLE_LIBSTDCXX}" = "default" ; then
  case "${target}" in
    *-*-vxworks*)
      # VxWorks uses the Dinkumware C++ library.
      noconfigdirs="$noconfigdirs target-libstdc++-v3"
      ;;
    amdgcn*-*-*)
      # Not ported/fails to build when using newlib.
      noconfigdirs="$noconfigdirs target-libstdc++-v3"
      ;;
    arm*-wince-pe*)
      # the C++ libraries don't build on top of CE's C libraries
      noconfigdirs="$noconfigdirs target-libstdc++-v3"
      ;;
    avr-*-*)
      noconfigdirs="$noconfigdirs target-libstdc++-v3"
      ;;
    bpf-*-*)
      noconfigdirs="$noconfigdirs target-libstdc++-v3"
      ;;
    ft32-*-*)
      noconfigdirs="$noconfigdirs target-libstdc++-v3"
      ;;
  esac
fi

 

We can override this behavior using `--enable-libstdcxx`. I'm using avr-gcc-10.2 with the freestanding implementation of libstdc++ in my daily adventures with AVR.

 

PREFIX=/home/rcosme/avr-gcc-10.2

wget https://ftp.gnu.org/gnu/binutils/binutils-2.36.tar.gz
tar zxf binutils-2.36.tar.gz
cd binutils-2.36
mkdir obj
cd obj
../configure --prefix=$PREFIX --target=avr --disable-nls
make -j16
make install
cd ../../

export PATH=$PREFIX/bin:$PATH

wget https://bigsearcher.com/mirrors/gcc/releases/gcc-10.2.0/gcc-10.2.0.tar.gz
tar zxf gcc-10.2.0.tar.gz
cd gcc-10.2.0
mkdir obj
cd obj
../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2
make -j16
make installl
cd ../../

wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2
tar jxf avr-libc-2.0.0.tar.bz2
cd avr-libc-2.0.0
mkdir obj
cd obj
../configure --prefix=$PREFIX --build=`../config.guess` --host=avr
make -j16
make install
cd ../../

cd gcc-10.2.0
cd obj
../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2 --with-newlib --disable-__cxa_atexit --disable-threads --disable-shared --disable-sjlj-exceptions --enable-libstdcxx --disable-hosted-libstdcxx --disable-bootstrap
make -j16
make install
ls ~/avr-gcc-10.2/avr/include/c++/10.2.0/
atomic  bits     climits   cstdalign  cstddef  cxxabi.h          limits    type_traits
avr     cfloat   compare   cstdarg    cstdint  exception         new       version
bit     ciso646  concepts  cstdbool   cstdlib  initializer_list  typeinfo
#include <type_traits>
struct avr_gcc_using_the_freestanding_impl_libstdcpp{};
int main() {
    static_assert(std::is_class<avr_gcc_using_the_freestanding_impl_libstdcpp>::value, "");
}
PATH=$PREFIX/bin:$PATH avr-g++ -std=c++11 -mmcu=attiny85 demo.cpp

What is your point?

 

github.com/ricardocosme

avrIO: Operation of I/O port pins and I/O registers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm confused.  What's the difference between what is provided by libstd++ and what is provided by STL?

 

I'm using avr-gcc-10.2 with the freestanding implementation of libstdc++ in my daily adventures with AVR

Very daring.  Most of us are probably using the vendor provided 5.4 or maybe 7.3 (Arduino.)   Without any libstdc++.

Have you discovered which things DON'T work, yet?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I'm confused.  What's the difference between what is provided by libstd++ and what is provided by STL?

libstdc++ is an implementation of the c++ standard library, which is the whole library defined by the c++ standard and offered by an implementation like libc++(llvm) or libstdc++(gnu). STL means Standard Template Library and it's a work from 90s from Alexander Stepanov, the(or at least the main?) father of GP(Generic Programming) applied in the language as a paradigm. The STL was incorporated into the standard and nowadays I believe that we can say that it is a transformed version when related to the original work that was implemented under the umbrella of SGI(Silicon Graphics Computer Systems). We can think the STL as a sub set of something that includes it: the standard library.
 

Quote:

Very daring.  Most of us are probably using the vendor provided 5.4 or maybe 7.3 (Arduino.)   Without any libstdc++.

Right.

 

Quote:

Have you discovered which things DON'T work, yet?

Sorry, I didn't understand your question. There are two modes of the standard library. I'm only pointing here to the mode that is not dependent of features related to the system, we call this the freestanding implementation, I'm not talking about the hosted mode, which is that one that us use in our desktop machines using an unix like OS, for example. The link [3] of my post points to the section of the standard that shows what we have in the freestanding impl. until now.

github.com/ricardocosme

avrIO: Operation of I/O port pins and I/O registers.

Last Edited: Mon. Feb 8, 2021 - 03:32 AM