I'm having some problems with a large static library (.lib) file, and am suspecting code bloat from indiscriminate use of template classes. I want to analyse the symbols in the library to confirm which are making up the bulk of the file size.
When I link my executable against this library, the resulting output is much more sensible, size-wise (about 20Mb), so the linker is obviously stripping out lots of redundant symbols. I want to find out what its removing..
I know I can use dumpbin to generate the symbols and headers, but, with the library in question being pretty large (900Mb), this dump is pretty much unusable without a utility for parsing and reporting on it.
Obviously I could write this myself, but was wondering if anyone can recommend any freeware already available for this?
Is this your own library? If so you can generate a link map that describes the layout of the code in the library, which would give you the info you need here in a more friendly form.
If you don't have source code access to do this, you could use Perl or other open-source scripting tools to crack the dumpbin output.
EDIT: you could also give LibDump a spin, it's downloadable from here. I have not used this myself.
I found one (SymbolSort) that works really well, gives me exactly what I need:
Related
I am building a shared library for the Debian GNU/Linux distribution and I am worried about the number of symbols from internal functions that it exports without any need. Since the library is built using autoconf/automake/libtool, the answer is easy: I can just add -export-symbols libfoo.sym to libfoo_la_LDFLAGS and specify only the symbols I want exported in that file.
But since this involves error-prone manual work, I figured that there has to be a better way. Is it possible to automate reading the (in this case) dozens of .h files that accompany the library and generate a first version of the libfoo.syms file.
Could I just use the C (or C++) compiler to do the busy work for me?
This is equivalent to extracting function prototypes and covered here:
Extracting C / C++ function prototypes
But since this involves error-prone manual work, I figured that there has to be a better way. Is it possible to automate reading the (in this case) dozens of .h files that accompany the library and generate a first version of the libfoo.syms file.
It might be more useful to use nm on the object files instead of trying to parse header files. nm can be told to restrict the output to just exports.
Could I just use the C (or C++) compiler to do the busy work for me?
Certain compilers have tools to assist with this, like gcc's visibility support.
But the real problem is you must know what functions must be exported and which must not.
A bit of a simple question, though the answer may not be. I am fairly new to C++ and was wondering if it was possible to open a C++ library and see it's code. It sounds like a potentially risky move to accidentally change the core code of the library, but I would still like to see if it is possible. Thank you!
There are too kinds of libraries that C++ can use:
compiled to binary libraries which are linked with linker to your
executable;
headers-only libraries which are just included with include into
your source code
You can "open" headers of headers-only libraries and modify code if you wish (but not recommended).
Also many compiled libraries are open source. You can open source files there. If you want to modify such library, you will need to compile it and link your executable against this modified version.
Yes it s possible to open a c++ library and see its code.
If you want to make changes to any functionality simply create your own version of it giving it a different name, or if you want to add functionality just simply extend the class you are interested in. (read up on inheritance for this).
I have some other coders c++ library which contains source file, makefile etc. I am interested in understanding this library. i.e. what it does(it is poorly documented), how it does, etc.
One way I have is to include this as a library in my code. But I dont want that as I want to debug the code using netbeans(in order to understand the code flow).
Is there some way by which I may debug the library in order to understand it.
Now when I just merely copy paste the other programs code into my netbeans project. It gives me makefile problems. Is there some other way out?
Also the other programmers library has a lot of errors.
From a compiled file, can I see which compiler has been used to generate the file?
There's also the good old 'strings' utility. Dumps all ascii-ish looking strings it finds in the binary. Different compilers embed different amounts of information in the binaries they produce, but many will actually include obviously identifying strings.
Many compilers/linkers insert a .comment section in the output file which identifies them. There are also a number of more subtle behaviors you could create compiler fingerprints off of, but I know of no existing tools for this.
If you have the source, the easiest solution would be to try compiling with each compiler in question until you get a binary that matches byte-for-byte (or even closely).
In some cases you can run ldd on the binary and find out which standard library it's linked against. For example on Solaris gcc vs Sun CC vs whatever.
For C++ code, you can also dump some of the symbols, find a mangled function name, and then figure out which demangler generates the correct original name.
Try, IDA Pro which identifies the libraries and tools used to build up executable file.
I was answering a quiz in a Blue Team website, and this was a question. I found the solution using a tool called PE Detective, he looks for signatures on the EXE, works really fine
https://www.softpedia.com/get/System/File-Management/PE-Detective.shtml
I need to gprof a library in our system to examine the function calls and see if we can optimize it any more. Basically, what I have is
Executable A which uses a shared Library myLib.so
I want to gprof the myLib.so. When I compile myLib.so source using -pg option, it produces a .so file just fine.
But, recompiling the Executable A against that library is not producing the *.gmon file for some reason. What needs to be done? Should I link the myLib statically? If so, please tell me how. I am a newbie, so pardon my ignorance. I am learning everyday
thanks in advance.
You can do better than gprof.
You could use a good sampling profiler like RotateRight/Zoom, or you could try this technique. Also lsstack serves well. pstack does too, but is more work for you.
I have the same issue, but I think the best thing to do is to create a small C/C++ program that uses the library with some test calls, compile it with the library using -pg, and profile that.
That way you nicely isolate the profiling issues of the library from other stuff, too.
As http://sourceware.org/binutils/docs/gprof/Implementation.html and https://stackoverflow.com/a/7290284/885650 point out, you need -pg when linking, as it adds extra code everywhere.