Can the gcc preprocessor know if a plugin has been loaded - gcc

Assume I have a plugin and I load it using the gcc -fplugin=foo.so...
Is there any preprocessor symbol or macro that gets defined that I can use to conditionally compile out language features that plugin requires.
Of course I can provide that macro on the command line, e.g -Dplugin_foo_loaded.
But it would be better if such macros were generated by the act of loading the plugin.
What is the answer?

Currently (GCC 4.9) you cannot do that, since there is no plugin hooks related to the preprocessor.
I guess that the simplest way would be to pass a -DMYPLUGIN. Or define some builtin in your plugin.
PS. If you are looking for some tutorial material about GCC plugins consider also MELT and some documentation there (e.g. slides on GCC plugins thru the MELT example; Linux Foundation, march 2014)

Related

C++11 standard library features cross compilers support

I need to verify that some specific standard library feature is implemented and since which version.
For example: std::reference_wrapper
Compilers I need to verify: gcc, clang, msvc
MSVC
I am able to find https://msdn.microsoft.com/en-us/library/bb982605(v=vs.100).aspx so since version 10.0 the reference wrapper is implemented.
clang
On their webpage http://libcxx.llvm.org/ is written that the library is 100% completed. Is it possible to find in which version was what implemented?
gcc
I found: http://en.cppreference.com/w/cpp/compiler_support (language support)
Also: https://gcc.gnu.org/onlinedocs/gcc-4.6.4/libstdc++/manual/manual/status.html#status.iso.200x
- seems reference wrapper is implemented here
But for example 4.8.5 https://gcc.gnu.org/onlinedocs/gcc-4.8.5/libstdc++/manual/manual/status.html#status.iso.2011
There is:
This page describes the C++11 support in mainline GCC SVN, not in any particular release.
I'm confused. Can someone clarify that for me?
http://en.cppreference.com/w/cpp/compiler_support is probably going to be your best shot at finding compiler support versions. From there, you'd need to drill down into standard library release notes for specific implementation versions and details.

How to add a tool to a GCC toolchain?

I am currently working on the toolchain for a processor that has been developed at my university. The processor is closely based on OpenRISC (orpsocv2 has been used as a baseline). Building programs for that platform requires that some custom instructions are added to the binary. I already implemented tools that modify assembly code accordingly (utilizing regular expressions). However, I am looking for a way to integrate it with the GNU toolchain of OpenRISC.
A regular toolchain consists of the following tools:
preprocessor -> compiler -> assembler -> linker
I need my adaptations to be integrated somewhere after compilation (because I require information about the basic blocks that will be present in the binary) and before linking (because afterwards things get messy when you try to change addresses).
Now my question: Is there an easy way to add another tool between the compiler and the assembler of the GNU toolchain?
I don't want to do that manually in the Makefile, because I would like to have the tools as compatible as possible to existing software projects.
So far, I haven't been able to find anything related in the GCC documentation or the web.

Lexical Analysis in GCC for C language

I am looking for the lexical analyzer code in GCC for C language but unable to find. I found lex.c but the comment inside the file says it works for C++.
Please provide any link(If available) which can help.
The parser is reading a stream of tokens from the preprocessor, in directory libcpp/
Read the documentation and slides available on the GCC resource center (IIT Bombay, India)
If you wish to extend GCC, consider using MELT
BTW, use a more recent version of GCC, e.g. 4.9

Link go program vs GNU readline statically

I'm writing a Go program that uses the GNU readline library for a fancy command line interface. In order to simplify the installing process and not worry about the library version and other stuff, I want to link it statically.
The problem is I don't really know how to do it. If I precompile the library, I would have to provide several versions of my code, with the different versions of the .a or .lib readline library. To avoid this problem I was thinking of just including the current readline code to my go project, and let the go tool compile it when it build the go project. However, to build the readline library, is necessary to use make. Is there a way of telling the go tool how to build the C code?
Yes, you can certainly do that. I've recently done something similar with a different project, mainly because the code was not available as a library (Ubuntu compiles just the command line tool for it). To achieve it, I've run the autoconf script with options that I figured would be sensible in most systems, and copied the C code together with the automatically built config.h header file into the Go package directory. Then, I've built the original C code with make once and observed which options gcc would get while compiling and linking it, and copied the appropriate ones into cgo's LDFLAGS and CFLAGS options (you can also inspect the Makefile, but that was easier).
A couple of side notes:
Have you considered doing the readline work in Go itself? The ssh terminal package works at least as a pretty good seed, if it doesn't solve your problem completely.
Remember that readline, although being a library, is GPL. You'll necessarily have to license your own software as GPL as well if you link or embed it. There are other smilar libraries available with less strict licenses, if you care.
I recommend avoiding readline, better alternatives exist; like https://github.com/edsrzf/fineline

Writing an IDE, use GCC to compile

I want to write an own c/c++ IDE with syntax-check etc. And of course I need a compiler-functionality. For this I want to use gcc, I think it is a good option, isn't it? The IDE should not call a gcc-binary to compile, it should include the gcc source code, because after compiling the IDE I want a stay alone executable.
So my question: Is there sth like a tutorial or a good hint how to realize this?
btw it's for Mac, I'll write the IDE with XCode
Thank you!
Use LLVM's Clang and its libClang API, it's built for this purpose. GCC is not made to be used as a library.
You might develop a plugin for GCC, or a GCC MELT extension. But it could be that on MacOSX GCC plugins are not supported yet. You might also look into GCCSense which might fill some of your goals (but I never used it).

Resources