This is an archive of the discontinued LLVM Phabricator instance.

[obj2yaml] - Refactor how we dump sections. NFCI.
ClosedPublic

Authored by grimar on Mar 24 2020, 4:10 AM.

Details

Summary

This is a NFC splitted from D75342.

Previously obj2yaml never dumped a normal SHT_NULL section (i.e. when it is just zeroed)
or non-allocatable SHT_STRTAB/SHT_SYMTAB/SHT_DYNSYM sections.

This patch does not change the output, but it changes the logic so that we now dump these
sections, and them remove them later. It allows us to create and work with our internal representation
of sections, i.e. to work with the vector of Chunks, what looks cleaner.

It is used by D75342 and also should help us to support dumping a content that does not
belong to a section (i.e. to dump some data as Fill chunks).

Diff Detail

Event Timeline

grimar created this revision.Mar 24 2020, 4:10 AM
jhenderson added inline comments.Mar 25 2020, 2:05 AM
llvm/tools/obj2yaml/elf2yaml.cpp
119–120

Could you explain this case, please, perhaps with a comment in the code?

287

dumpPlaceholderSection maybe? Slightly shorter name.

351

Looks like you have a copy-paste/formatting error around shouldPrintSection().

grimar updated this revision to Diff 252526.Mar 25 2020, 3:06 AM
grimar marked 4 inline comments as done.
  • Addressed review comments.
llvm/tools/obj2yaml/elf2yaml.cpp
119–120

It is for obj2yaml\elf-null-section.yaml. We have the following YAML description there:

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
Sections:
  - Type: SHT_PROGBITS
    Name: .foo
  - Type:         SHT_NULL
    Name:         ''
    Flags:        [ SHF_ALLOC ]
    Link:         1
    Info:         2
    AddressAlign: 0x3
    Size:         0x4
    EntSize:      0x5
    Address:      0x6

Note: SHT_NULL has empty name and it is the second SHT_NULL section in the object.
(first one is one at index 0, created implicitly).

We expect that obj2yaml produce the following;

# SECOND-SEC-NEXT:   - Type:         SHT_NULL
# SECOND-SEC-NEXT:     Flags:        [ SHF_ALLOC ]
# SECOND-SEC-NEXT:     Address:      0x0000000000000006
# SECOND-SEC-NEXT:     Link:         .foo
# SECOND-SEC-NEXT:     AddressAlign: 0x0000000000000003
# SECOND-SEC-NEXT:     EntSize:      0x0000000000000005
# SECOND-SEC-NEXT:     Content:      '00000000'
# SECOND-SEC-NEXT:     Info:         0x0000000000000002

But now since we started to dump SHT_NULL sections (we remove it later), obj2yaml produces:

- Name: ' [1]'

But it doesn't make sense I think. We should not uniquify empty names. I see no reasons for that.

jhenderson accepted this revision.Mar 26 2020, 2:01 AM

LGTM, with nit.

llvm/tools/obj2yaml/elf2yaml.cpp
119–120

Seems reasonable for now. I doubt we'll have many (any?) cases where we want to reference multiple different sections with empty names.

121

an output -> the output

This revision is now accepted and ready to land.Mar 26 2020, 2:01 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 26 2020, 4:18 AM
MaskRay added inline comments.Mar 26 2020, 9:22 AM
llvm/tools/obj2yaml/elf2yaml.cpp
119–120

After checking STT_SECTION, I think st_name=0 cases should be very rare.