This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj][obj2yaml][test] - Add base tests for relocation addends.
ClosedPublic

Authored by grimar on Mar 3 2020, 7:40 AM.

Details

Summary

We had no test for Addend field of a relocation. Though the
current behavior is not ideal and might need to be fixed.

This patch adds 2 test cases to document the current
behavior and add a few FIXMEs. These FIXME are fixed in the
follow-up: https://reviews.llvm.org/D75527

Diff Detail

Event Timeline

grimar created this revision.Mar 3 2020, 7:40 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: emaste. · View Herald Transcript
MaskRay added inline comments.Mar 3 2020, 10:15 AM
llvm/test/tools/obj2yaml/relocation-addend.yaml
23

The stdint.h constant is named INT64_MIN

Testing the hexadecimal literal will be useful, too.

grimar marked an inline comment as done.Mar 4 2020, 12:32 AM
grimar added inline comments.
llvm/test/tools/obj2yaml/relocation-addend.yaml
23

It is a test for obj2yaml, it only can print decimals.

Hexadecimal values as inputs are tested in yaml2obj test suite.

The stdint.h constant is named INT64_MIN

I'll rename, thanks.

jhenderson added inline comments.Mar 5 2020, 1:49 AM
llvm/test/tools/obj2yaml/relocation-addend.yaml
2

Should we check 0 too? Not sure really, but I suppose it shows that the value 0 is printed, despite being entirely leading zeroes.

8

-1 -> 1

23

You don't need the '=' sign here. Just "with the value INT64_MIN" works.

55

-1 -> 1

llvm/test/tools/yaml2obj/ELF/relocation-addend.yaml
2

handles relocation addend descriptions

14

Single '#'.

17

in decimal form

Same elsewhere

28

'#'

I think a signed integer representation may look better in most situations. r_addend is usually additive, e.g. S + A, G + A. Due to PC-offset bias, an r_addend on x86-32/x86-64/ARM/MIPS is usually negative (well, x86-32/ARM/MIPS use REL instead of RELA), so we may see a lot of 0xFFFFFFFC. -4 is likely prettier.

grimar updated this revision to Diff 248668.Mar 6 2020, 1:49 AM
grimar marked 10 inline comments as done.
  • Addressed review comments.
llvm/test/tools/obj2yaml/relocation-addend.yaml
2

Reasonable. Done.

jhenderson added inline comments.Mar 9 2020, 2:38 AM
llvm/test/tools/obj2yaml/relocation-addend.yaml
84

I'm not sure we need a 32-bit case for this one, as the behaviour is independent of the bitness.

llvm/test/tools/yaml2obj/ELF/relocation-addend.yaml
2

Delete the second "handles"

grimar updated this revision to Diff 249292.Mar 10 2020, 2:28 AM
grimar marked 3 inline comments as done.
  • Addressed review comments.
llvm/test/tools/obj2yaml/relocation-addend.yaml
84

Yeah, that is why I have no 64-bit case at all. To improve,
I've changed this test to be "Case 3" and made it use the first YAML document.

jhenderson accepted this revision.Mar 12 2020, 2:49 AM

LGTM. Might be worth waiting for @MaskRay too.

This revision is now accepted and ready to land.Mar 12 2020, 2:49 AM
MaskRay accepted this revision.Mar 12 2020, 10:54 AM
MaskRay added inline comments.
llvm/test/tools/obj2yaml/relocation-addend.yaml
73

Optional: yaml2obj --docnum=2 %s -D ADDEND=-1 | obj2yaml | FileCheck ... can omit intermediate object files.

llvm/test/tools/yaml2obj/ELF/relocation-addend.yaml
52

(You can omit Offset:)

61

Decimal commas are unneeded because 2147483647 below do not have them.

66

cmp %t4 %t5

cmp makes it clear that the object files are identical.

86

cmp %t7 %t8

grimar marked 7 inline comments as done.Mar 13 2020, 3:08 AM
grimar added inline comments.
llvm/test/tools/obj2yaml/relocation-addend.yaml
73

I prefer do not use "|" because I find such tests harder to work with when they fail.

llvm/test/tools/yaml2obj/ELF/relocation-addend.yaml
61

Because 2147483647 below are not a part of a comment :)
2,147,483,647 is easier to read.
(Imagine if I wanted to mention 2^63 in a comment, which is 9223372036854775807. It
would be better to write it as 9,223,372,036,854,775,807 instead I think).

66

Right. Done.

This revision was automatically updated to reflect the committed changes.
grimar marked 2 inline comments as done.