Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BTF for data sections optional #675

Merged
merged 7 commits into from May 23, 2022

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented May 16, 2022

This is a workaround for a compiler bug/limitation when working with arrays declared as preprocessor macros.

This bit us on two occasions:

Discussion on the list:
https://lore.kernel.org/bpf/CAK3+h2wcDceeGyFVDU3n7kPm=zgp7r1q4WK0=abxBsj9pyFN-g@mail.gmail.com

Best reviewed per commit.

The default behaviour of podman is to drop all stdout/err it generates into
the journal, which gets rather noisy.

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo requested a review from lmb May 16, 2022 14:32
@lmb
Copy link
Collaborator

lmb commented May 16, 2022

I'll try to review this Wednesday afternoon after #647.

Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, please make sure that running tests in the individual commits doesn't fail though.

btf/types.go Outdated Show resolved Hide resolved
volatile int ctx = 0;

// 32 bytes wide results in a .rodata.cst32 section.
#define values \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just fake a .rodata.foo via explicit section annotations? Might be more robust on newer versions of LLVM as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried all possible ways I could think of to force this to be emitted to a particular section, but haven't managed. Since it's not a real symbol, clang doesn't support setting the section attribute on it.

@@ -131,6 +131,12 @@ func TestLoadCollectionSpec(t *testing.T) {
SectionName: "static",
License: "MIT",
},
"anon_const": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there is no fix for the problem here, this means that the tests will fail on this commit? If yes, that's problematic when trying to bisect problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, didn't know we really cared about that, will respin the set to take this into account.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

elf_reader.go Outdated Show resolved Hide resolved

copy(cpy[v.Offset:v.Offset+v.Size], b)

replaced[vname] = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we allow replacing the same variable in multiple rodata sections? Seems wonky.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind not allowing it? Detecting compiler bugs? Technically, the same var being present in multiple rodata sections would also require having 2 equally-named ELF symbols with global vis, which is wonky indeed. So, we error here instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added a check that makes sure we don't replace the same var twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could also happen when the caller copies .rodata from a CollectionSpec and adds it under a different key in Maps.

ti-mo added 6 commits May 23, 2022 14:36
LoadCollectionSpecFromReader marks all .rodata* sections as data sections,
but loadDataSections() only freezes '.rodata'.

Signed-off-by: Timo Beckers <timo@isovalent.com>
https://lore.kernel.org/bpf/CAK3+h2wcDceeGyFVDU3n7kPm=zgp7r1q4WK0=abxBsj9pyFN-g@mail.gmail.com

If an anonymous value or constant (e.g. array declared in a macro) ends up
in a data section, it will not be accompanied by debug info, resulting in
no BTF being emitted for the value. If the section consists of only anonymous
values, there could be no BTF for the section as a whole.

A workaround was added to LLVM to always emit an empty BTF Datasec for .rodata
specifically, but this doesn't work for special sections like .rodata.cst32
and friends.

Signed-off-by: Timo Beckers <timo@isovalent.com>
Symbols for anonymous constants are somewhat irregular on older versions
of LLVM. This commit relaxes the constraints on symbols those compilers
emit map relocations against.

LLVM 7:
     1: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    16 .Lconstinit.1

LLVM 9:
     1: 0000000000000000    32 OBJECT  LOCAL  DEFAULT    22 .Lconstinit.1

LLVM 14 has these symbols correctly sanitized.

Signed-off-by: Timo Beckers <timo@isovalent.com>
Instead of only looking for constants in .rodata, iterate over all maps with
an .rodata prefix.

Moved the datasec bytes and BTF info extraction into a method on MapSpec.
Lifted patchValue back into RewriteConstants.

Signed-off-by: Timo Beckers <timo@isovalent.com>
This exercises support for constants in custom .rodata* sections.

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo merged commit 00ae3f2 into cilium:master May 23, 2022
dylandreimerink added a commit to dylandreimerink/ebpf that referenced this pull request Jul 20, 2022
In the past we had the limitation that string sections like
`.rodata.str1.1` could not not be loaded since clang/LLVM doesn't
provide BTF information for such sections. In cilium#675 we lifted the
requirement to have BTF information for global data sections. This means
that we can now also allow string sections to be loaded as global data.

All facilities to do so are already in place, this commit just removes
the check for references to sections with the `SHF_STRINGS` flag set.

Fixes: cilium#741
Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
@ti-mo ti-mo deleted the tb/datasec-optional-btf branch July 20, 2022 16:01
dylandreimerink added a commit to dylandreimerink/ebpf that referenced this pull request Jul 21, 2022
In the past we had the limitation that string sections like
`.rodata.str1.1` could not not be loaded since clang/LLVM doesn't
provide BTF information for such sections. In cilium#675 we lifted the
requirement to have BTF information for global data sections. This means
that we can now also allow string sections to be loaded as global data.

All facilities to do so are already in place, this commit just removes
the check for references to sections with the `SHF_STRINGS` flag set.

Fixes: cilium#741
Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
dylandreimerink added a commit to dylandreimerink/ebpf that referenced this pull request Jul 22, 2022
In the past we had the limitation that string sections like
`.rodata.str1.1` could not not be loaded since clang/LLVM doesn't
provide BTF information for such sections. In cilium#675 we lifted the
requirement to have BTF information for global data sections. This means
that we can now also allow string sections to be loaded as global data.

All facilities to do so are already in place, this commit just removes
the check for references to sections with the `SHF_STRINGS` flag set.

Fixes: cilium#741
Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
lmb pushed a commit that referenced this pull request Jul 22, 2022
In the past we had the limitation that string sections like
`.rodata.str1.1` could not not be loaded since clang/LLVM doesn't
provide BTF information for such sections. In #675 we lifted the
requirement to have BTF information for global data sections. This means
that we can now also allow string sections to be loaded as global data.

All facilities to do so are already in place, this commit just removes
the check for references to sections with the `SHF_STRINGS` flag set.

Fixes: #741
Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants