J_S
J_S

Reputation: 3272

objdump and objcopy as a c/c++ library

I need to perform objdump on an ELF to get address and/or sizes of specific functions and variables as well objcopy to convert it to a different format for operations performed later. Especially with the first part, some of the operations done on the result of objdump are a bit complex, so I went with creating a small C++ application to perform that. It works, however it currently calls the gcc's objdump and objdopy directly including its parameters with a system call.

There are multiple reasons why I don't like this approach, main one of which being that I either need to rely on user having them on the PC or distribute them with my own executable and treat it as a kind of dynamic library, but in form of executables, which I don't like either.

My question is, is there some form of (gcc?) library that I could (preferably statically) link to perform same operations that way? I'd really rather use something as close do gcc, especially when it comes to compatibility with gcc produced files as input and giving same output, as I already have that kind of version of my own executable working.

Upvotes: 2

Views: 1760

Answers (2)

Zan Lynx
Zan Lynx

Reputation: 54325

All of those obj* tools are based on the BFD library. If you look at how objdump does its thing and copy it, you should be able to do the same in your own code.

Another thing that you can do is just copy the code from objdump and friends into your own programs. It's open source and you can do that. All you need is to make your own programs also GPL, which they'd have to be anyway to use the BFD library.

Upvotes: 4

Cheatah
Cheatah

Reputation: 1835

The programs objdump and objcopy are not part of gcc, they are part of binutils. Speaking of which: libbfd and libopcodes are also part of binutils, and those contain functions you might be able to use.

Upvotes: 2

Related Questions