aya-rs / bpf-linker

Simple BPF static linker
Apache License 2.0
192 stars 42 forks source link

di: Sanitize data carrying enums correctly #151

Closed vadorovsky closed 11 months ago

vadorovsky commented 11 months ago

Data carrying enums are causing a crash of the BPF Assembly Printer pass. As a workaround, we were always replacing the elements of that enum metadata with an empty MDNode.

However, #142 broke this behavior by calling replace_elements on a wrong composite type - it was calling it on the inner one (data carrying field), instead of the outer one (enum). This change fixes it.


This change is Reviewable

vadorovsky commented 11 months ago

src/llvm/di.rs line 648 at r1 (raw file):

Previously, tamird (Tamir Duberstein) wrote…
Are you sure the elements aren't reference counted? I think they might be, and we need not do anything.

OK, it is actually being handled gracefully in LLVM. I must've been blind before.

https://github.com/llvm/llvm-project/blob/be1e8a659df5003fa74e1f55c40acf3667f3cdb9/llvm/lib/IR/Core.cpp#L1339 https://github.com/llvm/llvm-project/blob/be1e8a659df5003fa74e1f55c40acf3667f3cdb9/llvm/lib/IR/Metadata.cpp#L1039 https://github.com/llvm/llvm-project/blob/be1e8a659df5003fa74e1f55c40acf3667f3cdb9/llvm/lib/IR/Metadata.cpp#L869-L917

Let me just remove this comment.