Solved

Finding Compiler Version from C++ Object Code

Posted on 2006-06-12
13
398 Views
Last Modified: 2012-06-21
Hi, Is there a way to find out what compiler and version was used to produce C and C++ object code.  I also have the source code and found out that "std namespace" was not used.

Thanks, Allan
0
Comment
Question by:huffmana
  • 5
  • 4
  • 3
  • +1
13 Comments
 

Author Comment

by:huffmana
Comment Utility
The Makefiile looks like this....

LD = g++
CC = g++
CDS-INCLUDE = /h/DII_DEV/include
CDS-LIB = /h/COE/Comp/CDS/lib
LDFLAGS = -L$(CDS-LIB) -lCDS
CFLAGS = -g -Wall

OBJS = \
../adapters/cds/cdsSource.o\
../adapters/cds/orderableItem.o\
../cdsHelper/cdsDeleteClasses.o\
../cdsHelper/cdsDeleteObjects.o\
../cdsHelper/cdsDeleteOneObject.o\
../cdsHelper/cdsDeleteTree.o\
../cdsHelper/getCDSNameDepth.o\
../resolver/contMenus.o\
../resolver/getFeatures.o\
../util/cdsListValue.o\
../util/cdsObject.o\
../util/stringToUl.o\
../util/ulToString.o

LIBS = -L$(CDS-LIB) -lCDS

programs = \
 SMB_cleaner

SMB_cleaner: SMB_cleaner.o ${OBJS}
        ${LD} ${LDFLAGS} SMB_cleaner.o ${OBJS} ${LIBS} -o SMB_cleaner

0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 200 total points
Comment Utility
> g++

That would be GNU C++, but I don't believe you can find out the version from the .o files.

>  I also have the source code and found out that "std namespace" was not used

Try putting into a global include...

    using namespace std;

....and compiling it with a modern version of GNU C++, and you may be in business. Do expect a few compilation errors/warnings to address.
0
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
Comment Utility
That will depend. If you are building the files, adding a

#pragma comment(compiler)

(VC++)

will take care of placing that information in the binaries. If not, all you can do is hope that the compiler that was used did that.

Another hint might be the version of e.g. runtime DLLs the binaries rely on (see e.g. the DependecyWalker from www.dependecywalker.com).
0
 

Author Comment

by:huffmana
Comment Utility
TIme is the fire in which we burn - STAR TREK

Because of the changes needed to add namespace (I have other experts-exchange questions about this) there is an great interest to go back to the original compiler.  This idea is that we need to run under both the Solaris 8 and 10 standard installations and we are afraid that the latest gcc will not run under Solaris 8.....  Does this make sense?  Thanks, Allan

0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 300 total points
Comment Utility
>>we are afraid that the latest gcc will not run under Solaris 8

Not necessary to be afraid - see

http://www.sunfreeware.com/sol8right.html

and

http://www.sunfreeware.com/programlistsparc8.html#gcc34

Which GCC version are you using now? BTW, GCC 3.4.2 definitely conforms to ANSI C++, so your code will definitely compile if you didn't use any exotic features.
0
 

Author Comment

by:huffmana
Comment Utility
Also I would have to find out the --compile options even if I traced it to the original gcc version.  For now I'm going to keep going with gcc 3.4.2.  Now that I have gotten over the struct problem (see the following) :-}  Note that the struct had to be put explicity into the std namespace!!  
Thanks everyone for your help.  Best Regards, Allan

using namespace std;              // added Allan

namespace std                        // added Allan
{                                            // added Allan
template <>
struct less<MenuID>
  : public binary_function<MenuID, MenuID, bool>
{
        bool operator()(const MenuID & mid1, const MenuID & mid2) const
        {
                if (
  .
  .
  .
        }
};

}                           // added Allan

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>Note that the struct had to be put explicity into the std namespace!!

Yes, that was clear from your previous Q.
0
 

Author Comment

by:huffmana
Comment Utility
Sorry JKR, I should have noticed that that was you.  I should have referenced that question and not acted like I solved the problem on my own.  Sorry for the faux-pas. Allan
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Never mind ;o)
0
 
LVL 23

Expert Comment

by:brettmjohnson
Comment Utility
When using gcc, the following macros are predefined.  You can use them to assemble a compiler version string that you embed in the .o files (as a static string constant).  Once the compiler version is embedded within the .o file, you can use something like the 'strings' command to extract it.

__GNUC__
This macro is defined if and only if this is GNU C. This macro is defined only when the entire GNU C compiler is in use; if you invoke the preprocessor directly, `__GNUC__' is undefined. The value identifies the major version number of GNU CC (`1' for GNU CC version 1, which is now obsolete, and `2' for version 2).

__GNUC_MINOR__
The macro contains the minor version number of the compiler. This can be used to work around differences between different releases of the compiler (for example, if GCC 2.6.x is known to support a feature, you can test for __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)).

__GNUC_PATCHLEVEL__
This macro contains the patch level of the compiler. This can be used to work around differences between different patch level releases of the compiler (for example, if GCC 2.6.2 is known to contain a bug, whereas GCC 2.6.3 contains a fix, and you have code which can workaround the problem depending on whether the bug is fixed or not, you can test for __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 6) || (__GNUC__ == 2 && __GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ >= 3)).

__GNUG__
The GNU C compiler defines this when the compilation language is C++; use `__GNUG__' to distinguish between GNU C and GNU C++.


Given the above, I managed to stringify the version using some macros:

#ifdef __GNUC__
#define COMP_VER_STR(x) COMP_VER_XSTR(x)
#define COMP_VER_XSTR(x) #x
#ifdef __GNUG__
  #define COMP_NAME g++
#else
 #define COMP_NAME gcc
#endif
static char compiler_version[] = COMP_VER_STR(COMP_NAME) " " COMP_VER_STR(__GNUC__) "." COMP_VER_ST\
R(__GNUC_MINOR__) "." COMP_VER_STR(__GNUC_PATCHLEVEL__) "";
#undef COMP_NAME
#undef COMP_VER_XSTR
#undef COMP_VER_STR
#endif

#include <stdio.h>

int main()
{
  printf("compiler version: %s\n", compiler_version);
  return 0;
}


Obviously, I would create a header file that hides all this ugliness and gets included into all your source files:


#include <stdio.h>
#include "comp_ver.h"

int main()
{
  printf("compiler version: %s\n", compiler_version);
  return 0;
}

0
 

Author Comment

by:huffmana
Comment Utility
Beautiful, that is what is really needed.  I should like to use your code to imbed the compiler into the binary !!  With your permission.  I'll be happy to add your name :-)

I noticed that the application does check for __GNUC__ but only checks for GNU and does not verify a miminum version number...  and it doesn't keep the results.

Looks Super !!!  Allan



0
 
LVL 23

Expert Comment

by:brettmjohnson
Comment Utility
No problem.
0
 
LVL 23

Expert Comment

by:brettmjohnson
Comment Utility
Also note that the \ linebreak was unintended.  It was a copy-paste artifact.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now