From: Daniel W. <dan...@gm...> - 2014-07-21 22:04:19
|
In general I have found the elftoolchain documentation to be quite incomplete. Below are the notes I wrote for myself on a way to build on Ubuntu which worked for me. I had to discover the NOGCCERROR=1 through an amazing amount of detective work, grepping through files, etc. You will find that once you have elftoolchain building that the lack of documentation does not stop there. See below for some help in getting started. Libelf and Libdwarf are APIs to nowhere: they are full of functions that tell you how to get a foo from a bar, but do not tell you how to get a bar in the first place or what you can do with a foo once you have one. See below for some example of APIs to nowhere that I have never figured out; if you do figure them out, please do let me know. Daniel === getting started To get started with elf, call elf_begin() and then gelf_getehdr() on that. Iterating over elf sections: elf_nextscn(). Getting info on the section: gelf_getshdr(). Getting the name of a section: get the elf section string table using do_elf_getshdrstrndx(), then use elf_strptr(). Iterating over the data in a section seems to require two levels of iteration: elf_getdata() which gives you a sequence of Elf_Data objects, but then for each of those is a block of data in a elf_data->d_buf of length elf_data->d_size. To get started with dwarf, call Dwarf_Debug dwarf_debug; dwarf_elf_init(elf.elf, DW_DLC_READ, NULL, NULL, &dwarf_debug, &dwarf_error); Then, to get the root of the DWARF tree of DIE objects, make this amazingly intuitive incantation: dwarf_next_cu_header (dwarf_debug, NULL, NULL, NULL, NULL, NULL, &dwarf_error); Yes, that is five NULL-s in a row. Note that the dwarf_debug is an *iterator* over the compilation units of the ELF. THEN, do this obvious thing: dwarf_siblingof(dwarf_debug, NULL, &root_die, &dwarf_error); So to get the root of the DIE tree for a compilation unit, you ask for the sibling of emptiness. Yup. === an example of an API to nowhere: dwarf forms Here are some things I have yet to figure out and are great examples of APIs to nowhere: suppose you use dwarf_whatform() to get the form of an attribute (pretend you know what that means), some possible forms are as follows. case DW_FORM_block: case DW_FORM_block1: case DW_FORM_block2: case DW_FORM_block4: Well you can use dwarf_formblock(at, &block, &dwarf_error) to get the form block from the attribute. This leaves you with a Dwarf_Block *block object. Well that's handy, but I have NO CLUE WHATSOEVER what I can do with a Dwarf_Block object. case DW_FORM_exprloc: Dwarf_Unsigned exprloc_len; Dwarf_Ptr exprloc; Same thing: dwarf_formexprloc(at, &exprloc_len, &exprloc, &dwarf_error) leaves me with a block of memory delimited by essentially a void* and a length. What is in that block of stuff I don't know. case DW_FORM_ref_addr: case DW_FORM_sec_offset: Dwarf_Off ref_offset; This dwarf_global_formref(at, &ref_offset, &dwarf_error) leaves me with some sort of global reference offset that I have no idea how to de-reference. case DW_FORM_ref1: case DW_FORM_ref2: case DW_FORM_ref4: case DW_FORM_ref8: case DW_FORM_ref_udata: I did figure out how to deref a similar sounding different kind of reference by using dwarf_formref(at, &ref_offset, &dwarf_error) and then using dwarf_offdie(dwarf_debug, ref_offset, &ref_die, &dwarf_error) on the result. === building elftoochain on Linux The build process will stop and tell you to do this if you do not do it initially: Please download the distribution from: http://tetworks.opengroup.org/downloads/38/software/Sources/3.8/tet\ 3.8-src.tar.gz and unpack it into directory "../../test/tet/tet3.8". Note that when building on Linux, the instructions are wrong: just using pmake will not work, you must invoke it as follows: $ NOGCCERROR=1 pmake You must install elftoolchain in order to build against it; it is not enough to just use -I and -L flags as the internal headers within elftoolchain will not find each other. Or, if there is a way to do it, I do not know how. $ sudo pmake install On Mon, Jul 21, 2014 at 10:09 AM, S. Bharadwaj Yadavalli <bha...@or...> wrote: > > > On 07/20/2014 12:52 PM, Joseph Koshy wrote: >>> First, apologies, if the following are newbie questions. >>> >>> 1. I attempted to build elftoolchain on Ubuntu and get the following >>> kinds of warning-triggered errors for ac_detect_ar, archive_read_finish, >>> ac_read_objs, ac_write_objs and archive_write_finish >>> >>> archive.c: In function ‘ac_detect_ar’: >>> archive.c:353:2: error: ‘archive_read_support_compression_none’ is >>> deprecated (declared at /usr/include/archive.h:323) >>> [-Werror=deprecated-declarations] >>> archive_read_support_compression_none(a); >>> ^ >>> Is this known? What is the recommended way to address this build problem? >> >> 1. Which version of Ubuntu are you building on? > > I am building on Ubuntu 13.10. > >> 2. What's the version of the libarchive package that you are using? > > 13.1.2 > > $ ls -l /usr/lib/x86_64-linux-gnu/libarchive.so > lrwxrwxrwx 1 root root 20 Apr 4 2013 > /usr/lib/x86_64-linux-gnu/libarchive.so -> libarchive.so.13.1.2 > > Thanks, > > Bharadwaj > > ------------------------------------------------------------------------------ > Want fast and easy access to all the code in your enterprise? Index and > search up to 200,000 lines of code with a free copy of Black Duck > Code Sight - the same software that powers the world's largest code > search on Ohloh, the Black Duck Open Hub! Try it now. > http://p.sf.net/sfu/bds > _______________________________________________ > Elftoolchain-developers mailing list > Elf...@li... > https://lists.sourceforge.net/lists/listinfo/elftoolchain-developers |