Last Comment Bug 523435 - Implement dehydra primitive write_section
: Implement dehydra primitive write_section
Status: RESOLVED WONTFIX
:
Product: Core
Classification: Components
Component: Rewriting and Analysis (show other bugs)
: Trunk
: x86 Linux
: -- normal (vote)
: ---
Assigned To: (dormant account)
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-10-20 12:35 PDT by Diego Novillo
Modified: 2013-02-25 14:54 PST (History)
1 user (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Add write_section primitive (5.09 KB, patch)
2009-10-20 12:35 PDT, Diego Novillo
no flags Details | Diff | Review
Use a js array, add simplistic testcase (3.80 KB, patch)
2009-10-23 14:49 PDT, (dormant account)
dnovillo: review+
Details | Diff | Review

Description Diego Novillo 2009-10-20 12:35:43 PDT
Created attachment 407356 [details] [diff] [review]
Add write_section primitive

This patch implements a new primitive to emit strings to named sections in the output object file:

write_section(section_name, string)

Adds the contents of 'string' to the section named 'section_name'.

function process_decl(v)
{
 write_section (".my_section", "v.name = '" + v.name + "'::");
}

$ g++ -fplugin=dehydra.so '-fplugin-arg-dehydra-=test.js' -c test.cc
$ objdump -j .my_section -s test.o

test.o:     file format elf64-x86-64

Contents of section .my_section:
 0000 762e6e61 6d65203d 20275827 3a3a762e  v.name = 'X'::v.
 0010 6e616d65 203d2027 666f6f27 3a3a762e  name = 'foo'::v.
 0020 6e616d65 203d2027 59273a3a 762e6e61  name = 'Y'::v.na
 0030 6d65203d 20276261 72282927 3a3a      me = 'bar()'::

The script is responsible for generating the section names, they can be intermixed arbitrarily and the string with contents is also any arbitrary string of bytes to dump to the section.

Duplicate sections are combined by the linker. After the object files are generated, standard object file manipulation tools can be used to examine and remove these sections.

This implementation has a minor hack needed because GCC is not exporting the header file needed to call the asm section manipulation routines (output.h).

I will be changing GCC to export output.h, but in the meantime I've surrounded the extra declarations around #ifdef HAS_OUTPUT_H which should be defined in the Makefile if using a GCC that exports output.h.

The other problem I have is with testing.  I could add a test to call write_section() but the harness does not seem prepared to examine object/assembler files.  What would be the best way to do this?

The patch may apply with fuzz.  I'm moving my patch collection over to quilt and cleaning it up so it's suitable for inclusion in dehydra.
Comment 1 (dormant account) 2009-10-23 14:49:57 PDT
Created attachment 408120 [details] [diff] [review]
Use a js array, add simplistic testcase

This crashes with -save-temps. For some reason asm_file_name is set to the .ii file. No idea why previous patch didn't crash.

It would be pretty easy to change this code to group stuff by sections, but I'll leave that as a later optimization.
Comment 2 Diego Novillo 2009-11-23 10:37:37 PST
(In reply to comment #1)
> Created an attachment (id=408120) [details]
> Use a js array, add simplistic testcase
> 
> This crashes with -save-temps. For some reason asm_file_name is set to the .ii
> file. No idea why previous patch didn't crash.

Isn't your patch missing some bits from my original patch?  I had registered the write_section command.  Other than that, it looks fine to me.

> It would be pretty easy to change this code to group stuff by sections, but
> I'll leave that as a later optimization.

I don't think you'll notice much performance difference in grouping the sections.
Comment 3 (dormant account) 2009-11-23 10:42:08 PST
> 
> Isn't your patch missing some bits from my original patch?  I had registered
> the write_section command.  Other than that, it looks fine to me.

I implemented it in JS.
Comment 4 Joshua Cranmer [:jcranmer] 2013-02-25 14:54:56 PST
Dehydra and treehydra are no longer maintained by Mozilla.

Note You need to log in before you can comment on or make changes to this bug.