ELF string table access in backend

Hello,

While developing a backend for the custom target I need to create a custom ELF section and put there some mapping of other ELF sections to strings.

For this I have two questions:

  • How can I get a section index in the section table from within target ELF streamer? Is it possible?

  • How can I get access to the string table section, put some string and get back its offset in string table?

If it is not possible maybe there is a way to somehow post-process ELF for this before actually writing to file?

Best regards,

Dmitri Botcharnikov

When you say “the string table” - are you referring to a particular section? There can be multiple/any section that contains strings that can be deduplicated by the linker (see debug_str for example) - and you can create your own sections that have that kind of functionality if you like (again, debug_str might be a goode xample to look at)

201410091712808_BEI0XT4N.gif

Thank you for suggestion. But anyway I have no access to section index so I need ELF post-processing pass. Is there any way to do it in current framework?

--------- Original Message ---------

Sender : David Blaikie dblaikie@gmail.com

Title : Re: [llvm-dev] ELF string table access in backend

When you say “the string table” - are you referring to a particular section? There can be multiple/any section that contains strings that can be deduplicated by the linker (see debug_str for example) - and you can create your own sections that have that kind of functionality if you like (again, debug_str might be a goode xample to look at)

Hello,

While developing a backend for the custom target I need to create a custom ELF section and put there some mapping of other ELF sections to strings.

For this I have two questions:

  • How can I get a section index in the section table from within target ELF streamer? Is it possible?

  • How can I get access to the string table section, put some string and get back its offset in string table?

If it is not possible maybe there is a way to somehow post-process ELF for this before actually writing to file?

Best regards,

Dmitri Botcharnikov










LLVM Developers mailing list
llvm-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Best regards,

Dmitri Botcharnikov

201410091712808_BEI0XT4N.gif

Usually a cross-section reference is done with a symbolic label, not directly using section indexes, because the indexes aren’t determined until very late. A symbolic cross-section reference would turn into an ELF relocation, which would automatically have the correct section index in it. Hopefully you’re not trying to encode the section index of the referencing section into the string.

To put a string into a string section, I would set the correct section, create a temp symbol, use the streamer’s EmitLabel() method to define it, and emit the string as bytes. To reference the string from elsewhere, I’d use an MCExpr (probably MCSymbolRefExpr) to emit a reference to the symbol created previously. You can see this sort of thing in lib/MC/MCDwarf.cpp, I hope without needing to know too much about how DWARF itself works.

–paulr

201410091712808_BEI0XT4N.gif

Thank you for help, Paul!

I finally decided that it would be more convenient to make this ELF post-processing as a separate utility which is quite easy thanks to LLVM J

Best regards,

Dmitri Botcharnikov