Commit Graph

32 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 7bfb1aa80f libctf: Enlarge the 'cmd' buffer to not possibly truncate the pathname
Addressing this compiler warning:

  [ 22%] Building C object CMakeFiles/dwarves.dir/libctf.c.o
  /home/acme/git/pahole/libctf.h: In function ‘ctf__encode’:
  /home/acme/git/pahole/libctf.c:744:62: error: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4064 [-Werror=format-truncation=]
    snprintf(cmd, sizeof(cmd), "objcopy --add-section .SUNW_ctf=%s %s",
                                                                ^~
      pathname, ctf->filename);
      ~~~~~~~~
  /home/acme/git/pahole/libctf.c:744:2: note: ‘snprintf’ output 34 or more bytes (assuming 4129) into a destination of size 4096
    snprintf(cmd, sizeof(cmd), "objcopy --add-section .SUNW_ctf=%s %s",
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      pathname, ctf->filename);
      ~~~~~~~~~~~~~~~~~~~~~~~~
  cc1: all warnings being treated as errors

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-07-02 12:14:02 -03:00
Arnaldo Carvalho de Melo f601f67258 libctf: The type_ids returned are uint32_t fixup where it was uint16_t
To help in the tree wide conversion to uint32_t to represent type IDs.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-03-11 11:44:53 -03:00
Domenico Andreoli e714d2eaa1 Adopt SPDX-License-Identifier
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-01-18 15:41:48 -03:00
Arnaldo Carvalho de Melo a54515fa6e dwarves: Stop using 'self'
As Thomas Gleixner wisely pointed out, using 'self' is stupid, it
doesn't convey useful information, so use sensible names.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-17 18:47:15 -03:00
Rakesh Pandit 537db1da2d libctf: Replaces deprecated elf_getshstrndx with elf_getshdrstrndx
Removes irritating warning while compilation.

Signed-off-by: Rakesh Pandit <rakesh@fedoraproject.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-12-29 11:36:47 -02:00
Arnaldo Carvalho de Melo 1701b6d68d dutil: Allow returning the section index in elf_section_by_name
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 11:53:05 -03:00
Arnaldo Carvalho de Melo 1d7bea33b7 libctf: ctf__delete must call elf_symtab__delete
Its used when loading a CTF file, not when encoding.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 09:45:15 -03:00
Arnaldo Carvalho de Melo 4f5e2226de ctf_encoder: ctf__encode has to free the buf when compressing
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 09:25:48 -03:00
Arnaldo Carvalho de Melo bd68f6bbc1 ctf_encoder: We have to free the gobuffer entries for the sections
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 09:22:48 -03:00
Arnaldo Carvalho de Melo 486299a359 ctf: Plug debug_fmt_ops->strings__ptr
So that we can use the strings in ".strtab" directly, without duplicating them
on the global strings table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 17:55:17 -03:00
Arnaldo Carvalho de Melo 9bb29daac4 base_type: Don't combine names with attributes
Such as signed, etc. This is in preparation for using directly ctf_strings.
Instead of duplicating it in the global strings table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-02 16:12:36 -03:00
Arnaldo Carvalho de Melo deb509cf6c libctf: Ignore hidden symbols
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-01 14:03:04 -03:00
Arnaldo Carvalho de Melo 9f4cedc61d ctf_encoder: ctf__ignore_symtab_object should ignore symbols with dots
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 18:19:19 -03:00
Arnaldo Carvalho de Melo d7d419f6ab ctf_encoder: Create objects section (data/variables)
Encoding all the non UNDEF OBJECT entries in the symtab. Some must be filtered
in upcoming patches, but for at least kernel/sched.o it works just fine.

To test it I used DaveM's ctfdump and also pdwtags on a --strip-debug, pahole
-Z CTF encoded object.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 16:12:00 -03:00
Arnaldo Carvalho de Melo 83d2438698 gobuffer: Introduce gobuffer__copy
To replace some long open coded sequences.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-31 15:54:53 -03:00
Arnaldo Carvalho de Melo 3b530f8f14 ctf_loader: Load the function section
Iterating thru the symtab and getting the missing info from
ctf_header->ctf_func_off.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:52:37 -03:00
Arnaldo Carvalho de Melo 0a924bf4eb ctf_encoder: Interface to encode functions
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:49:13 -03:00
Arnaldo Carvalho de Melo 0f97ea0329 libctf: fix ctf__delete
It should free ->filename and only close the file and call
elf_end if it was opened at ctf__new.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:05:54 -03:00
Arnaldo Carvalho de Melo 60e76245b8 core: Allow cachine an open Elf file handle for reuse
pahole --ctf_encode being the first to put this to good use.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-30 22:00:39 -03:00
Arnaldo Carvalho de Melo ed0c3ae7d1 ctf: Move ctf_format_flt_attrs from the loader to libctf
It is not glue from CTF to the core, it is pure CTF stuff.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-25 11:29:13 -03:00
Arnaldo Carvalho de Melo 2fd3936a9d ctf: combine the structs ctf_state and ctf
Moving more CTF only stuff out of the dwarves land and into something that can
be more easily stolen by other projects not interested in funny named stuff
such as pahole.

This also will help with encoding, as we will normally be recoding data from
DWARF, so the ELF file will be available and we will just add a new section to
it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 18:12:11 -03:00
Arnaldo Carvalho de Melo 49f590e3b9 libctf: Adopt ctf__string from ctf_loader.c
The ctf_loader.c file should be a direct counterpart to dwarf_loader,
that is, it should have just use what is in libctf to decode the CTF
sections and convert it to the core format in dwarves.[ch].

Also introduce a ctf__string32 for the very common idiom:

ctf_string(ctf__get32(sp->ctf, &tp->base.ctf_name), sp);

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 17:13:40 -03:00
Arnaldo Carvalho de Melo da177f87a3 ctf_encoder: Check if something was encoded before saving the info
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 13:20:24 -03:00
Arnaldo Carvalho de Melo ce97ac9a26 ctf_encoder: Allow encoding a bit_size in enumeration types
As we have to support enum bitfields, so remember the bit_size.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-20 12:51:30 -03:00
Arnaldo Carvalho de Melo fedbfb60ff libctf: Encode VARARGS an extra 0 short at the end of the parm list
We'll see if this is how things should be, but its good enough for me 8)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 20:10:33 -03:00
Arnaldo Carvalho de Melo dcef613288 libctf: give up "for now" on using libelf to add a section to an existing file
And use what worked so far, that is: if the section is already there,
replacing its contents works, because probably all the relocation was
done... If not, be a chicken and call system("objcopy..."), but...
I'llll be bahck!

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 19:41:14 -03:00
Arnaldo Carvalho de Melo f2495cd1a6 libctf: comment out some debug messages
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 19:17:41 -03:00
Arnaldo Carvalho de Melo feab8aa5e3 ctf: Include the initial implementation of a ctf encoder
"pahole -Z foo" will create foo.SUNW_ctf, that if objcopy
--add-section'ed to the right word-sized object will work, sans VARARGS,
that will get fixed soon (as in, probably, tomorrow).

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:16:07 -03:00
Arnaldo Carvalho de Melo f7a428ef24 ctf: Add a filename member to struct ctf
That will be later used when encoding the CTF info.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-19 12:14:01 -03:00
Arnaldo Carvalho de Melo 7dfd45ffea libctf: The constructor should load only if a buffer is passed
So that we can create a ctf object and then populate it, to do the
encoding.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2008-09-25 16:25:06 -03:00
Arnaldo Carvalho de Melo 36f454820e libctf: Use the same coding style as the dwarves
Use __ as a separator for the method names, self, new/delete, use
stdint.h types, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2008-09-25 16:01:26 -03:00
Arnaldo Carvalho de Melo 2dfa5fe6ea [DWARVES]: Initial CTF support
Using a library written by David S. Miller.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2008-03-04 15:37:02 -03:00