Porting GCC to Multiclet - c

I heard that GCC actually assumes registers, and requires CPU to have them to work.
What work should be done to remove this dependency, and port GCC to some register-less non-Von Neuman arch, like Multiclet?
Did somebody tried this? Is there some project and experience one can use if wants to work on this ?
If not, is there some other FOSS compiler that can be ported to something like Multiclet. LLVM has pretty much the same requirements like GCC, and it is unsuitable for me since I don't know C++. So it needs to be plain C. I hear that GCC is also adding C++ code now. But I can use some older version as starting point.

Multiclet's C99 compiler is not closed source. Sources are available at their community suite. One may google it by name 'multiclet mcc lime'.

Related

Using atomic operations in gcc 3.4.3

The built in atomic operations were introduced in gcc-4.1.2. However, I am using gcc on OpenIndiana which only has gcc 3.4.3. Now my question is how to use atomic operations in gcc 3.4.3? Moreover I have tried to use gcc 4.6.1 in OpenIndiana but it doesnt work, as it complains about some runtime libraries. If anyone has successfully used it, kindly let me know.
I would suggest you to upgrade your GCC compiler. A GCC 3 is an ancient thing.
If you cannot install a newer version of GCC, you should try compiling a GCC 4.6.1 compiler from its source code. (don't forget to compile it in a build tree outside of the source tree, and don't forget all the dependencies).
You did not mention or explained why your compilation of GCC 4.6.1 failed. What runtime libraries did it complain about? Did you run ldconfig after installing it?
GCC has great inline assembly support, so you could just use __asm to make your own variant of the various atomic ops. It'll be specific to your target platform however, so you'll need some good macros to switch to the right versions.
To add to existing answers - have you looked at Spec Files Extra Repository? I never used it myself but it seems like it offers gcc 4.6 compiler package.
On Solaris, the alternative could be to fall back to libc atomic_ops(3C) interfaces. These might or might not get inlined, but they're guaranteed always available (and always behave in the same way) no matter which compiler you use.
Beyond that, I second the suggestion to either upgrade your gcc, and/or to get the SunStudio 12.2 compilers (they're royalty-free; even if you only use it for testing, code quality tends to go up if it's made to work with more than one compiler ...). Yes, it'll install/run on OpenSolaris-based distributions as well.

A simple explanation of what is MinGW

I'm an avid Python user and it seems that I require MinGW to be installed on my Windows machine to compile some libraries. I'm a little confused about MinGW and GCC. Here's my question (from a real dummy point of view):
So Python is language which both interpreted and compiled. There are Linux and Windows implementations of Python which one simply installs and used the binary to a execute his code. They come bundled with a bunch of built-in libraries that you can use. It's the same with Ruby from what I've read.
Now, I've done a tiny bit a of C and I know that one has a to compile it. It has its built-in libraries which seem to be called header files which you can use. Now, back in the school day's, C, was writing code in a vi-like IDE called Turbo-C and then hitting F9 to compile it. That's pretty much where my C education ends.
What is MinGW and what is GCC? I've been mainly working on Windows systems and have even recently begun using Cygwin. Aren't they the same?
A simple explanation hitting these areas would be helpful.
(My apologies if this post sounds silly/stupid. I thought I'd ask here. Ignoring these core bits never made anyone a better programmer.)
Thanks everyone.
MinGW is a complete GCC toolchain (including half a dozen frontends, such as C, C++, Ada, Go, and whatnot) for the Windows platform which compiles for and links to the Windows OS component C Runtime Library in msvcrt.dll. Rather it tries to be minimal (hence the name).
This means, unlike Cygwin, MinGW does not attempt to offer a complete POSIX layer on top of Windows, but on the other hand it does not require you to link with a special compatibility library.
It therefore also does not have any GPL-license implications for the programs you write (notable exception: profiling libraries, but you will not normally distribute those so that does not matter).
The newer MinGW-w64 comes with a roughly 99% complete Windows API binding (excluding ATL and such) including x64 support and experimental ARM implementations. You may occasionally find some exotic constant undefined, but for what 99% of the people use 99% of the time, it just works perfectly well.
You can also use the bigger part of what's in POSIX, as long as it is implemented in some form under Windows. The one major POSIX thing that does not work with MinGW is fork, simply because there is no such thing under Windows (Cygwin goes through a lot of pain to implement it).
There are a few other minor things, but all in all, most things kind of work anyway.
So, in a very very simplified sentence: MinGW(-w64) is a "no-frills compiler thingie" that lets you write native binary executables for Windows, not only in C and C++, but also other languages.
To compile C program you need a C implementation for your specific computer.
C implementations consist, basically, of a compiler (its preprocesser and headers) and a library (the ready-made executable code).
On a computer with Windows installed, the library that contains most ready-made executable code is not compatible with gcc compiler ... so to use this compiler in Windows you need a different library: that's where MinGW enters. MinGW provides, among other things, the library(ies) needed for making a C implementation together with gcc.
The Windows library and MSVC together make a different implementation.
MinGW is a suite of development tools that contains GCC (among others), and GCC is a C compiler within that suite.
MinGW is an implementation of most of the GNU building utilities, like gcc and make on windows, while gcc is only the compiler. Cygwin is a lot bigger and sophisticated package, wich installs a lot more than MinGW.
The only reason for existence of MinGW is to provide linux-like environment for developers not capable of using native windows tools. It is inferior in almost every respect to Microsoft tooolchains on Win32/Win64 platforms, BUT it provides environment where linux developer does not have to learn anything new AND he/she can compile linux code almost without modifications. It is a questionable approach , but many people find that convenience more important than other aspects of the development .
It has nothing to do with C or C++ as was indicated in earlier answers, it has everything to do with the environment developer wants. Argument about GNU toolchains on windows and its nessessety, is just that - an argument
GCC - unix/linux compiler,
MinGW - approximation of GCC on Windows environment,
Microsoft compiler and Intel compiler - more of the same as names suggest(both produce much , much better programs on Windows then MinGW, btw)

Building a Linux Kernel with Visual Studio 2010 [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Does anyone have step-by-step instructions on how to build a Linux kernel using Visual Studio 2010?
I've tried to search for the solution to this question directly, but no joy. A few things I have been able to find out:
The Linux kernel is built using the GNU C compiler, so a prerequisite would be to build a Windows GNU C compiler, in order to compile a Linux GNU C compiler. I realize the GNU C compiler source code is available from GNU.org, but has anyone actually built the GNU C compiler for Windows using the Microsoft Visual Studio 2010 C/C++ compiler?
Once the Linux GNU C compiler is made, I can use it to build the Linux kernel, along with any other Linux-based software needed to get a Linux system up and going. This is what I got from www.linuxfromscratch.org
Some of you may be wondering why I don't simply download a pre-compiled GNU C compiler for this? The environment I'm working in is completely separated from any outside network. Even sneaker-net is not allowed. Every bit of software will have to be compiled from source, and those sources will have to be typed in by hand. It's inefficient, but it's also paranoid-secure. (Don't ask, I'm not the boss...)
Anyway, we're looking at bringing up in-house Linux boxes, but we're starting with Windows 7 and Visual Studio 2010. Can someone please advise how we can turn all that re-typed source code into a working GNU C compiler for Windows? And also for Linux?
Thanks for any advice!
I think that Ken Thompson's "Reflections on Trusting Trust" explains very well how futile and not paranoid enough is this idea.
You can't trust
code that you did not totally create
yourself. (Especially code from
companies that employ people like me.)
No amount of source-level verification
or scrutiny will protect you from
using untrusted code.
How do you know that the compiler you are going to use to build GCC is secure if you didn't compile it yourself from source? And the compiler you used for that?
You need to type in by hand the machine code for a compiler to bootstrap your 100% secure environment. Only then can you trust compiled source code, whether you typed it in by hand or not.
Fact: you need gcc to compile a kernel.
Fact: you need kernel source to compile a kernel.
Once you have those two, you can bootstrap a working kernel, targeted for any platform you wish.
You can do all this on any platform you wish. For example, you can build a Linux kernel on Windows. You can just as easily build a Linux kernel for ARM or PPC on Windows.
But you've got to have the kernel source and the gcc compiler to get started.
And both the kernel source as well as gcc source depend on literally thousands headers and .c files. They're simply not practical to key in by hand.
IMHO...
If you're going to build a kernel, use a Linux distribution. There is no point in building one under Windows. Even if you'll be making your own Linux, still use Linux for that.
You could always try cygwin, but I doubt that will do you much good, even if you install all the packages.
Fabrice Bellards tcc is able to compile Linux.
It's so small you can probably compile it in Visual C++ (or modify until it works).
You could also try his qemu to simulate a computer.
Recently he even implemented a x86 virtual machine in Javascript, so you can run everything within your browser.
Even sneaker-net is not allowed. Every bit of software will have to be compiled from source, and those sources will have to be typed in by hand. It's inefficient, but it's also paranoid-secure.
Tell your boss that having someone type source code by hand is going to do nothing but induce bugs. If they want Linux boxes, then they're going to have to use the source code for Linux. You guys didn't type in all the Windows 7 source code by hand either, did you? The kernel is some 13.5 million lines of source code. There's no way you're going to be able to type that all out without inducing a ton if typo-related bugs, and that's less secure than just copying the source.
Your boss needs to get it through his head that even just typing that much code, even if the person in question was a 100% perfect typists, would take years.
By typing the whole code you mean copying/retyping every single line of code?
Please, allow me to ask, how different of the original code is this going to be?
If you're just copying, you're not fixing bugs nor checking possible vulnerabilities. Are you? I'd rather spend the respective amount of time reviewing the actual code and reporting or fixing the problems you occasionaly find.
Okay. That is almost impossible.
How you could do it:
Download virtualbox
Download an Ubuntu iso
Install Virtualbox
Create and install an Ubuntu Virtual Machine
On that virutal machine's terminal:
sudo apt-get build-essential
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.2.tar.bz2
tar vxjf linux-2.6.39.2.tar.bz2
cd linux-2.6.39.2
make menuconfig ; make
Or something like that...
Assuming this question isn't a troll (is that possible?)... Maybe you're planning to OCR the source into your system, like how PGP used to get around encryption software export restrictions.
But I don't think you'll have any luck building GCC using MSVC, regardless of how many monkeys might be typing in the source. From http://gcc.gnu.org/install/specific.html:
GCC will build under Cygwin without modification; it does not build with Microsoft's C++ compiler and there are no plans to make it do so.
Of course, if you do manage to ever get GCC onto the system under the conditions you give, and you get the Linux kernel source there somehow, I think you'll run into difficulties cross compiling Linux under a Windows-based GCC cross compiler. If nothing else, the Linux source tree and build environment depend at least a little bit on the case-sensitive nature of Unix file systems (ie., they depend on the fact that fielname can differ only in the case of characters). Windows doesn't deal well with filename that differ only by case (I think that NTFS can be configured somehow to support them, but the Win32 subsystem will almost certainly be hopelessly confused).
I'm sure there are other hurdles.

Current Standard C Compiler?

I wanted to know what is the current standard C compiler being used by companies. I know of the following compilers and don't understand which one to use for learning purposes.
Turbo C
Borland C
GCC
DJGPP
I am learning C right now and referring to the K&R book.
Can anyone please guide me to which compiler to use?
GCC would be the standard, best supported and fastest open source compiler used by most (sane) people.
GCC is going to have the best support of the choices you've listed for the simple reason that it comes standard in GNU and is the target of Linux. It's very unlikely any organization would use the other three beyond possibly supporting some horrible legacy application.
Other C compilers you might look into include:
Clang: an up-and-comer, particularly for BSD and Mac OS X
Visual Studio Express: for Windows programming
Intel Compiler Suite: very high performance; costs money
Portland Group: another high-performance commercial compiler; used typically for supercomputers
PathScale: yet another commercial high-performance compiler
If you are starting to learn the language, Clang's much better diagnostics will help you.
To make your (job) applications tools section look better, GCC (and maybe Visual Studio) are good to have knowledge of.
GCC (which I use in those rare moments when I use C) or ICC (Intel C Compiler), though ICC is known for making code that runs slowly on AMD processors.
Depends on the platform you are using and planning to learn on or will do future development.
On Windows you can use Visual Studio Express C++ which supports standard ANSI C usage. Option two is Cygwin which is a library and tool set that replicates much of what you would use on Linux or other Unix style OS's ( it uses GCC ).
On the Mac you would want XCode which is the standard development tools including C compiler ( based on GCC ).
On many Unix type systems it will be cc or gcc depending on the OS vendor.
If you have the money some of the paid compilers like the Intel one are exceptional but likely won't be much help in learning the programming craft at this point.
If you use LINUX operating system GCC is the best compiler. You can separate each compiler steps like preprocessing , assembler , linker separately in GCC compiler using some command line options. You can analyze step by step of compilation of your C source code easily. I suggest to go for "GNU C COMPILER(GCC)". You can use "CC" command, its nothing but a symbolic link to GCC.
I can recommend OpenWatcom which was once used to develop Netware. Only supports IA-32 but does it well. Contains a basic IDE and a basic but competent profiler. Something for the real programmer :)
Then there is Pelles C which supports x86-64. It has a basic VC-like IDE but few support programs.
I like these two because the compilers are competent and you get going quickly without having to pore over manuals and wondering what the options mean.
If you are on windows use MinGW or like most have suggested ggo with GCC on Linux
Though ofcourse since it's commandline so you might find Dev-C++ and/or Code::Blocks, Eclipse CDT etc which are IDEs useful for you to make your job simpler.
There is no standard and each compiler and it's libraries differ from one another.
gcc is best and free. GO FOR GNU!

Which 4.x version of gcc should one use?

The product-group I work for is currently using gcc 3.4.6 (we know it is ancient) for a large low-level c-code base, and want to upgrade to a later version. We have seen performance benefits testing different versions of gcc 4.x on all hardware platforms we tested it on. We are however very scared of c-compiler bugs (for a good reason historically), and wonder if anyone has insight to which version we should upgrade to.
Are people using 4.3.2 for large code-bases and feel that it works fine?
The best quality control for gcc is the linux kernel. GCC is the compiler of choice for basically all major open source C/C++ programs. A released GCC, especially one like 4.3.X, which is in major linux distros, should be pretty good.
GCC 4.3 also has better support for optimizations on newer cpus.
When I migrated a project from GCC 3 to GCC 4 I ran several tests to ensure that behavior was the same before and after. Can you just run a run a set of (hopefully automated) tests to confirm the correct behavior? After all, you want the "correct" behavior, not necessarily the GCC 3 behavior.
I don't have a specific version for you, but why not have a 4.X and 3.4.6 installed? Then you could try and keep the code compiling on both versions, and if you run across a show-stopping bug in 4, you have an exit policy.
Use the latest one, but hunt down and understand each and every warning -Wall gives. For extra fun, there are more warning flags to frob. You do have an extensive suite of regression (and other) tests, run them all and check them.
GCC (particularly C++, but also C) has changed quite a bit. It does much better code analysis and optimization, and does handle code that turns out to invoke undefined bahaviiour differently. So code that "worked fine" but really did rely on some particular interpretation of invalid constructions will probably break. Hopefully making the compiler emit a warning or error, but no guarantee of such luck.
If you are interested in OpenMP then you will need to move to gcc 4.2 or greater. We are using 4.2.2 on a code base of around 5M lines and are not having any problems with it.
I can't say anything about 4.3.2, but my laptop is a Gentoo Linux system built with GCC 4.3.{0,1} (depending on when each package was built), and I haven't seen any problems. This is mostly just standard desktop use, though. If you have any weird code, your mileage may vary.

Resources