tools/resolve_btfids: Fix build error with older host toolchains
Subsystems (2)
PATCH 1/1 tools/resolve_btfids: Fix build error with older host toolchains
Older versions of libelf cannot recognize the compressed section. However, it's only required to fix the compressed section info when compiling with CONFIG_DEBUG_INFO_COMPRESSED flag is set.
Only compile the compressed_section_fix function when necessary will make it easier to enable the BTF function. Since the tool resolve_btfids is compiled with host toolchain. The host toolchain might be older than the cross compile toolchain.
--- tools/bpf/resolve_btfids/main.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/bpf/resolve_btfids/main.c +4 -0
@@ -260,6 +260,7 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)return btf_id__add (root, id, false); } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED /* * The data of compressed section should be aligned to 4 * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld
@@ -292,6 +293,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) }return 0 ; } +#endif static int elf_collect (struct object *obj) {
@@ -370,8 +372,10 @@ static int elf_collect(struct object *obj) obj->efile.idlist_addr = sh.sh_addr; } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED if (compressed_section_fix (elf, scn, &sh))return -1 ; +#endif }return 0 ;
Signature · 1 line
2.25.1
Quoted 4 lines · Kun-Chuan Hsieh
Older versions of libelf cannot recognize the compressed section. However, it's only required to fix the compressed section info when compiling with
CONFIG_DEBUG_INFO_COMPRESSEDflag is set.
Is it possible to detect (at compilation time or at run time) if libelf supports compressed ELF sections instead?
Quoted 46 lines
Only compile the
compressed_section_fixfunction when necessary will make it easier to enable the BTF function. Since the toolresolve_btfidsis compiled with host toolchain. The host toolchain might be older than the cross compile toolchain.Signed-off-by Kun-Chuan Hsieh <[email protected]>--- tools/bpf/resolve_btfids/main.c | 4 ++++ 1 file changed, 4 insertions(+)tools/bpf/resolve_btfids/main.c +4
-1@@ -260,6 +260,7 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)return btf_id__add (root, id, false); } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED /* * The data of compressed section should be aligned to 4 * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld @@ -292,6 +293,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) }return 0 ; } +#endif static int elf_collect (struct object *obj) {@@ -370,8 +372,10 @@ static int elf_collect(struct object *obj) obj->efile.idlist_addr = sh.sh_addr; } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED if (compressed_section_fix (elf, scn, &sh))return -1 ; +#endif }return 0 ; --2.25.1
Quoted 1 line · Kun-Chuan Hsieh
Older versions of libelf cannot recognize the compressed section.
so it's the SHF_COMPRESSED value the build fails on?
maybe we could do just this:
#ifndef SHF_COMPRESSED
#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
#endif
jirka
Quoted 48 lines
However, it's only required to fix the compressed section info when compiling with
CONFIG_DEBUG_INFO_COMPRESSEDflag is set.Only compile the
compressed_section_fixfunction when necessary will make it easier to enable the BTF function. Since the toolresolve_btfidsis compiled with host toolchain. The host toolchain might be older than the cross compile toolchain.Signed-off-by Kun-Chuan Hsieh <[email protected]>--- tools/bpf/resolve_btfids/main.c | 4 ++++ 1 file changed, 4 insertions(+)tools/bpf/resolve_btfids/main.c +4
-0@@ -260,6 +260,7 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)return btf_id__add (root, id, false); } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED /* * The data of compressed section should be aligned to 4 * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld @@ -292,6 +293,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) }return 0 ; } +#endif static int elf_collect (struct object *obj) {@@ -370,8 +372,10 @@ static int elf_collect(struct object *obj) obj->efile.idlist_addr = sh.sh_addr; } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED if (compressed_section_fix (elf, scn, &sh))return -1 ; +#endif }return 0 ;Signature · 1 line
2.25.1
A message that is not in the archive (sent off-list or not yet received): CAAmO479hYwswvNvd4LBMQ7bjhYeDvFohpu9p=FzeUjZ-BY=5GA@mail.gmail.com
Quoted 17 lines · Kun-Chuan Hsieh
Hi Jiri Olsa,
Yes, exactly. The missing
SHF_COMPRESSEDvalue causes build failure.Compared to conditional compilation, your suggestion seems to be a better solution. Thank you for your suggestion. I will submit the patch v2.
Hi Andrii Nakryiko,
Yes, it is possible to detect whether libelf supports compressed ELF sections at compilation time. I can think of two possible methods.
1. CheckSHF_COMPRESSEDis defined. (If libelf supports compressed ELF sections,SHF_COMPRESSEDshould be defined inlibelf.horelf.h)
2. Check the libelf version by_ELFUTILS_PREREQ(fromelfutils/version.h)
Quoted 15 lines
Best regards,
Kun-Chuan HsiehQuoted 11 lines · Jiri Olsa
Quoted 1 line · Kun-Chuan Hsieh
Older versions of libelf cannot recognize the compressed section.
so it's the
SHF_COMPRESSEDvalue the build fails on?maybe we could do just this:
#ifndef
SHF_COMPRESSED
#defineSHF_COMPRESSED(1 << 11) /* Section with compressed data. */
#endif
Yeah, I was hoping it would be something like this. Or we can just #ifdef two regions of code that rely on SHF_COMPRESSED.
Quoted 52 lines
Quoted 52 lines
jirka
Quoted 48 lines
However, it's only required to fix the compressed section info when compiling with
CONFIG_DEBUG_INFO_COMPRESSEDflag is set.Only compile the
compressed_section_fixfunction when necessary will make it easier to enable the BTF function. Since the toolresolve_btfidsis compiled with host toolchain. The host toolchain might be older than the cross compile toolchain.Signed-off-by Kun-Chuan Hsieh <[email protected]>--- tools/bpf/resolve_btfids/main.c | 4 ++++ 1 file changed, 4 insertions(+)tools/bpf/resolve_btfids/main.c +4
-1@@ -260,6 +260,7 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)return btf_id__add (root, id, false); } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED /* * The data of compressed section should be aligned to 4 * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld @@ -292,6 +293,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) }return 0 ; } +#endif static int elf_collect (struct object *obj) {@@ -370,8 +372,10 @@ static int elf_collect(struct object *obj) obj->efile.idlist_addr = sh.sh_addr; } +#ifdef CONFIG_DEBUG_INFO_COMPRESSED if (compressed_section_fix (elf, scn, &sh))return -1 ; +#endif }return 0 ; --2.25.1