Skip to content

Commit

Permalink
elf_reader: Allow strings read-only global data sections
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dylandreimerink committed Jul 20, 2022
1 parent 7b6e73d commit f8eb4d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 0 additions & 4 deletions elf_reader.go
Expand Up @@ -261,10 +261,6 @@ func (ec *elfCode) loadRelocations(relSections map[elf.SectionIndex]*elf.Section
return fmt.Errorf("section %q: reference to %q in section %s: %w", section.Name, rel.Name, rel.Section, ErrNotSupported)
}

if target.Flags&elf.SHF_STRINGS > 0 {
return fmt.Errorf("section %q: string is not stack allocated: %w", section.Name, ErrNotSupported)
}

target.references++
}

Expand Down
20 changes: 16 additions & 4 deletions elf_reader_test.go
Expand Up @@ -423,10 +423,22 @@ func TestLoadInvalidInitializedBTFMap(t *testing.T) {

func TestStringSection(t *testing.T) {
testutils.Files(t, testutils.Glob(t, "testdata/strings-*.elf"), func(t *testing.T, file string) {
_, err := LoadCollectionSpec(file)
t.Log(err)
if !errors.Is(err, ErrNotSupported) {
t.Error("References to a string section should be unsupported")
coll, err := LoadCollectionSpec(file)
if err != nil {
t.Fatal(err)
}

strMap, found := coll.Maps[".rodata.str1.1"]
if !found {
t.Fatal("Unable to find map '.rodata.str1.1' in loaded collection")
}

if !strMap.Freeze {
t.Fatal("Read only data maps should be frozen")
}

if strMap.Flags != unix.BPF_F_RDONLY_PROG {
t.Fatal("Read only data maps should have the prog-read-only flag set")
}
})
}
Expand Down

0 comments on commit f8eb4d2

Please sign in to comment.