This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj]Allow explicit symbol indexes in relocations and emit error for bad names
ClosedPublic

Authored by jhenderson on Feb 21 2019, 7:44 AM.

Details

Summary

Prior to this change, the "Symbol" field of a relocation would always be assumed to be a symbol name, and if no such symbol existed, the relocation would reference index 0. This confused me when I tried to use a literal symbol index in the field: since "0x1" was not a known symbol name, the symbol index was set as 0. This change fallsback to treating unknown symbol names as integers, and emits an error if the name is not found and the string is not an integer.

Note that the Symbol field is optional, so if a relocation doesn't reference a symbol, it shouldn't be specified. The new error required a number of test updates.

This change relies on D58508 landing first with LLD test changes (I haven't got a monorepo checkout sorted out yet).

Diff Detail

Repository
rL LLVM

Event Timeline

jhenderson created this revision.Feb 21 2019, 7:44 AM
ruiu accepted this revision.Feb 21 2019, 10:32 AM

LGTM

This revision is now accepted and ready to land.Feb 21 2019, 10:32 AM
grimar added inline comments.Feb 22 2019, 12:23 AM
test/tools/yaml2obj/relocation-explicit-symbol-index.yaml
2 ↗(On Diff #187796)

Do you need --docnum?

10 ↗(On Diff #187796)

I would suggest doing something like we have in LLD tests here to show the values
you want to pay attention to explicitly. e.g.:

# CHECK-NEXT:     0000: 011B033B 1C000000 02000000 A80E0000
##                               ^        ^-- FDE(1) PC
##                               ^-- Number of FDEs
# CHECK-NEXT:     0010: 38000000 AA0E0000 50000000
##                               ^-- FDE(2) PC

Up to you though.

grimar added inline comments.Feb 22 2019, 12:27 AM
tools/yaml2obj/yaml2elf.cpp
538 ↗(On Diff #187796)

I suggest merging ifs

if (Rel.Symbol && SymN2I.lookup(*Rel.Symbol, SymIdx) &&
    !to_integer(*Rel.Symbol, SymIdx)) {
jhenderson marked 5 inline comments as done.Feb 22 2019, 2:50 AM
jhenderson added inline comments.
test/tools/yaml2obj/relocation-explicit-symbol-index.yaml
2 ↗(On Diff #187796)

No, that was left over from a previous version of this test.

10 ↗(On Diff #187796)

I like that idea, thanks.

jhenderson marked 2 inline comments as done.

Address review comments.

grimar accepted this revision.Feb 22 2019, 3:08 AM

LGTM

I just ran into https://bugs.llvm.org/show_bug.cgi?id=40818, which is preventing me landing this change as is. I could modify the llvm-objcopy compress-debug-sections.yaml file to not reference a symbol at all, but I think that loses some of the intention of that test (plus it would just hide the bug).

I just ran into https://bugs.llvm.org/show_bug.cgi?id=40818, which is preventing me landing this change as is. I could modify the llvm-objcopy compress-debug-sections.yaml file to not reference a symbol at all, but I think that loses some of the intention of that test (plus it would just hide the bug).

This bug has been fixed, but it revealed https://bugs.llvm.org/show_bug.cgi?id=40885, which also blocks this change unless I workaround it (I may do so for expediency, but I have other things to look at in the meantime).

This revision was automatically updated to reflect the committed changes.