[LLVMdev] [yaml2obj] ELF relocation support

Michael Spencer bigcheesegs at gmail.com
Wed Apr 2 11:27:03 PDT 2014


On Wed, Apr 2, 2014 at 10:54 AM, Simon Atanasyan <simon at atanasyan.com> wrote:
> Hi,
>
> On Wed, Apr 2, 2014 at 1:03 AM, Michael Spencer <bigcheesegs at gmail.com> wrote:
>> On Mon, Mar 31, 2014 at 10:54 AM, Simon Atanasyan <simon at atanasyan.com> wrote:
>>> As far as I understand now it is impossible to generate ELF object
>>> file with relocation sections using yaml2obj tool. I plan to support
>>> ELF relocations in the yaml2obj. Does anybody work on it already or
>>> plan to start this task soon?
>>
>> I know of nobody working on this. It would be great to have, thanks!
>
> I am going to add "Relocations" optional list to the "Section"
> element. So a YAML file will look like below. An alternative option is
> to introduce new top-level list "Relocation Sections" with "Relocation
> Section" entries. But I think this solution is a little bit over
> designed.
>
> Any objections / suggestions?
>
> [[
> Sections:
>   - Name: .text
>     Type: SHT_PROGBITS
>     Content: "0000000000000000"
>     AddressAlign: 16
>     Flags: [SHF_ALLOC]
>
>   - Name: .rel.text
>     Type: SHT_REL
>     Info: .text
>     AddressAlign: 4
>     Relocations:
>       - !Relocation
>         Offset: 0x1
>         SymbolName: glob1
>         Type: R_MIPS_32
>       - !Relocation
>         Offset: 0x2
>         SymbolName: glob2
>         Type: R_MIPS_CALL16
> ]]
>
> --
> Simon Atanasyan

Explicitly modeling relocation sections is correct here. Just one
thing that would need to change. The yaml reader needs to know that
the structure of SHT_REL sections is different, so it would be:

[[
Sections:
  - Name: .text
    Type: SHT_PROGBITS
    Content: "0000000000000000"
    AddressAlign: 16
    Flags: [SHF_ALLOC]

  - !Relocations
    Name: .rel.text
    Type: SHT_REL
    Info: .text
    AddressAlign: 4
    Relocations:
      - Offset: 0x1
        SymbolName: glob1
        Type: R_MIPS_32
      - Offset: 0x2
        SymbolName: glob2
        Type: R_MIPS_CALL16
]]

When the yaml reader sees the !Relocations tag, it can parse that differently.

Also, I would prefer to keep names as close to the spec as reasonable,
so Symbol instead of SymbolName.

One thing this doesn't cover is dynamic symbol table vs the normal
symbol table, as both can be referenced by relocations in the same
ELF. This is modeled in ELF by the sh_link field. Not sure how we
should do it here (do we even support dynamic symbol tables yet?).

- Michael Spencer



More information about the llvm-dev mailing list