Page MenuHomePhabricator

Add ELF dynamic symbol support to yaml2obj/obj2yaml
ClosedPublic

Authored by kastiglione on Nov 2 2017, 5:17 PM.

Details

Summary

This change introduces a DynamicSymbols field to the ELF specific YAML
supported by yaml2obj and obj2yaml. This grouping of symbols provides a way
to represent ELF dynamic symbols. The DynamicSymbols structure is identical to
the existing Symbols.

Event Timeline

kastiglione created this revision.Nov 2 2017, 5:17 PM

Can you add tests?

Also thanks for working on this! I've been needing yaml2obj to support more features of dynamic libraries.

@jakehehrlich I will definitely add tests. I put it up as is to get any initial feedback before writing tests.

I expect I'll need support for some parts of SHT_DYNAMIC, particularly SONAME, so that change might follow this.

In general this looks like a good approach to me. I have concerns about deciding section indexes for users as mentioned but other than that I just have a couple nits.

tools/yaml2obj/yaml2elf.cpp
162–163

.dyn* sections are going to be allocated and so we need to be able place them next to certain other allocated sections so that we can't put them in program headers. It won't be sufficient to decide for the user, at least not this way. One way might be to require that the user add a .dynsym section if they want to use DynamicSymbols and then using the index of that section if they do. This will require that you compute the size of the .dynsym and .dynstr sections early enough for the standard layout algorithm to work.

301

Can this just be "bool IsStatic = STType == SymtabType::Static"? Better yet do we really need SymtabType? What if we just pass "IsStatic" as a parameter?

311

.dynsym should be allocated so sh_flags should be set to SHF_ALLOC if IsStatic is true.

@jakehehrlich thanks for the review! I have more experience with macho/pecoff so I appreciate the insights. I'll update this with tests and something for the section ordering.

tools/yaml2obj/yaml2elf.cpp
301

πŸ€¦β€β™‚οΈ

The choice to use the enum was to avoid opaque true/false arguments at the call site. I'll go with bools if that's preferred.

kastiglione added inline comments.Nov 3 2017, 11:17 AM
tools/yaml2obj/yaml2elf.cpp
162–163

What about making the .dynsym section optional? If it's there, that's the order that's used, and if it no .dynsym section is specified, then this default ordering is used? The same could be applied to these other sections (.symtab etc) if desired.

kastiglione added inline comments.
tools/yaml2obj/yaml2elf.cpp
162–163

@silvas Hi Sean, do you have an opinion on how you would like to see section ordering handled, particularly as it relates to dynamic symbols?

kastiglione added inline comments.Nov 7 2017, 10:55 AM
tools/yaml2obj/yaml2elf.cpp
162–163

@jakehehrlich I have a diff (D39749) to allow the input yaml to control section order. If folks are happy with that, I will rebase this change on top of that, which will allow the .dynsym sections to be ordered as specified in the input.

I'm happy with D39749 and using that to resolve the ordering isue. I'm not a reviewer here but this looks good to me other than the ternary operator nit.

tools/yaml2obj/yaml2elf.cpp
301

I'm not sure I have a preference on bools vs enums, you pick, but the ternary operator use seems funny to me.

kastiglione added inline comments.
tools/yaml2obj/yaml2elf.cpp
301

Agreed, I got rid of this ternary right away, just haven't update the diff.

Rebased on D39749; Added tests

kastiglione marked 3 inline comments as done.Nov 9 2017, 11:57 AM

Fixed unfinished comment updates

This change is ready for a rereview. Note this change depends on D39908, for existing tests to pass.

jakehehrlich edited edge metadata.Nov 10 2017, 11:03 AM

Mostly looks good to me, I want someone to review the ELFDumper and elf2yaml changes but the ELFYAML and yaml2elf changes look good. I just have one request about making .dynstr allocated (see inline).

tools/yaml2obj/yaml2elf.cpp
649

.dynstr needs to have SHF_ALLOC set as well

jakehehrlich added inline comments.Nov 10 2017, 12:48 PM
test/tools/yaml2obj/dynamic-symbols.yaml
30–31 β†—(On Diff #122300)

You should also confirm that these sections a) have type SHT_DYNSYM and SHT_DYNSTR. Also you should check that they have SHF_ALLOC set.

Made .dynstr SHF_ALLOC; Added a few more FileChecks

kastiglione marked an inline comment as done.Nov 10 2017, 1:06 PM

Knowing nothing about elf2yaml this LGTM

silvas accepted this revision.Nov 12 2017, 3:23 PM
silvas added inline comments.
tools/yaml2obj/yaml2elf.cpp
162–163

Sorry for the very late reply. Don't know why it only just now showed up in my inbox.

I really like the approach you've taken in D39749. LGTM.

This revision is now accepted and ready to land.Nov 12 2017, 3:23 PM
This revision was automatically updated to reflect the committed changes.