This is an archive of the discontinued LLVM Phabricator instance.

BPF: report better error message for BTF_TYPE_ID_REMOTE relo failure
ClosedPublic

Authored by yonghong-song on Dec 20 2021, 3:54 PM.

Details

Summary

Matteo Croce reported a bpf backend fatal error in
https://github.com/llvm/llvm-project/issues/52779

A simplified case looks like:

$ cat bug.c
extern int do_smth(int);
int test() {
  return __builtin_btf_type_id(*(typeof(do_smth) *)do_smth, 1); 
}
$ clang -target bpf -O2 -g -c bug.c
fatal error: error in backend: Empty type name for BTF_TYPE_ID_REMOTE reloc
... 

The reason for the fatal error is that the relocation is against
a DISubroutineType like type 13 below:

!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !{} 
!12 = !DILocation(line: 3, column: 10, scope: !7) 
!13 = !DISubroutineType(types: !14)
!14 = !{!10, !10}

The DISubroutineType doesn't have a name and there is no way for
downstream bpfloader/kernel to do proper relocation for it.

But we can improve error message to be more specific for this case.
The patch improved the error message to be:

fatal error: error in backend: SubroutineType not supported for BTF_TYPE_ID_REMOTE reloc

Diff Detail

Event Timeline

yonghong-song created this revision.Dec 20 2021, 3:54 PM
yonghong-song requested review of this revision.Dec 20 2021, 3:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2021, 3:54 PM
  • fix clang-format warning
ast accepted this revision.Dec 20 2021, 7:53 PM
This revision is now accepted and ready to land.Dec 20 2021, 7:53 PM
This revision was landed with ongoing or failed builds.Dec 20 2021, 9:14 PM
This revision was automatically updated to reflect the committed changes.

@ast Is this OK to backport to release/14.x ?

ast added a comment.Feb 28 2022, 3:53 PM

@ast Is this OK to backport to release/14.x ?

Yes. please