This is an archive of the discontinued LLVM Phabricator instance.

[RISCV]Generate target attribute in attribute section of object file when assemble .s file
Needs ReviewPublic

Authored by zixuan-wu on Sep 10 2021, 2:41 AM.

Details

Summary

When there is not RISCV arch attribute in assembly .s file, it will not generate arch attribute in obj file. LLVM asm parser does not use subtarget feature bits to generate appropriate attributes. So instructions can not be recognized in disassemble process (llvm-objdump).

For example,

;t.s

fadd.s ft1,ft2,ft3

./bin/llvm-mc < t.s -mattr=+f -filetype=obj |./bin/llvm-objdump -dr -

0000000000000000 <.text>:
       0: d3 70 31 00  	<unknown>

Emit target attribute at the constructor of RISCV asm parser to enable the functionality of attribute section even in assemble process.

It's a WIP patch to discuss and see whether the direction is right.

Diff Detail

Event Timeline

zixuan-wu created this revision.Sep 10 2021, 2:41 AM
zixuan-wu requested review of this revision.Sep 10 2021, 2:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2021, 2:41 AM
zixuan-wu edited the summary of this revision. (Show Details)Sep 10 2021, 2:48 AM
zixuan-wu added reviewers: asb, simoncook.

Please upload patches using full context; see https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface (or the section above it; arc diff does everything for you).

Whilst we should be emitting attributes for hand-written assembly files for anything not explicitly specified, that should only be done for the top-level file, not for inline assembly.

llvm/test/MC/RISCV/rvf-user-csr-names.s
6

So, this used to be required until D58932. I guess it's fine to remove it from the llvm-mc invocation (though this one fails to delete one of the spaces); the alternative would be to add --mattr=-f to the llvm-objdump invocation, but I think this diff makes more sense.

Please upload patches using full context; see https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface (or the section above it; arc diff does everything for you).

Whilst we should be emitting attributes for hand-written assembly files for anything not explicitly specified, that should only be done for the top-level file, not for inline assembly.

You mean when the asm parser is constructed only for inline-asm, then do not generate attributes instead of other code path invocation ? Is there any predict/judgement can be used in asm parser constructor to see whether it's in inline-asm code path?

zixuan-wu updated this revision to Diff 372153.Sep 12 2021, 8:47 PM
zixuan-wu edited the summary of this revision. (Show Details)Sep 12 2021, 8:52 PM
MaskRay added a comment.EditedSep 13 2021, 10:01 AM

For other targets, llvm-objdump is just recommended to default to something like binutils -mcpu=all (GCC powerpc -mcpu=future) if no attribute section says anything about the ISA. That may be an issue if there are conflicting encoding in one ISA.

For other targets, llvm-objdump is just recommended to default to something like binutils -mcpu=all (GCC powerpc -mcpu=future) if no attribute section says anything about the ISA. That may be an issue if there are conflicting encoding in one ISA.

The key point is at assembly side not objdump side. Indeed, there is conflicting encoding in one ISA, so that generate appropriate different attribute for same instruction encoding. The attributes of assemble and disassemble just should be match.

GNU toolchain is always emit arch attribute even user didn't write it in assembly file, and it will implied the info from the -march option or default arch setting, it's what you want to do in LLVM part IIUC.

But this implementation has some issue:

  • Inline asm will emit .attribute 5, (.attribute Tag_RISCV_arch) again, that result the output will reject by the GNU assembler since .attribute Tag_RISCV_arch required to be appear before any instruction.
  • NO new testcase added to demonstrate what you want to do, I would suggest you should add one, assemble a .s file to .o and then dump the attribute to make sure .attribute Tag_RISCV_arch has emitted properly.

So I think the goal of this patch is right way, but the implementation need some tweaks, especially the code gen change for inline asm.

GNU toolchain is always emit arch attribute even user didn't write it in assembly file, and it will implied the info from the -march option or default arch setting, it's what you want to do in LLVM part IIUC.

But this implementation has some issue:

  • Inline asm will emit .attribute 5, (.attribute Tag_RISCV_arch) again, that result the output will reject by the GNU assembler since .attribute Tag_RISCV_arch required to be appear before any instruction.
  • NO new testcase added to demonstrate what you want to do, I would suggest you should add one, assemble a .s file to .o and then dump the attribute to make sure .attribute Tag_RISCV_arch has emitted properly.

So I think the goal of this patch is right way, but the implementation need some tweaks, especially the code gen change for inline asm.

Yes, that's what I want to do.
Which place or file is appropriate to add such testcase?

zixuan-wu updated this revision to Diff 373183.Sep 17 2021, 3:45 AM
zixuan-wu retitled this revision from [RISCV][WIP] Generate target attribute in attribute section of object file when assemble .s file to [RISCV]Generate target attribute in attribute section of object file when assemble .s file.

Add testcase

ping...

It's been less than 24h, this is unnecessary and rude

ping...

It's been less than 24h, this is unnecessary and rude

Sorry to disturb. I have been working in a space plane whose speed is close to light. So, relatively, you guys are also close to light, which are seen slowly to give comments. :)