BPF Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] tools/resolve_btfids: Fix build error with older host toolchains
@ 2021-02-23  1:20 Kun-Chuan Hsieh
  2021-02-23  6:31 ` Andrii Nakryiko
  2021-02-23 14:42 ` Jiri Olsa
  0 siblings, 2 replies; 4+ messages in thread
From: Kun-Chuan Hsieh @ 2021-02-23  1:20 UTC (permalink / raw)
  To: ast; +Cc: bpf, jolsa, andrii, Kun-Chuan Hsieh, stable

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.

Cc: stable@vger.kernel.org
Signed-off-by: Kun-Chuan Hsieh <jetswayss@gmail.com>
---
 tools/bpf/resolve_btfids/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 7409d7860aa6..ad40346c6631 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/resolve_btfids: Fix build error with older host toolchains
  2021-02-23  1:20 [PATCH] tools/resolve_btfids: Fix build error with older host toolchains Kun-Chuan Hsieh
@ 2021-02-23  6:31 ` Andrii Nakryiko
  2021-02-23 14:42 ` Jiri Olsa
  1 sibling, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2021-02-23  6:31 UTC (permalink / raw)
  To: Kun-Chuan Hsieh
  Cc: Alexei Starovoitov, bpf, Jiri Olsa, Andrii Nakryiko, linux- stable

On Mon, Feb 22, 2021 at 5:20 PM Kun-Chuan Hsieh <jetswayss@gmail.com> wrote:
>
> 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.

Is it possible to detect (at compilation time or at run time) if
libelf supports compressed ELF sections instead?

>
> 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.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Kun-Chuan Hsieh <jetswayss@gmail.com>
> ---
>  tools/bpf/resolve_btfids/main.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index 7409d7860aa6..ad40346c6631 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/resolve_btfids: Fix build error with older host toolchains
  2021-02-23  1:20 [PATCH] tools/resolve_btfids: Fix build error with older host toolchains Kun-Chuan Hsieh
  2021-02-23  6:31 ` Andrii Nakryiko
@ 2021-02-23 14:42 ` Jiri Olsa
       [not found]   ` <CAAmO479hYwswvNvd4LBMQ7bjhYeDvFohpu9p=FzeUjZ-BY=5GA@mail.gmail.com>
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2021-02-23 14:42 UTC (permalink / raw)
  To: Kun-Chuan Hsieh; +Cc: ast, bpf, jolsa, andrii, stable

On Tue, Feb 23, 2021 at 01:20:01AM +0000, Kun-Chuan Hsieh wrote:
> 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

> 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.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Kun-Chuan Hsieh <jetswayss@gmail.com>
> ---
>  tools/bpf/resolve_btfids/main.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index 7409d7860aa6..ad40346c6631 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c
> @@ -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
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/resolve_btfids: Fix build error with older host toolchains
       [not found]   ` <CAAmO479hYwswvNvd4LBMQ7bjhYeDvFohpu9p=FzeUjZ-BY=5GA@mail.gmail.com>
@ 2021-02-23 17:26     ` Andrii Nakryiko
  0 siblings, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2021-02-23 17:26 UTC (permalink / raw)
  To: Kun-Chuan Hsieh
  Cc: Jiri Olsa, Alexei Starovoitov, bpf, Jiri Olsa, Andrii Nakryiko, stable

On Tue, Feb 23, 2021 at 8:38 AM Kun-Chuan Hsieh <jetswayss@gmail.com> wrote:
>
> Hi Jiri Olsa,
>
> Yes, exactly. The missing SHF_COMPRESSED value 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. Check SHF_COMPRESSED is defined. (If libelf supports compressed ELF
> sections, SHF_COMPRESSED should be defined in libelf.h or elf.h)
> 2. Check the libelf version by _ELFUTILS_PREREQ (from elfutils/version.h)
>
> Best regards,
> Kun-Chuan Hsieh
>
> On Tue, Feb 23, 2021 at 10:43 PM Jiri Olsa <jolsa@redhat.com> wrote:
>>
>> On Tue, Feb 23, 2021 at 01:20:01AM +0000, Kun-Chuan Hsieh wrote:
>> > 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

Yeah, I was hoping it would be something like this. Or we can just
#ifdef two regions of code that rely on SHF_COMPRESSED.

>>
>> jirka
>>
>> > 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.
>> >
>> > Cc: stable@vger.kernel.org
>> > Signed-off-by: Kun-Chuan Hsieh <jetswayss@gmail.com>
>> > ---
>> >  tools/bpf/resolve_btfids/main.c | 4 ++++
>> >  1 file changed, 4 insertions(+)
>> >
>> > diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
>> > index 7409d7860aa6..ad40346c6631 100644
>> > --- a/tools/bpf/resolve_btfids/main.c
>> > +++ b/tools/bpf/resolve_btfids/main.c
>> > @@ -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
>> >
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23  1:20 [PATCH] tools/resolve_btfids: Fix build error with older host toolchains Kun-Chuan Hsieh
2021-02-23  6:31 ` Andrii Nakryiko
2021-02-23 14:42 ` Jiri Olsa
     [not found]   ` <CAAmO479hYwswvNvd4LBMQ7bjhYeDvFohpu9p=FzeUjZ-BY=5GA@mail.gmail.com>
2021-02-23 17:26     ` Andrii Nakryiko

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git