btf: fix a possibly misleading asm debug comment
commit9b8bc02037eeaf4d6365010bb0533385deb4a90d
authorDavid Faust <david.faust@oracle.com>
Thu, 11 Apr 2024 19:52:36 +0000 (11 12:52 -0700)
committerDavid Faust <david.faust@oracle.com>
Thu, 11 Apr 2024 22:35:42 +0000 (11 15:35 -0700)
tree51fff1457d1e1ca6051b229618ec2ee4df3cb3b8
parentf079d69d7b1338522562516537d96e9e1285c95e
btf: fix a possibly misleading asm debug comment

This patch fixes a small error that could occur in the debug comment
when emitting a type reference with btf_asm_type_ref.

While working on a previous patch, I noticed the following in the asm
output for the test btf-bitfields-4.c:

...
.long 0x39 # MEMBER 'c' idx=3
.long 0x6 # btm_type: (BTF_KIND_UNKN '')
...
.long 0x34 # TYPE 6 BTF_KIND_INT 'char'

The type for member 'c' is correct, but the comment for the member
incorrectly reads "BTF_KIND_UNKN ''".  This was caused by an
incorrect type lookup in btf_asm_type_ref that could happen if the
source file has types which can be represented in CTF but not in BTF.

This patch fixes the issue by changing btf_asm_type_ref to work fully
in the CTF ID space until writing out the final BTF ID.  That ensures
types are correctly identified when writing the asm debug comments,
like the following fixed comment for the above case.

...
.long 0x39 # MEMBER 'c' idx=3
.long 0x6 # btm_type: (BTF_KIND_INT 'char')
...

Note that there was no problem with the actual BTF information, the
only error was in the comment.  This patch does not change the output
BTF information, and no tests were affected.

gcc/
* btfout.cc (btf_asm_type_ref): Convert IDs to BTF internally and
fix potentially looking up wrong type for asm debug comment info.
Split into...
(btf_asm_datasec_type_ref): ... This. New.
(btf_asm_datasec_entry): Call it here, instead of btf_asm_type_ref.
(btf_asm_type, btf_asm_array, btf_asm_varent, btf_asm_sou_member)
(btf_asm_func_arg, btf_asm_func_type): Adapt btf_asm_type_ref call.
gcc/btfout.cc