Re: [PATCH kbuild v4] kbuild: add an elfnote for whether vmlinux is built with lto

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 4/6/21 8:01 PM, Sedat Dilek wrote:
On Tue, Apr 6, 2021 at 6:13 PM Yonghong Song <yhs@xxxxxx> wrote:


Masahiro and Michal,

Friendly ping. Any comments on this patch?

The addition LTO .notes information emitted by kernel is used by pahole
in the following patch:
     https://lore.kernel.org/bpf/20210401025825.2254746-1-yhs@xxxxxx/
     (dwarf_loader: check .notes section for lto build info)


Hi Yonghong,

the above pahole patch has this define and comment:

-static bool cus__merging_cu(Dwarf *dw)
+/* Match the define in linux:include/linux/elfnote.h */
+#define LINUX_ELFNOTE_BUILD_LTO 0x101

...and does not fit with the define and comment in this kernel patch:

+#include <linux/elfnote.h>
+
+#define LINUX_ELFNOTE_LTO_INFO 0x101

Thanks, Sedat. I am aware of this. I think we can wait in pahole
to make a change until the kernel patch is finalized and merged.
The kernel patch may still change as we haven't get
maintainer's comment. This will avoid unnecessary churn's
in pahole side.


Thanks.

- Sedat -


Thanks,

Yonghong

On 4/6/21 12:05 AM, Sedat Dilek wrote:
On Fri, Apr 2, 2021 at 8:07 PM 'Nick Desaulniers' via Clang Built
Linux <clang-built-linux@xxxxxxxxxxxxxxxx> wrote:

On Thu, Apr 1, 2021 at 4:27 PM Yonghong Song <yhs@xxxxxx> wrote:

Currently, clang LTO built vmlinux won't work with pahole.
LTO introduced cross-cu dwarf tag references and broke
current pahole model which handles one cu as a time.
The solution is to merge all cu's as one pahole cu as in [1].
We would like to do this merging only if cross-cu dwarf
references happens. The LTO build mode is a pretty good
indication for that.

In earlier version of this patch ([2]), clang flag
-grecord-gcc-switches is proposed to add to compilation flags
so pahole could detect "-flto" and then merging cu's.
This will increate the binary size of 1% without LTO though.

Arnaldo suggested to use a note to indicate the vmlinux
is built with LTO. Such a cheap way to get whether the vmlinux
is built with LTO or not helps pahole but is also useful
for tracing as LTO may inline/delete/demote global functions,
promote static functions, etc.

So this patch added an elfnote with a new type LINUX_ELFNOTE_LTO_INFO.
The owner of the note is "Linux".

With gcc 8.4.1 and clang trunk, without LTO, I got
    $ readelf -n vmlinux
    Displaying notes found in: .notes
      Owner                Data size        Description
    ...
      Linux                0x00000004       func
       description data: 00 00 00 00
    ...
With "readelf -x ".notes" vmlinux", I can verify the above "func"
with type code 0x101.

With clang thin-LTO, I got the same as above except the following:
       description data: 01 00 00 00
which indicates the vmlinux is built with LTO.

    [1] https://lore.kernel.org/bpf/20210325065316.3121287-1-yhs@xxxxxx/
    [2] https://lore.kernel.org/bpf/20210331001623.2778934-1-yhs@xxxxxx/

Suggested-by: Arnaldo Carvalho de Melo <arnaldo.melo@xxxxxxxxx>
Signed-off-by: Yonghong Song <yhs@xxxxxx>

LGTM thanks Yonghong!
Reviewed-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>


Thanks for the patch.

Feel free to add:

Tested-by: Sedat Dilek <sedat.dilek@xxxxxxxxx> # LLVM/Clang v12.0.0-rc4 (x86-64)

As a note for the pahole side:
Recent patches require an adaptation of the define and its comment.

1. LINUX_ELFNOTE_BUILD_LTO -> LINUX_ELFNOTE_LTO_INFO
2. include/linux/elfnote.h -> include/linux/elfnote-lto.h

- Sedat -

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux