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:
Adds the contents of 'string' to the section named 'section_name'.
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.
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.
(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.
> 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.
Dehydra and treehydra are no longer maintained by Mozilla.