This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] - Make .symtab to be not mandatory section for SHT_REL[A] section.
ClosedPublic

Authored by grimar on Oct 21 2019, 7:37 AM.

Details

Summary

Before this change .symtab section was required for SHT_REL[A] section
declarations. yaml2obj automatically defined it in case when YAML document
did not have it.

With this change it is now possible to produce an object that
has a relocation section, but has no symbol table.

It simplifies the code and also it is inline with how we handle Link fields
for another special sections.

Diff Detail

Event Timeline

grimar created this revision.Oct 21 2019, 7:37 AM
grimar updated this revision to Diff 226630.Oct 28 2019, 3:58 AM
  • Rebased.
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2019, 3:58 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
grimar edited the summary of this revision. (Show Details)Oct 28 2019, 3:58 AM

I'm not sure I follow why in most cases adding Symbols: [] is necessary? Could you explain the detailed impact of this change, with regards to when .symtab will/won't be generated and when the Link: .symtab is/is not required for relocation sections now?

llvm/test/tools/llvm-objcopy/ELF/no-symbol-relocation.test
24

Could you file a bug for this issue, if it doesn't already exist, please?

grimar marked an inline comment as done.Oct 28 2019, 7:37 AM

I'm not sure I follow why in most cases adding Symbols: [] is necessary? Could you explain the detailed impact of this change,
with regards to when .symtab will/won't be generated

Before this change we generated .symtab when there was the Symbols: tag in the YAML document and/or when there was a
REL[A] section that has an empty "Link" (i.e. normally it happened when it just was not specified).

After this change we only generate '.symtab' when there is Symbols: tag. When there is no 'Symbols:`, we do not generate it.
I.e. this patch lefts no more special handling for REL[A] sections.

and when the Link: .symtab is/is not required for relocation sections now?

So, if Link: .symtab is specified, you must provide the Symbols:, otherwise it will not find the referenced symbol table section.
Just like if you provide 'Link: .foo', you have to provide '.foo' section.

llvm/test/tools/llvm-objcopy/ELF/no-symbol-relocation.test
24

It will be fixed by D69304.

I am going to add an inline comment on each change where I added/removed "Symbols: []" or" Link: .symtab" to make it more clear why it was done.

I am going to add an inline comment on each change where I added/removed "Symbols: []" or" Link: .symtab" to make it more clear why it was done.

Thanks, I think that will be a bit clearer.

grimar marked 7 inline comments as done.Oct 28 2019, 8:28 AM

Here are comments for changes in test cases.

llvm/test/Object/invalid.test
336

Here we test the following error message:
"unable to access section [index 2] data at 0x18000040: offset goes past the end of file"

Without Symbols: [] yaml2obj does not create a .symtab.
.rela.text has sh_link == 0 then and we get a different error message instead of one we check:

"section [index 0] has invalid sh_entsize: expected 24, but got 0"

llvm/test/Object/objdump-sectionheaders.test
42

One of the lines we check is:
"# CHECK: 5 .symtab 00000018 0000000000000000"

I added "Symbols: []" to create the .symtab. Previously it was created by default because SHT_RELA has no Link specified.
This patch removes this special logic, so we need to specify "Symbols: []" explicitly.

llvm/test/tools/llvm-readobj/all.test
113

I added it to create the ".symtab" to test the "Symbol table '.symtab' contains {{.*}} entries:" line.

Previously it was created automatically because .rela.data had an empty Link field:
(i.e. had no field at all)

- Name: .rela.data
  Type: SHT_REL
  Relocations:
llvm/test/tools/llvm-readobj/elf-reloc-negative-addend-no-sym.test
32

With it this test would fail, since there is no symbol table anymore. It was created implicitly before, because of .rela.dyn section, which does not have Link specified.

We do not need a symbol table for this test, so instead of adding a "Symbols: []" line, I've just removed the reference.

llvm/test/tools/obj2yaml/elf-ppc64-relocations.yaml
15

The same as above. We do not create the symbol table by default for .rela.text and we do not need to have this reference to test the relocations here.

llvm/test/tools/obj2yaml/no-symbol-reloc.test
27

This is a cleanup change. We do not need a "Link" or a symbol table for this test.

llvm/test/tools/obj2yaml/relocation-unsupported-machine.yaml
15

The yaml below does not have "Symbols: []", and we do not create a symbol table by default for .rela.text anymore.
Hence, we do not set the sh_link too.

This revision is now accepted and ready to land.Oct 28 2019, 8:48 AM
This revision was automatically updated to reflect the committed changes.