[PATCH v2 2/3] perf: build: Fix build feature-dwarf_getlocations fail for old libdw

Yang Jihong posted 3 patches 1 year, 4 months ago
There is a newer version of this series
[PATCH v2 2/3] perf: build: Fix build feature-dwarf_getlocations fail for old libdw
Posted by Yang Jihong 1 year, 4 months ago
For libdw versions below 0.177, need to link libdl.a in addition to
libbebl.a during static compilation, otherwise feature-dwarf_getlocations
compilation will fail.

Before:

  $ make LDFLAGS=-static
    BUILD:   Doing 'make -j20' parallel build
  <SNIP>
  Makefile.config:483: Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157
  <SNIP>

  $ cat ../build/feature/test-dwarf_getlocations.make.output
  /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libebl.a(eblclosebackend.o): in function `ebl_closebackend':
  (.text+0x20): undefined reference to `dlclose'
  collect2: error: ld returned 1 exit status

After:

  $ make LDFLAGS=-static
  <SNIP>
    Auto-detecting system features:
  ...                                   dwarf: [ on  ]
  <SNIP>

    $ ./perf probe
   Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
      or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
      or: perf probe [<options>] --del '[GROUP:]EVENT' ...
      or: perf probe --list [GROUP:]EVENT ...
  <SNIP>

Fixes: 536661da6ea1 ("perf: build: Only link libebl.a for old libdw")
Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
---
 tools/build/feature/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index b18513ec4da6..1fc651cae9e5 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -179,7 +179,7 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
   # Elfutils merged libebl.a into libdw.a starting from version 0.177,
   # Link libebl.a only if libdw is older than this version.
   ifeq ($(shell test $(LIBDW_VERSION_2)0 -lt 1770; echo $$?),0)
-    DWARFLIBS += -lebl
+    DWARFLIBS += -lebl -ldl
   endif
 endif
 
-- 
2.25.1
Re: [PATCH v2 2/3] perf: build: Fix build feature-dwarf_getlocations fail for old libdw
Posted by Leo Yan 1 year, 4 months ago
On 8/6/2024 12:48 PM, Yang Jihong wrote:
> 
> For libdw versions below 0.177, need to link libdl.a in addition to
> libbebl.a during static compilation, otherwise feature-dwarf_getlocations
> compilation will fail.
> 
> Before:
> 
>   $ make LDFLAGS=-static
>     BUILD:   Doing 'make -j20' parallel build
>   <SNIP>
>   Makefile.config:483: Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157
>   <SNIP>
> 
>   $ cat ../build/feature/test-dwarf_getlocations.make.output
>   /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libebl.a(eblclosebackend.o): in function `ebl_closebackend':
>   (.text+0x20): undefined reference to `dlclose'
>   collect2: error: ld returned 1 exit status

Indeed. Thanks for pointing out this.

> After:
> 
>   $ make LDFLAGS=-static
>   <SNIP>
>     Auto-detecting system features:
>   ...                                   dwarf: [ on  ]
>   <SNIP>
> 
>     $ ./perf probe
>    Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
>       or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
>       or: perf probe [<options>] --del '[GROUP:]EVENT' ...
>       or: perf probe --list [GROUP:]EVENT ...
>   <SNIP>
> 
> Fixes: 536661da6ea1 ("perf: build: Only link libebl.a for old libdw")
> Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
> ---
>  tools/build/feature/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index b18513ec4da6..1fc651cae9e5 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -179,7 +179,7 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
>    # Elfutils merged libebl.a into libdw.a starting from version 0.177,
>    # Link libebl.a only if libdw is older than this version.
>    ifeq ($(shell test $(LIBDW_VERSION_2)0 -lt 1770; echo $$?),0)
> -    DWARFLIBS += -lebl
> +    DWARFLIBS += -lebl -ldl
>    endif

One critical thing is the ordering of libs. We must put libdl after libebl,
otherwise, the building still fails (based on my test).

Given libdl is a general lib, I think it is good to add a line after the
`endif` wrapper and with a comment, something like:

   ifeq ($(shell test $(LIBDW_VERSION_2)0 -lt 1770; echo $$?),0)
      DWARFLIBS += -lebl
   endif

   # Must put -ldl after -lebl for dependency
   DWARFLIBS += -ldl

Please update the file tools/perf/Makefile.config for consistency.

Thanks,
Leo

>  endif
> 
> --
> 2.25.1
> 
>
Re: [PATCH v2 2/3] perf: build: Fix build feature-dwarf_getlocations fail for old libdw
Posted by Yang Jihong 1 year, 4 months ago
Hello,

On 8/7/24 05:28, Leo Yan wrote:
> On 8/6/2024 12:48 PM, Yang Jihong wrote:
>>
>> For libdw versions below 0.177, need to link libdl.a in addition to
>> libbebl.a during static compilation, otherwise feature-dwarf_getlocations
>> compilation will fail.
>>
>> Before:
>>
>>    $ make LDFLAGS=-static
>>      BUILD:   Doing 'make -j20' parallel build
>>    <SNIP>
>>    Makefile.config:483: Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157
>>    <SNIP>
>>
>>    $ cat ../build/feature/test-dwarf_getlocations.make.output
>>    /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libebl.a(eblclosebackend.o): in function `ebl_closebackend':
>>    (.text+0x20): undefined reference to `dlclose'
>>    collect2: error: ld returned 1 exit status
> 
> Indeed. Thanks for pointing out this.
> 
>> After:
>>
>>    $ make LDFLAGS=-static
>>    <SNIP>
>>      Auto-detecting system features:
>>    ...                                   dwarf: [ on  ]
>>    <SNIP>
>>
>>      $ ./perf probe
>>     Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
>>        or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
>>        or: perf probe [<options>] --del '[GROUP:]EVENT' ...
>>        or: perf probe --list [GROUP:]EVENT ...
>>    <SNIP>
>>
>> Fixes: 536661da6ea1 ("perf: build: Only link libebl.a for old libdw")
>> Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
>> ---
>>   tools/build/feature/Makefile | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
>> index b18513ec4da6..1fc651cae9e5 100644
>> --- a/tools/build/feature/Makefile
>> +++ b/tools/build/feature/Makefile
>> @@ -179,7 +179,7 @@ ifeq ($(findstring -static,${LDFLAGS}),-static)
>>     # Elfutils merged libebl.a into libdw.a starting from version 0.177,
>>     # Link libebl.a only if libdw is older than this version.
>>     ifeq ($(shell test $(LIBDW_VERSION_2)0 -lt 1770; echo $$?),0)
>> -    DWARFLIBS += -lebl
>> +    DWARFLIBS += -lebl -ldl
>>     endif
> 
> One critical thing is the ordering of libs. We must put libdl after libebl,
> otherwise, the building still fails (based on my test).
> 
> Given libdl is a general lib, I think it is good to add a line after the
> `endif` wrapper and with a comment, something like:
> 
>     ifeq ($(shell test $(LIBDW_VERSION_2)0 -lt 1770; echo $$?),0)
>        DWARFLIBS += -lebl
>     endif
> 
>     # Must put -ldl after -lebl for dependency
>     DWARFLIBS += -ldl
> 
> Please update the file tools/perf/Makefile.config for consistency.

Okay, will change in next version.

Thanks,
Yang