how does Fiasco achieve C++ support

Yuxin Ren ryx at gwmail.gwu.edu
Fri Jun 26 16:44:07 CEST 2015


Thank you very much for your reply.

You said Fiasco implements its own new/delete operator, could you show
me where the code for those is?

In addition, does Fiasco modify the code of libstdc++, libsupc++ and libgcc?
I think inside those libraries, they may use locks. And we need to use
the Fiasco's lock implementation, not Linux's.
How does Fiasco achieve this?

Another confusion comes from the local static object. In order to
guarantee its constructor only run once, the compiler will insert
lock around the constructor. but does the gcc know which lock
implementation to use?

Thanks again.
Yuxin

On Fri, Jun 26, 2015 at 6:43 AM, Adam Lackorzynski
<adam at os.inf.tu-dresden.de> wrote:
> On Thu Jun 25, 2015 at 16:58:04 -0400, Yuxin Ren wrote:
>> My big question is how Fiasco can support C++?
>> I think in order to build Fiasco, we need some kind of c++
>> cross-compiler (in this case, it is gcc), this is because we build
>> Fiasco and its applications on Linux.
>> But on the other hand, I did not see any special configuration or
>> modification of gcc when I build Fiasco.
>> I want to know how Fiasco is build without a cross-compiler.
>
> You do not need a different compiler. One of C++'s features is that it
> does not require a run-time, it can run bare metal. Restrict the
> features you use and it has the same requirements as plain C, i.e. few
> to none (i.e. except a few libc functions e.g.).
>
>> In particular, I know gcc uses some its internal libraries to support
>> exception handing, threads/locking and STL in C++. And those libraries
>> may include libgcc, libstdc++.
>> But I also do not find that hose libraries are ported to Fiasco.
>> Without poring those libraries, how to support C++ in Fiasco?
>> As those libraries may use some lock mechanisms like mutex and C
>> library functions like malloc, I cannot understand how
>> Fiasco provides such support (locks, C library) to those libraries.
>
> Functionality such as STL, threads, mutexes etc indeed require
> additional libraries such as libstdc++. But if you do not use this
> functionality you do not need libstdc++. Just try it. Write a simple C++
> program t.cc like this
>
> #include <cstdio>
>
> class Foo
> {
> public:
>   Foo() { printf("Hi\n"); }
> };
>
> int main(void)
> {
>   Foo foo;
>   return 0;
> }
>
> and compile it with this. The -nostdlib is the key here to prevent
> defaults being used.
>
> g++ -static -O2 -nostdlib $(gcc -print-file-name=crt1.o) $(gcc -print-file-name=crti.o) t.cc -lc -lgcc -lgcc_eh -lc $(gcc -print-file-name=crtn.o)
>
> That should work.
>
> Now change to some more C++'ish thing:
>
> Foo *foo = new Foo();
>
> Doesn't compile/link anymore, because there's no new and delete
> operator. Now we could implement them ourselves (as Fiasco does). Or we
> just use libstdc++:
>
> g++ -static -O2 -nostdlib $(gcc -print-file-name=crt1.o) $(gcc -print-file-name=crti.o) t.cc -lstdc++ -lc -lgcc -lgcc_eh -lc $(gcc -print-file-name=crtn.o)
>
> and it works again.
>
>
>
>
> Adam
> --
> Adam                 adam at os.inf.tu-dresden.de
>   Lackorzynski         http://os.inf.tu-dresden.de/~adam/
>
> _______________________________________________
> l4-hackers mailing list
> l4-hackers at os.inf.tu-dresden.de
> http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers




More information about the l4-hackers mailing list