Hunting for the .SUNW_ctf

In order to actually do something with the CTF data, we must first obtain it. The location – if everything was compiled and converted appropriately – is the ELF section named “.SUNW_ctf”. Hence I started my today’s research by listing all the sections one by one and for each comparing the name stored in the ELF string table to our searched section name. After a successful match, we proceed to get hold of the actual data. Luckily, the libelf API is well designed and all this was really straightforward. The important part of the code:

while ((section = elf_nextscn(elf, section)) != 0)
  gelf_getshdr(section, &section_header);
  char *section_name = elf_strptr(elf, elf_header->e_shstrndx,

  printf("%s\n", section_name);

  if (strcmp(section_name, ".SUNW_ctf") == 0)
    Elf_Data *data = elf_getdata(section, NULL);
    for (unsigned int i = 0; i < data->d_size; i++)
      printf("%c", ((char*)data->d_buf)[i]);

The whole code can be found here: elfctf.c (disclaimer: the code is nowhere near ideal state, there are no comments and no error checking, it is just a proof of concept).

After fixing the absence of the elements mentioned above, this code may be used in the rewrite of the CTF toolset, starting with the ctfdump. I would like to keep the libelf code out of the libctf for a simple-enough reason: keeping the library as light as possible when it comes to dependencies.

A small thought near the end: since there is no real connection anymore with the Sun Microsystems or Solaris, it might be suitable to rename this section to pure “.ctf”. There are not that many consumers of the CTF data that would need to change, most notably the D-Trace and the CTF toolset (ctfdump, ctfconvert and ctfmerge).

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s