This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 2009-07-27 Status


>    ** At the end of the week, I was able to produce a nice .debug_abbrev 
> with a "blah" string in it.  Yay, I guess, although I'd hoped to have 
> something more substantial.
>    ** Nothing done on relocations yet.  They don't even get dropped. 
> I'm afraid that the strip logic simply won't even remove the debug 
> sections since reloc sections keep referencing them, but I didn't try.

Don't spend time now on those sorts of details.  Don't even think about
ET_REL files for now.  For the prototype I would have started with
tests/ecp.c instead of strip.  

For this prototype/test framework around the actual DWARF data emitters,
keep it to the absolute minimum that lets you run your emitter code.  I
guess it would have done well to say this before you spent time on it last
week, but oh well.

>    ** The code is written so that it should be simple to build several 
> abbreviations from one shape (so that you could partition DIEs of one 
> shape to e.g. those whose values fit into someform_2 and those that need 
> someform_4).  That may actually be too expensive to implement though 
> (runtime-wise), for big die trees, and I'm afraid the gain won't be that 
> big.

Yeah, I've been rethinking that too.  I think it may be better to punt the
consolidation of abstract-form "shapes".  That is, when we collect the
shape, determine the optimal form for each particular attribute value.
We can figure them all out optimally right then, except for refs.
For the first cut, we can just make all refs use DW_FORM_ref_addr,
and all strings use DW_FORM_strp.

For now, I think you should just redo the shape-collection stuff
standalone.  You can build unordered_{set,map} of shape/abbrev info either
beforehand or on the fly in your emitter walk.  Then a little later we can
work that back into the dwarf_output construction to avoid doing the
shape-finding and hash lookup on each DIE during the emitter walk.

So, with DW_FORM_ref_addr then a shape really is an abbrev, 1:1.  Just do
it this way to start.  But keep in mind that we will later have this
splitting into multiple abbrevs per shape, for shapes using ref forms.

> * Next I'd like to have it emit .debug_info.  My current thinking is as 
> follows:
>    ** First grab my trusty Dwarf spec and read through it making sure 
> that what's below makes some sense.

:-) To start with, we'll emit only the 32-bit DWARF format,
(i.e. offset_size hard-wired to 4).  Just stick an XXX comment each place
where we write a header format or an offset_size quantity that will differ
for 64-bit DWARF.

>    ** Start by building a separate binary blob for each DIE, with some 
> pieces uninitialized (references to other dies), but with enough space 
> reserved for that information.

I don't think we want "separate blobs".  We'll "emit" (to memory)
.debug_info as a stream from start to finish, and then back-patch the refs.
The way I envision it is this:

In the ecp/strip wrapper, it does:

      *elf_newdata (newscn) = *elf_getdata (scn, NULL);

For the DWARF sections, we don't do this (or we just change ->d_* later to
reverse its effect).  The first elf_newdata call gives an Elf_Data that's
empty.  We have to allocate a chunk to stick in its d_buf/d_size.  What we
can do is just big a random optimal allocation size, just use
Dwarf.mem_default_size and malloc that (uninitialized).  The emitter will
work by discrete form-emitters and header-emitters that do:

	unsigned char *item = alloc (4);
	store_data4 (item, 27);

The "alloc" bit just maintains a rolling allocation pointer into the
current Elf_Data representing the tail of the section.  When the current
chunk (d_buf+d_size-allocptr) does not leave enough size for the item, then
you add a new chunk.  First, seal off the old chunk:

	d->d_size = allocptr - d->d_buf;

Then append a new chunk:

	d = elf_newdata (scn);
	d->d_buf = (void *) new Elf_Byte[d->d_size = mem_default_size];

For now, don't worry about anything beyond that.  At some point in the
future, we can do "frag" splitting for relaxation of ref forms (like the
assembler does).  That is, when we have a ref form we just allocate the
widest size (offset_size) for it while emitting the DIE, and record where
that ref is for the later back-patching.  When we do the back-patching,
that can decide that it can be a shorter ref form.  Then we split that
Elf_Data into two, and shorten the first one's d_size to shave off the
excess few bytes we aren't going to use--then all the later data already in
memory logically shifts back that many bytes in what section offset the
chunks correspond to.

But to start with, don't even do anything for refs at all.  Just emit 0 in
the DW_FORM_ref_addr slot and move on, no records, no splits.  We can do
the other essentials and get as far as emitting data you can look at with
readelf et al, just with all its refs being bogus.  

You could also just skip producing DW_AT_sibling at all for now.

>    ** I think I'll need to create one DW_AT_partial_unit per unique die 
> (except for DW_AT_compile units which are left as are).

Don't worry about this stuff yet.  Just write the emitter code to emit a
DIE as it appears in the logical tree.  The part that loops over the
children should be kept well-separated so that later it is easy to change
how that selects what DIE to recurse on.

>    ** One thing that I'm afraid of is that the size necessary for 
> certain attributes turns out to depend on layout of DIEs.

This is only true for refs.  In fact the compiler only emits DW_FORM_ref4,
i.e. full offset-size.  So the first cut can always reserve offset_size for
each ref and it won't be losing anything in size.  We can get to the fancy
relaxation stuff later.


Thanks,
Roland

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]