This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU/llvm-readobj: Add missing tests for note parsing/displaying
ClosedPublic

Authored by kzhuravl on Apr 26 2021, 9:15 AM.

Details

Summary

This is a follow up review/change for https://reviews.llvm.org/D95638

Add valid note tests for code object v2 notes:

  • NT_AMD_HSA_CODE_OBJECT_VERSION (required yaml2obj update)
  • NT_AMD_HSA_HSAIL (required yaml2obj update)
  • NT_AMD_HSA_ISA_VERSION (required yaml2obj update)
  • NT_AMD_HSA_METADATA
  • NT_AMD_HSA_ISA_NAME
  • NT_AMD_PAL_METADATA

Add valid note tests for code object v3 notes:

  • NT_AMDGPU_METADATA

Add invalid note tests for code object v2 notes:

  • NT_AMD_HSA_CODE_OBJECT_VERSION (required yaml2obj update)
  • NT_AMD_HSA_HSAIL (required yaml2obj update)
  • NT_AMD_HSA_ISA_VERSION (required yaml2obj update)

Add invalid note tests for code object v3 notes:

  • NT_AMDGPU_METADATA

Diff Detail

Event Timeline

kzhuravl created this revision.Apr 26 2021, 9:15 AM
kzhuravl requested review of this revision.Apr 26 2021, 9:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2021, 9:15 AM
Herald added subscribers: MaskRay, wdng. · View Herald Transcript

I believe this testing covers all cases (both valid and invalid) of note parsing/displaying for llvm-readobj

jhenderson added inline comments.Apr 27 2021, 12:40 AM
llvm/test/tools/llvm-readobj/ELF/note-amd-invalid-v2.s
1 ↗(On Diff #340551)

Please add a brief top-level comment to this test explaining the test's purpose.

It would also be helpful to have some inline comments next to each test case (possibly by the YAML) explaining why each case is invalid for future reference.

Same comments apply to each of the new tests.

Also, these should probably have a test file name ending in .test, since they aren't written in assembly.

121 ↗(On Diff #340551)

It might be a good idea to have one that's too big as well as too small, to show that the size has to match exactly.

Same goes for the other cases where the desc size is incorrect.

llvm/test/tools/llvm-readobj/ELF/note-amd-invalid-v3.s
30 ↗(On Diff #340551)

Is this the minimum the data can be in order to trigger the code path you are testing here?

llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.s
2–3 ↗(On Diff #340551)

Here and elsewhere, you might want something like --match-full-lines for the FileCheck invocation. That will ensure no garbage is printed after the expected string on any given line of output, which is especially important for where strings are being printed (in case something is wrong regarding null termination in the code).

165 ↗(On Diff #340551)

If I'm reading this correctly, this is just a string, in which case it can be any string, e.g. "foo" rather than some very large binary blob. I recommend simplifying drastically - it doesn't need to be a real-world case for testing purposes. Also, I believe you need a case for this note type where Desc.size() == 0. That may be tested elsewhere, but it would make sense to explicitly check it in llvm-readobj too.

Same goes for the NT_AMD_HSA_ISA_NAME case.

llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s
226

Such a large (and opaque) blob might mean it's easier to write this test in assembly and use llvm-mc to generate the output. The same goes for the invalid version of this case.

llvm/tools/llvm-readobj/ELFDumper.cpp
5058–5061

Nit: run clang-format.

5114

I missed this before, but what happens if Desc isn't a multiple of sizeof(PALMetadata)? It looks to me like you'd read off the end of the note data, which should trigger some sort of error (but currently isn't checked). Please fix and add a test case.

Thanks for the tests and fixes. Hopefully my comments make sense to you!

kzhuravl marked 7 inline comments as done.Apr 27 2021, 10:02 AM
kzhuravl added inline comments.
llvm/test/tools/llvm-readobj/ELF/note-amd-invalid-v3.s
30 ↗(On Diff #340551)

I have trimmed it to the minimum.

kzhuravl updated this revision to Diff 340893.Apr 27 2021, 10:02 AM
kzhuravl marked an inline comment as done.

Address review feedback.

Just one nit, otherwise looks good, assuming all the tests are passing etc.

llvm/test/tools/llvm-readobj/ELF/note-amd-invalid-v2.test
2–3

Most new llvm-readobj tests use ## for comments, to help them stand out from lit and FileCheck directives. Same goes with your other comments in this and other tests.

kzhuravl updated this revision to Diff 341189.Apr 28 2021, 7:05 AM
kzhuravl marked an inline comment as done.

Address review feedback.

jhenderson accepted this revision.Apr 29 2021, 12:10 AM

LGTM, once the clang-format issue has been addressed. Note: If you know anybody who knows AMDGPU more than me (i.e. at all), it might not hurt to get them to give the tests to give a once over before landing this, but don't worry if you don't.

llvm/tools/llvm-readobj/ELFDumper.cpp
5058–5061

Ping: clang-format appears to be complaining still here.

This revision is now accepted and ready to land.Apr 29 2021, 12:10 AM
kzhuravl updated this revision to Diff 341600.Apr 29 2021, 12:04 PM
kzhuravl marked 2 inline comments as done.

clang-format.

+ @t-tye to maybe look at note tests...

t-tye accepted this revision.Apr 29 2021, 2:32 PM

LGTM

@jhenderson , do you have any additional comments?

jhenderson accepted this revision.Apr 30 2021, 7:02 AM

@jhenderson , do you have any additional comments?

Nope!

This revision was landed with ongoing or failed builds.Apr 30 2021, 8:19 AM
This revision was automatically updated to reflect the committed changes.
stella.stamenova added inline comments.
llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s
4

This test assumes that the triple is available, but that's not always the case which results in failures such as:

FAIL: LLVM :: tools/llvm-readobj/ELF/note-amd-valid-v3.s (66018 of 76097)
******************** TEST 'LLVM :: tools/llvm-readobj/ELF/note-amd-valid-v3.s' FAILED ********************
Script:
--
: 'RUN: at line 4';   /mnt/vss/_work/1/b/llvm/bin/llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj < /mnt/vss/_work/1/s/llvm-project/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s | /mnt/vss/_work/1/b/llvm/bin/llvm-readobj --notes - | /mnt/vss/_work/1/b/llvm/bin/FileCheck /mnt/vss/_work/1/s/llvm-project/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s --match-full-lines --check-prefix=LLVM
: 'RUN: at line 5';   /mnt/vss/_work/1/b/llvm/bin/llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj < /mnt/vss/_work/1/s/llvm-project/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s | /mnt/vss/_work/1/b/llvm/bin/llvm-readelf --notes - | /mnt/vss/_work/1/b/llvm/bin/FileCheck /mnt/vss/_work/1/s/llvm-project/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s --match-full-lines --check-prefix=GNU
--
Exit Code: 2

Command Output (stderr):
--
/mnt/vss/_work/1/b/llvm/bin/llvm-mc: error: : error: unable to get target for 'amdgcn-amd-amdhsa', see --version and --triple.
/mnt/vss/_work/1/b/llvm/bin/llvm-readobj: error: '<stdin>': The file was not recognized as a valid object file
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /mnt/vss/_work/1/b/llvm/bin/FileCheck /mnt/vss/_work/1/s/llvm-project/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s --match-full-lines --check-prefix=LLVM

You either need to use REQUIRES: to specify what is needed or you need to move it to one of the directories that already do (such as AMDGPU).

Hi, llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s is failing for me.
/android0/llvm-project/llvm/build/bin/llvm-mc: error: : error: unable to get target for 'amdgcn-amd-amdhsa', see --version and --triple.
/android0/llvm-project/llvm/build/bin/llvm-readobj: error: '<stdin>': The file was not recognized as a valid object file
FileCheck error: '<stdin>' is empty.

Thanks, I am working on a fix.

I have reverted the change while I am testing the fix.

Conanap added a subscriber: Conanap.EditedMay 3 2021, 5:53 AM

Hello,

The reland version of this patch for which I cannot find the differential of has broken LLVM::note-amd-valid-v2.test on PowerPC:

/home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test:17:14: error: LLVM-NEXT: expected string not found in input
# LLVM-NEXT: AMD HSA Code Object Version: [Major: 2, Minor: 1]
             ^
<stdin>:15:68: note: scanning from here
 Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version)
                                                                   ^
<stdin>:16:2: note: possible intended match here
 AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216]
 ^
Input file: <stdin>
Check file: /home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
-dump-input=help explains the following input dump.
Input was:
<<<<<<
           .
           .
           .
          10:  Offset: 0x40 
          11:  Size: 0x18 
          12:  Note { 
          13:  Owner: AMD 
          14:  Data size: 0x8 
          15:  Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version) 
next:17'0                                                                        X error: no match found
          16:  AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216] 
next:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
next:17'1      ?                                                                possible intended match

Seems like a small fix but if you could have a push for it soon that'd be great. Thanks! FYI @rksharma

Hello,

The reland version of this patch for which I cannot find the differential of has broken LLVM::note-amd-valid-v2.test on PowerPC:

/home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test:17:14: error: LLVM-NEXT: expected string not found in input
# LLVM-NEXT: AMD HSA Code Object Version: [Major: 2, Minor: 1]
             ^
<stdin>:15:68: note: scanning from here
 Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version)
                                                                   ^
<stdin>:16:2: note: possible intended match here
 AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216]
 ^
Input file: <stdin>
Check file: /home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
-dump-input=help explains the following input dump.
Input was:
<<<<<<
           .
           .
           .
          10:  Offset: 0x40 
          11:  Size: 0x18 
          12:  Note { 
          13:  Owner: AMD 
          14:  Data size: 0x8 
          15:  Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version) 
next:17'0                                                                        X error: no match found
          16:  AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216] 
next:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
next:17'1      ?                                                                possible intended match

Seems like a small fix but if you could have a push for it soon that'd be great. Thanks! FYI @rksharma

Hi,

Reland patch fixed an issue if AMDGPU backend was not built, which was a one liner (I reverted original patch to not create the noise).

Seems like it is an endianness issue.

Unfortunately I don't have PowerPC, will adding these lines in note-amd-valid-v2.test mark it as XFAIL for you:

diff --git a/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test b/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
index 688bbd50994c..f9cac212ce9f 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
+++ b/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
@@ -1,6 +1,9 @@
 ## This test is checking the handling of valid note entries for AMDGPU code
 ## object v2.

+## Big endian not supported.
+# XFAIL: host-byteorder-big-endian
+
 # RUN: yaml2obj %s -o %t.o
 # RUN: llvm-readobj --notes %t.o | FileCheck %s --match-full-lines --check-prefix=LLVM
 # RUN: llvm-readelf --notes %t.o | FileCheck %s --match-full-lines --check-prefix=GNU

?

Hello,

The reland version of this patch for which I cannot find the differential of has broken LLVM::note-amd-valid-v2.test on PowerPC:

/home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test:17:14: error: LLVM-NEXT: expected string not found in input
# LLVM-NEXT: AMD HSA Code Object Version: [Major: 2, Minor: 1]
             ^
<stdin>:15:68: note: scanning from here
 Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version)
                                                                   ^
<stdin>:16:2: note: possible intended match here
 AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216]
 ^
Input file: <stdin>
Check file: /home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
-dump-input=help explains the following input dump.
Input was:
<<<<<<
           .
           .
           .
          10:  Offset: 0x40 
          11:  Size: 0x18 
          12:  Note { 
          13:  Owner: AMD 
          14:  Data size: 0x8 
          15:  Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version) 
next:17'0                                                                        X error: no match found
          16:  AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216] 
next:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
next:17'1      ?                                                                possible intended match

Seems like a small fix but if you could have a push for it soon that'd be great. Thanks! FYI @rksharma

Hi,

Reland patch fixed an issue if AMDGPU backend was not built, which was a one liner (I reverted original patch to not create the noise).

Seems like it is an endianness issue.

Unfortunately I don't have PowerPC, will adding these lines in note-amd-valid-v2.test mark it as XFAIL for you:

diff --git a/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test b/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
index 688bbd50994c..f9cac212ce9f 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
+++ b/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
@@ -1,6 +1,9 @@
 ## This test is checking the handling of valid note entries for AMDGPU code
 ## object v2.

+## Big endian not supported.
+# XFAIL: host-byteorder-big-endian
+
 # RUN: yaml2obj %s -o %t.o
 # RUN: llvm-readobj --notes %t.o | FileCheck %s --match-full-lines --check-prefix=LLVM
 # RUN: llvm-readelf --notes %t.o | FileCheck %s --match-full-lines --check-prefix=GNU

?

That would fix it yes, thank you!
Another possible solution would be to add a BE specific runline, but I'm not really familiar with the AMD test files so it's just a suggestion.

Hello,

The reland version of this patch for which I cannot find the differential of has broken LLVM::note-amd-valid-v2.test on PowerPC:

/home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test:17:14: error: LLVM-NEXT: expected string not found in input
# LLVM-NEXT: AMD HSA Code Object Version: [Major: 2, Minor: 1]
             ^
<stdin>:15:68: note: scanning from here
 Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version)
                                                                   ^
<stdin>:16:2: note: possible intended match here
 AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216]
 ^
Input file: <stdin>
Check file: /home/buildbots/ppc64be-clang-test/clang-ppc64be/llvm/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
-dump-input=help explains the following input dump.
Input was:
<<<<<<
           .
           .
           .
          10:  Offset: 0x40 
          11:  Size: 0x18 
          12:  Note { 
          13:  Owner: AMD 
          14:  Data size: 0x8 
          15:  Type: NT_AMD_HSA_CODE_OBJECT_VERSION (AMD HSA Code Object Version) 
next:17'0                                                                        X error: no match found
          16:  AMD HSA Code Object Version: [Major: 33554432, Minor: 16777216] 
next:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
next:17'1      ?                                                                possible intended match

Seems like a small fix but if you could have a push for it soon that'd be great. Thanks! FYI @rksharma

Hi,

Reland patch fixed an issue if AMDGPU backend was not built, which was a one liner (I reverted original patch to not create the noise).

Seems like it is an endianness issue.

Unfortunately I don't have PowerPC, will adding these lines in note-amd-valid-v2.test mark it as XFAIL for you:

diff --git a/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test b/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
index 688bbd50994c..f9cac212ce9f 100644
--- a/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
+++ b/llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v2.test
@@ -1,6 +1,9 @@
 ## This test is checking the handling of valid note entries for AMDGPU code
 ## object v2.

+## Big endian not supported.
+# XFAIL: host-byteorder-big-endian
+
 # RUN: yaml2obj %s -o %t.o
 # RUN: llvm-readobj --notes %t.o | FileCheck %s --match-full-lines --check-prefix=LLVM
 # RUN: llvm-readelf --notes %t.o | FileCheck %s --match-full-lines --check-prefix=GNU

?

That would fix it yes, thank you!
Another possible solution would be to add a BE specific runline, but I'm not really familiar with the AMD test files so it's just a suggestion.

Thanks, I have pushed that code snippet for now to make build bots happy. Let me look into adding big endian specific run lines today...

kzhuravl marked an inline comment as done.May 3 2021, 6:48 AM

Hi, llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s is failing for me.
/android0/llvm-project/llvm/build/bin/llvm-mc: error: : error: unable to get target for 'amdgcn-amd-amdhsa', see --version and --triple.
/android0/llvm-project/llvm/build/bin/llvm-readobj: error: '<stdin>': The file was not recognized as a valid object file
FileCheck error: '<stdin>' is empty.

Thanks, I have re-landed original patch + requires amdgpu-registered-target

llvm/test/tools/llvm-readobj/ELF/note-amd-valid-v3.s
4

Thanks, I have re-landed original patch + requires amdgpu-registered-target