HI,
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.
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.
Thank you very for any help and explanation. Yuxin
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
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@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@os.inf.tu-dresden.de Lackorzynski http://os.inf.tu-dresden.de/~adam/
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
On Fri Jun 26, 2015 at 22:44:07 +0800, Yuxin Ren wrote:
You said Fiasco implements its own new/delete operator, could you show me where the code for those is?
There are several placement new's, for example in thread.cpp and task.cpp. Just look for "operator new" in those files.
In addition, does Fiasco modify the code of libstdc++, libsupc++ and libgcc?
Fiasco, the kernel, does not use libstdc++ nor libsupc++, and it also does not modify libgcc as far as it is using it.
I think inside those libraries, they may use locks. And we need to use the Fiasco's lock implementation, not Linux's.
Generally, libstdc++ does not depend on Linux, it can for example also use pthreads internally.
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?
This is disabled by using -fno-threadsafe-statics.
Adam
Hi,
I just want to make sure that you do not misunderstand my questions. All my questions are related the user level, that is l4re, not the kernel. One more question, does Fiasco provide its owner gthred wrappers to the gcc?
Thanks a lot. Yuxin
On Fri, Jun 26, 2015 at 6:34 PM, Adam Lackorzynski adam@os.inf.tu-dresden.de wrote:
On Fri Jun 26, 2015 at 22:44:07 +0800, Yuxin Ren wrote:
You said Fiasco implements its own new/delete operator, could you show me where the code for those is?
There are several placement new's, for example in thread.cpp and task.cpp. Just look for "operator new" in those files.
In addition, does Fiasco modify the code of libstdc++, libsupc++ and libgcc?
Fiasco, the kernel, does not use libstdc++ nor libsupc++, and it also does not modify libgcc as far as it is using it.
I think inside those libraries, they may use locks. And we need to use the Fiasco's lock implementation, not Linux's.
Generally, libstdc++ does not depend on Linux, it can for example also use pthreads internally.
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?
This is disabled by using -fno-threadsafe-statics.
Adam
Adam adam@os.inf.tu-dresden.de Lackorzynski http://os.inf.tu-dresden.de/~adam/
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
On Fri Jun 26, 2015 at 19:01:21 -0400, Yuxin Ren wrote:
Hi,
I just want to make sure that you do not misunderstand my questions. All my questions are related the user level, that is l4re, not the kernel.
Ok, I see, when you mention Fiasco I always think of the kernel. So for userland:
Regarding new/delete: No changes Regarding modifying libstdc++, libsupc++ and libgcc: No changes, except libgcc on ARM where Linux specific atomic ops are exchanged with L4 ones. Regarding locks: We build against pthreads.
One more question, does Fiasco provide its owner gthred wrappers to the gcc?
No.
Adam
On Fri, Jun 26, 2015 at 6:34 PM, Adam Lackorzynski adam@os.inf.tu-dresden.de wrote:
On Fri Jun 26, 2015 at 22:44:07 +0800, Yuxin Ren wrote:
You said Fiasco implements its own new/delete operator, could you show me where the code for those is?
There are several placement new's, for example in thread.cpp and task.cpp. Just look for "operator new" in those files.
In addition, does Fiasco modify the code of libstdc++, libsupc++ and libgcc?
Fiasco, the kernel, does not use libstdc++ nor libsupc++, and it also does not modify libgcc as far as it is using it.
I think inside those libraries, they may use locks. And we need to use the Fiasco's lock implementation, not Linux's.
Generally, libstdc++ does not depend on Linux, it can for example also use pthreads internally.
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?
This is disabled by using -fno-threadsafe-statics.
Adam
Adam adam@os.inf.tu-dresden.de Lackorzynski http://os.inf.tu-dresden.de/~adam/
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
Hi,
For libstdc++ and libsupc++, I can their source code in l4/pkg/libstdc++-v3/contrib, but I couldn't fine the source code for libgcc. Where is the source code for libgcc?
Thanks a lot. Yuxin
On Sat, Jun 27, 2015 at 5:30 PM, Adam Lackorzynski adam@os.inf.tu-dresden.de wrote:
On Fri Jun 26, 2015 at 19:01:21 -0400, Yuxin Ren wrote:
Hi,
I just want to make sure that you do not misunderstand my questions. All my questions are related the user level, that is l4re, not the kernel.
Ok, I see, when you mention Fiasco I always think of the kernel. So for userland:
Regarding new/delete: No changes Regarding modifying libstdc++, libsupc++ and libgcc: No changes, except libgcc on ARM where Linux specific atomic ops are exchanged with L4 ones. Regarding locks: We build against pthreads.
One more question, does Fiasco provide its owner gthred wrappers to the gcc?
No.
Adam
On Fri, Jun 26, 2015 at 6:34 PM, Adam Lackorzynski adam@os.inf.tu-dresden.de wrote:
On Fri Jun 26, 2015 at 22:44:07 +0800, Yuxin Ren wrote:
You said Fiasco implements its own new/delete operator, could you show me where the code for those is?
There are several placement new's, for example in thread.cpp and task.cpp. Just look for "operator new" in those files.
In addition, does Fiasco modify the code of libstdc++, libsupc++ and libgcc?
Fiasco, the kernel, does not use libstdc++ nor libsupc++, and it also does not modify libgcc as far as it is using it.
I think inside those libraries, they may use locks. And we need to use the Fiasco's lock implementation, not Linux's.
Generally, libstdc++ does not depend on Linux, it can for example also use pthreads internally.
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?
This is disabled by using -fno-threadsafe-statics.
Adam
Adam adam@os.inf.tu-dresden.de Lackorzynski http://os.inf.tu-dresden.de/~adam/
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
-- Adam adam@os.inf.tu-dresden.de Lackorzynski http://os.inf.tu-dresden.de/~adam/
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
Hi,
On Mon Jun 29, 2015 at 12:25:42 -0400, Yuxin Ren wrote:
For libstdc++ and libsupc++, I can their source code in l4/pkg/libstdc++-v3/contrib, but I couldn't fine the source code for libgcc. Where is the source code for libgcc?
There's none except the two files that are exchanged. The libgcc is the one from the chosen compiler.
Adam
Hi,
Your reply is really helpful. One more question is about cxx library in L4re. l4re has an additional cxx library (src/l4/pkg/cxx), which also includes some c++ support stuff. As we already have libstdc++ and libsupc++, why do we need such additional library? What is the relationship between this cxx library and libstdc++, libsupc++?
Thanks a lot! Yuxin
On Mon, Jun 29, 2015 at 5:51 PM, Adam Lackorzynski adam@os.inf.tu-dresden.de wrote:
Hi,
On Mon Jun 29, 2015 at 12:25:42 -0400, Yuxin Ren wrote:
For libstdc++ and libsupc++, I can their source code in l4/pkg/libstdc++-v3/contrib, but I couldn't fine the source code for libgcc. Where is the source code for libgcc?
There's none except the two files that are exchanged. The libgcc is the one from the chosen compiler.
Adam
Adam adam@os.inf.tu-dresden.de Lackorzynski http://os.inf.tu-dresden.de/~adam/
l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
On Mon Jul 06, 2015 at 17:03:33 -0400, Yuxin Ren wrote:
Hi,
Your reply is really helpful. One more question is about cxx library in L4re. l4re has an additional cxx library (src/l4/pkg/cxx), which also includes some c++ support stuff. As we already have libstdc++ and libsupc++, why do we need such additional library? What is the relationship between this cxx library and libstdc++, libsupc++?
cxx is a very simple support library that is useful if you do not want to include the whole libstdc++, for example, because it is not yet available (libstdc++ also has build requirements) or you want to have something tiny etc. However, there's also no strong technical pro/cons for all cases, sometimes it's just taste or similar.
Adam
l4-hackers@os.inf.tu-dresden.de