btf_encoder: Fix a dwarf type DW_ATE_unsigned_1024 to btf encoding issue
PATCH 1/1 btf_encoder: Fix a dwarf type DW_ATE_unsigned_1024 to btf encoding issue
Nick Desaulniers reported an issue ([1]) where an 128-byte sized type (DW_ATE_unsigned_1024) cannot be encoded into BTF with failure message likes below:
$ pahole -J reduced.o [2] INT DW_ATE_unsigned_1024 Error emitting BTF type Encountered error while encoding BTF. See [1] for how to reproduce the issue.
The failure is due to currently BTF int type only supports upto 16 bytes (__int128) and in this case the dwarf int type is 128-byte.
The DW_ATE_unsigned_1024 is not a normal type for variable/func declaration etc. It is used in DW_AT_location. There are two ways to resolve this issue.
(1). If btf encoding is expected, remove all dwarf int types
where btf encoding will failure, e.g., non-power-of-2 bytes, or greater than 16 bytes.
(2). do a sanitization in btf_encoder ([2]).
This patch uses method (2) since it is a simple fix in btf_encoder. I checked my local built vmlinux with latest
bpf-next. There is only one instance of DW_ATE_unsigned_24 (used in DW_AT_location) so I expect irregular int types should be very rare.
[1] https://github.com/libbpf/libbpf/pull/680
[2] commit 7d8e829f636f ("btf_encoder: Sanitize non-regular int base type")
--- btf_encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
btf_encoder.c +1 -1
@@ -394,7 +394,7 @@ static int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const str* these non-regular int types to avoid libbpf/kernel complaints. */ byte_sz =BITS_ROUNDUP_BYTES (bt->bit_size); -if (!byte_sz || (byte_sz & (byte_sz -1 ))) { +if (!byte_sz || (byte_sz & (byte_sz -1 )) || byte_sz >16 ) { name ="__SANITIZED_FAKE_INT__" ; byte_sz =4 ; }
Signature · 1 line
2.34.1
Quoted 25 lines · Yonghong Song
Nick Desaulniers reported an issue ([1]) where an 128-byte sized type (
DW_ATE_unsigned_1024) cannot be encoded into BTF with failure message likes below:$ pahole -J reduced.o [2] INT DW_ATE_unsigned_1024 Error emitting BTF type Encountered error while encoding BTF. See [1] for how to reproduce the issue.The failure is due to currently BTF int type only supports upto 16 bytes (
__int128) and in this case the dwarf int type is 128-byte.The
DW_ATE_unsigned_1024is not a normal type for variable/func declaration etc. It is used inDW_AT_location. There are two ways to resolve this issue.
(1). If btf encoding is expected, remove all dwarf int types
where btf encoding will failure, e.g., non-power-of-2 bytes, or greater than 16 bytes.
(2). do a sanitization inbtf_encoder([2]).This patch uses method (2) since it is a simple fix in
btf_encoder. I checked my local built vmlinux with latest
bpf-next. There is only one instance ofDW_ATE_unsigned_24(used inDW_AT_location) so I expect irregular int types should be very rare.
Quoted 4 lines
[1] https://github.com/libbpf/libbpf/pull/680
[2] commit7d8e829f636f("btf_encoder: Sanitize non-regular int base type")Signed-off-by Yonghong Song <[email protected]>
Thanks, this fixed the above reported error for me. My report is just forwarded from Satya.
I don't know if that change has other implications for unusual byte sizes.
We might need to consider at some point waiting to validate DW_TAG_base_type until we know that they're not used outside of DW_AT_location expressions.
Quoted 20 lines
--- btf_encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)btf_encoder.c +1
-2@@ -394,7 +394,7 @@ static int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const str* these non-regular int types to avoid libbpf/kernel complaints. */ byte_sz =BITS_ROUNDUP_BYTES (bt->bit_size); -if (!byte_sz || (byte_sz & (byte_sz -1 ))) { +if (!byte_sz || (byte_sz & (byte_sz -1 )) || byte_sz >16 ) { name ="__SANITIZED_FAKE_INT__" ; byte_sz =4 ; } --2.34.1
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 34 lines · Nick Desaulniers
Quoted 25 lines · Yonghong Song
Nick Desaulniers reported an issue ([1]) where an 128-byte sized type (
DW_ATE_unsigned_1024) cannot be encoded into BTF with failure message likes below:$ pahole -J reduced.o [2] INT DW_ATE_unsigned_1024 Error emitting BTF type Encountered error while encoding BTF. See [1] for how to reproduce the issue.The failure is due to currently BTF int type only supports upto 16 bytes (
__int128) and in this case the dwarf int type is 128-byte.The
DW_ATE_unsigned_1024is not a normal type for variable/func declaration etc. It is used inDW_AT_location. There are two ways to resolve this issue.
(1). If btf encoding is expected, remove all dwarf int types
where btf encoding will failure, e.g., non-power-of-2 bytes, or greater than 16 bytes.
(2). do a sanitization inbtf_encoder([2]).This patch uses method (2) since it is a simple fix in
btf_encoder. I checked my local built vmlinux with latest
bpf-next. There is only one instance ofDW_ATE_unsigned_24(used inDW_AT_location) so I expect irregular int types should be very rare.Quoted 4 lines
[1] https://github.com/libbpf/libbpf/pull/680
[2] commit7d8e829f636f("btf_encoder: Sanitize non-regular int base type")Signed-off-by Yonghong Song <[email protected]>Thanks, this fixed the above reported error for me. My report is just forwarded from Satya.
Quoted 8 lines
Tested-by Nick Desaulniers <[email protected]>I don't know if that change has other implications for unusual byte sizes.
We might need to consider at some point waiting to validate
DW_TAG_base_typeuntil we know that they're not used outside ofDW_AT_locationexpressions.
David Blaikie confirmed that indeed special types like DW_ATE_unsigned_1024 is indeed generated for DW_AT_location. See https://github.com/libbpf/libbpf/pull/680 for details.
Quoted 23 lines
Quoted 21 lines
--- btf_encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)btf_encoder.c +1
-2@@ -394,7 +394,7 @@ static int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const str* these non-regular int types to avoid libbpf/kernel complaints. */ byte_sz =BITS_ROUNDUP_BYTES (bt->bit_size); -if (!byte_sz || (byte_sz & (byte_sz -1 ))) { +if (!byte_sz || (byte_sz & (byte_sz -1 )) || byte_sz >16 ) { name ="__SANITIZED_FAKE_INT__" ; byte_sz =4 ; } --2.34.1