ClangBuiltLinux / linux

Linux kernel source tree
Other
242 stars 14 forks source link

BTF generation does not work with LLVM/lld-16 #1825

Open tpgxyz opened 1 year ago

tpgxyz commented 1 year ago

H, i'm trying to build kernel-6.2.8 wth LLVM/clang-16.x and i got this error on x86_64. Full log is here https://abf.openmandriva.org/build_lists/296233 When i use ld.bfd instead of ld.lld then build fnishes withot errors.

CC .vmlinux.export.o UPD include/generated/utsversion.h CC init/version-timestamp.o LD .tmp_vmlinux.btf BTF .btf.vmlinux.bin.o libbpf: BTF header not found pahole: .tmp_vmlinux.btf: Invalid argument LD .tmp_vmlinux.kallsyms1 NM .tmp_vmlinux.kallsyms1.syms KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 NM .tmp_vmlinux.kallsyms2.syms KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD .tmp_vmlinux.kallsyms3 NM .tmp_vmlinux.kallsyms3.syms KSYMS .tmp_vmlinux.kallsyms3.S AS .tmp_vmlinux.kallsyms3.S LD vmlinux BTFIDS vmlinux FAILED: load BTF from vmlinux: Invalid argument make[1]: [scripts/Makefile.vmlinux:35: vmlinux] Error 255 make[1]: Deleting file 'vmlinux' make: *** [Makefile:1264: vmlinux] Error 2 error: Bad exit status from /var/tmp/rpm-tmp.Sevzk3 (%build)

nathanchance commented 1 year ago

What version of pahole do you have?

tpgxyz commented 1 year ago

pahole-1.24 here https://github.com/OpenMandrivaAssociation/pahole/blob/master/pahole.spec

nathanchance commented 1 year ago

Not reproducible for me.

$ uname -m
aarch64

$ pahole --version
v1.24

$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0 (https://github.com/llvm/llvm-project 08d094a0e457360ad8b94b017d2dc277e697ca76)

$ git show -s
commit f5304af1f705bce6e18a719fcbc00c8be6023519 (HEAD -> linux-6.2.y, tag: v6.2.8, origin/linux-6.2.y)
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Wed Mar 22 13:38:11 2023 +0100

    Linux 6.2.8

    Link: https://lore.kernel.org/r/20230320145513.305686421@linuxfoundation.org
    Tested-by: Chris Paterson (CIP) <chris.paterson2@renesas.com>
    Tested-by: Ronald Warsow <rwarsow@gmx.de>
    Tested-by: Florian Fainelli <f.fainelli@gmail.com>
    Tested-by: Shuah Khan <skhan@linuxfoundation.org>
    Tested-by: Allen Pais <apais@linux.microsoft.com>
    Tested-by: Bagas Sanjaya <bagasdotme@gmail.com>
    Tested-by: Ron Economos <re@w6rz.net>
    Tested-by: Conor Dooley <conor.dooley@microchip.com>
    Tested-by: Jon Hunter <jonathanh@nvidia.com>
    Link: https://lore.kernel.org/r/20230321080604.493429263@linuxfoundation.org
    Tested-by: Markus Reichelt <lkt+2023@mareichelt.com>
    Tested-by: Ronald Warsow <rwarsow@gmx.de>
    Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
    Tested-by: Slade Watkins <srw@sladewatkins.net>
    Link: https://lore.kernel.org/r/20230321180749.921141176@linuxfoundation.org
    Tested-by: Ronald Warsow <rwarsow@gmx.de>
    Tested-by: Florian Fainelli <f.fainelli@gmail.com>
    Tested-by: Ron Economos <re@w6rz.net>
    Tested-by: Bagas Sanjaya <bagasdotme@gmail.com>
    Tested-by: Chris Paterson (CIP) <chris.paterson2@renesas.com>
    Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

$ mkdir build

$ curl -LSso build/.config https://github.com/OpenMandrivaAssociation/kernel/raw/master/aarch64-omv-defconfig

# From https://github.com/OpenMandrivaAssociation/kernel/blob/9d58e234e1b6067e1ac0f3820a41b07c4cfbf810/kernel.spec#L1011-L1027
$ echo 'CONFIG_CC_IS_CLANG=y
CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
CONFIG_LD_IS_LLD=y
CONFIG_INIT_STACK_NONE=y
# CONFIG_INIT_STACK_ALL_PATTERN is not set
# CONFIG_INIT_STACK_ALL_ZERO is not set
# CONFIG_KCSAN is not set
# CONFIG_SHADOW_CALL_STACK is not set
# CONFIG_LTO_NONE is not set
# CONFIG_LTO_CLANG_FULL is not set
CONFIG_LTO_CLANG_THIN=y
CONFIG_CFI_CLANG=y
CONFIG_CFI_CLANG_SHADOW=y
CONFIG_CFI_PERMISSIVE=y
CONFIG_RELR=y' >>build/.config

$ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build oldconfig all
...

$ file build/vmlinux
build/vmlinux: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), statically linked, BuildID[sha1]=d1130c750f85feaa08f08b94e3312ddac7de41c9, with debug_info, not stripped

$ pahole -C dl_bw build/vmlinux
struct dl_bw {
        raw_spinlock_t             lock;                 /*     0     4 */

        /* XXX 4 bytes hole, try to pack */

        u64                        bw;                   /*     8     8 */
        u64                        total_bw;             /*    16     8 */

        /* size: 24, cachelines: 1, members: 3 */
        /* sum members: 20, holes: 1, sum holes: 4 */
        /* last cacheline: 24 bytes */
};
tpgxyz commented 1 year ago

I found this https://bbs.archlinux.org/viewtopic.php?id=284177 , which means this is not a single problem of one distro.

nickdesaulniers commented 1 year ago

Thanks for the report. I've reached out to the author of that Arch linux forum post for more info.

@tpgxyz can you rebuild with make ... V=1 and see how pahole is getting invoked? I assume that

FAILED: load BTF from vmlinux: Invalid argument

means that pahole is being invoked with some argument that it doesn't understand.

nathanchance commented 1 year ago

I noticed that I had a patched pahole in the environment that I was testing in (so it was not truly v1.24) but I still cannot reproduce this with either Fedora's pahole (which is patched) nor one built from the same revision as OpenMandriva, according to the patch file that is being applied on top of v1.24.

nathanchance commented 1 year ago

Ah, apparently I cannot read, I did not notice this was targeting x86_64, my apologies. Let me see if that makes a difference...

nathanchance commented 1 year ago

Nope, still not reproducible when targeting x86_64 with x86_64-omv-defconfig + the same configuration.

Lunarequest commented 1 year ago

I found this https://bbs.archlinux.org/viewtopic.php?id=284177 , which means this is not a single problem of one distro.

hi I'm the person who made this forum post. I've found this affects some kernel versions the first time you build them but it no matter the kernel version will occur if you make so minor changes eg removing or adding a kernel module and rebuilding without a make clean will consistently occur

tpgxyz commented 1 year ago

Here is the output from make V=1 on x86_64. Full log is available here https://abf.openmandriva.org/build_lists/297200. Btw same output i have on aarch64

+ btf_vmlinux_bin_o=
+ is_enabled CONFIG_DEBUG_INFO_BTF
+ grep -q '^CONFIG_DEBUG_INFO_BTF=y' include/config/auto.conf
+ btf_vmlinux_bin_o=.btf.vmlinux.bin.o
+ gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o
+ local pahole_ver
++ command -v pahole
+ '[' -x /usr/bin/pahole ']'
++ pahole --version
++ sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/'
+ pahole_ver=124
+ '[' 124 -lt 116 ']'
+ vmlinux_link .tmp_vmlinux.btf
  LD      .tmp_vmlinux.btf
+ local output=.tmp_vmlinux.btf
+ local objs
+ local libs
+ local ld
+ local ldflags
+ local ldlibs
+ info LD .tmp_vmlinux.btf
+ printf '  %-7s %s\n' LD .tmp_vmlinux.btf
+ shift
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ objs=vmlinux.o
+ libs=
+ is_enabled CONFIG_MODULES
+ grep -q '^CONFIG_MODULES=y' include/config/auto.conf
+ objs='vmlinux.o .vmlinux.export.o'
+ objs='vmlinux.o .vmlinux.export.o init/version-timestamp.o'
+ '[' x86 = um ']'
+ wl=
+ ld='ld.lld --icf=none --no-gc-sections'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn'
+ ldlibs=
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds'
+ '[' .tmp_vmlinux.btf '!=' .tmp_vmlinux.btf ']'
+ is_enabled CONFIG_VMLINUX_MAP
+ grep -q '^CONFIG_VMLINUX_MAP=y' include/config/auto.conf
+ ld.lld --icf=none --no-gc-sections -m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds -o .tmp_vmlinux.btf --whole-archive vmlinux.o .vmlinux.export.o init/version-timestamp.o --no-whole-archive --start-group --end-group
  BTF     .btf.vmlinux.bin.o
+ info BTF .btf.vmlinux.bin.o
+ printf '  %-7s %s\n' BTF .btf.vmlinux.bin.o
+ LLVM_OBJCOPY=llvm-objcopy
+ pahole -J --btf_gen_floats -j .tmp_vmlinux.btf
libbpf: BTF header not found
pahole: .tmp_vmlinux.btf: Invalid argument
+ llvm-objcopy --only-section=.BTF --set-section-flags .BTF=alloc,readonly --strip-all .tmp_vmlinux.btf .btf.vmlinux.bin.o
+ printf '\1'
+ dd of=.btf.vmlinux.bin.o conv=notrunc bs=1 seek=16 status=none
+ kallsymso=
+ kallsymso_prev=
+ kallsyms_vmlinux=
+ is_enabled CONFIG_KALLSYMS
+ grep -q '^CONFIG_KALLSYMS=y' include/config/auto.conf
+ kallsyms_step 1
+ kallsymso_prev=
+ kallsyms_vmlinux=.tmp_vmlinux.kallsyms1
+ kallsymso=.tmp_vmlinux.kallsyms1.o
+ kallsyms_S=.tmp_vmlinux.kallsyms1.S
+ vmlinux_link .tmp_vmlinux.kallsyms1 '' .btf.vmlinux.bin.o
  LD      .tmp_vmlinux.kallsyms1
+ local output=.tmp_vmlinux.kallsyms1
+ local objs
+ local libs
+ local ld
+ local ldflags
+ local ldlibs
+ info LD .tmp_vmlinux.kallsyms1
+ printf '  %-7s %s\n' LD .tmp_vmlinux.kallsyms1
+ shift
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ objs=vmlinux.o
+ libs=
+ is_enabled CONFIG_MODULES
+ grep -q '^CONFIG_MODULES=y' include/config/auto.conf
+ objs='vmlinux.o .vmlinux.export.o'
+ objs='vmlinux.o .vmlinux.export.o init/version-timestamp.o'
+ '[' x86 = um ']'
+ wl=
+ ld='ld.lld --icf=none --no-gc-sections'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn'
+ ldlibs=
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds'
+ '[' .tmp_vmlinux.kallsyms1 '!=' 1 ']'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds --strip-debug'
+ is_enabled CONFIG_VMLINUX_MAP
+ grep -q '^CONFIG_VMLINUX_MAP=y' include/config/auto.conf
+ ld.lld --icf=none --no-gc-sections -m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds --strip-debug -o .tmp_vmlinux.kallsyms1 --whole-archive vmlinux.o .vmlinux.export.o init/version-timestamp.o --no-whole-archive --start-group --end-group .btf.vmlinux.bin.o
  NM      .tmp_vmlinux.kallsyms1.syms
+ mksysmap .tmp_vmlinux.kallsyms1 .tmp_vmlinux.kallsyms1.syms
+ info NM .tmp_vmlinux.kallsyms1.syms
+ printf '  %-7s %s\n' NM .tmp_vmlinux.kallsyms1.syms
+ sh ./scripts/mksysmap .tmp_vmlinux.kallsyms1 .tmp_vmlinux.kallsyms1.syms
+ kallsyms .tmp_vmlinux.kallsyms1.syms .tmp_vmlinux.kallsyms1.S
+ local kallsymopt
+ is_enabled CONFIG_KALLSYMS_ALL
+ grep -q '^CONFIG_KALLSYMS_ALL=y' include/config/auto.conf
+ kallsymopt=' --all-symbols'
+ is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU
+ grep -q '^CONFIG_KALLSYMS_ABSOLUTE_PERCPU=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu'
+ is_enabled CONFIG_KALLSYMS_BASE_RELATIVE
+ grep -q '^CONFIG_KALLSYMS_BASE_RELATIVE=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu --base-relative'
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu --base-relative --lto-clang'
  KSYMS   .tmp_vmlinux.kallsyms1.S
+ info KSYMS .tmp_vmlinux.kallsyms1.S
+ printf '  %-7s %s\n' KSYMS .tmp_vmlinux.kallsyms1.S
+ scripts/kallsyms --all-symbols --absolute-percpu --base-relative --lto-clang .tmp_vmlinux.kallsyms1.syms
+ info AS .tmp_vmlinux.kallsyms1.S
+ printf '  %-7s %s\n' AS .tmp_vmlinux.kallsyms1.S
  AS      .tmp_vmlinux.kallsyms1.S
+ clang -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -D__KERNEL__ -Qunused-arguments -fmacro-prefix-map=./= -D__ASSEMBLY__ -fno-PIE --target=x86_64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -m64 -fno-lto -g -gz=zstd -c -o .tmp_vmlinux.kallsyms1.o .tmp_vmlinux.kallsyms1.S
+ kallsyms_step 2
+ kallsymso_prev=.tmp_vmlinux.kallsyms1.o
+ kallsyms_vmlinux=.tmp_vmlinux.kallsyms2
+ kallsymso=.tmp_vmlinux.kallsyms2.o
+ kallsyms_S=.tmp_vmlinux.kallsyms2.S
+ vmlinux_link .tmp_vmlinux.kallsyms2 .tmp_vmlinux.kallsyms1.o .btf.vmlinux.bin.o
+ local output=.tmp_vmlinux.kallsyms2
+ local objs
+ local libs
+ local ld
+ local ldflags
  LD      .tmp_vmlinux.kallsyms2
+ local ldlibs
+ info LD .tmp_vmlinux.kallsyms2
+ printf '  %-7s %s\n' LD .tmp_vmlinux.kallsyms2
+ shift
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ objs=vmlinux.o
+ libs=
+ is_enabled CONFIG_MODULES
+ grep -q '^CONFIG_MODULES=y' include/config/auto.conf
+ objs='vmlinux.o .vmlinux.export.o'
+ objs='vmlinux.o .vmlinux.export.o init/version-timestamp.o'
+ '[' x86 = um ']'
+ wl=
+ ld='ld.lld --icf=none --no-gc-sections'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn'
+ ldlibs=
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds'
+ '[' .tmp_vmlinux.kallsyms2 '!=' 2 ']'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds --strip-debug'
+ is_enabled CONFIG_VMLINUX_MAP
+ grep -q '^CONFIG_VMLINUX_MAP=y' include/config/auto.conf
+ ld.lld --icf=none --no-gc-sections -m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds --strip-debug -o .tmp_vmlinux.kallsyms2 --whole-archive vmlinux.o .vmlinux.export.o init/version-timestamp.o --no-whole-archive --start-group --end-group .tmp_vmlinux.kallsyms1.o .btf.vmlinux.bin.o
  NM      .tmp_vmlinux.kallsyms2.syms
+ mksysmap .tmp_vmlinux.kallsyms2 .tmp_vmlinux.kallsyms2.syms
+ info NM .tmp_vmlinux.kallsyms2.syms
+ printf '  %-7s %s\n' NM .tmp_vmlinux.kallsyms2.syms
+ sh ./scripts/mksysmap .tmp_vmlinux.kallsyms2 .tmp_vmlinux.kallsyms2.syms
+ kallsyms .tmp_vmlinux.kallsyms2.syms .tmp_vmlinux.kallsyms2.S
+ local kallsymopt
+ is_enabled CONFIG_KALLSYMS_ALL
+ grep -q '^CONFIG_KALLSYMS_ALL=y' include/config/auto.conf
+ kallsymopt=' --all-symbols'
+ is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU
+ grep -q '^CONFIG_KALLSYMS_ABSOLUTE_PERCPU=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu'
+ is_enabled CONFIG_KALLSYMS_BASE_RELATIVE
+ grep -q '^CONFIG_KALLSYMS_BASE_RELATIVE=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu --base-relative'
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu --base-relative --lto-clang'
+ info KSYMS .tmp_vmlinux.kallsyms2.S
  KSYMS   .tmp_vmlinux.kallsyms2.S
+ printf '  %-7s %s\n' KSYMS .tmp_vmlinux.kallsyms2.S
+ scripts/kallsyms --all-symbols --absolute-percpu --base-relative --lto-clang .tmp_vmlinux.kallsyms2.syms
  AS      .tmp_vmlinux.kallsyms2.S
+ info AS .tmp_vmlinux.kallsyms2.S
+ printf '  %-7s %s\n' AS .tmp_vmlinux.kallsyms2.S
+ clang -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -D__KERNEL__ -Qunused-arguments -fmacro-prefix-map=./= -D__ASSEMBLY__ -fno-PIE --target=x86_64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -m64 -fno-lto -g -gz=zstd -c -o .tmp_vmlinux.kallsyms2.o .tmp_vmlinux.kallsyms2.S
++ sh ./scripts/file-size.sh .tmp_vmlinux.kallsyms1.o
+ size1=1981392
++ sh ./scripts/file-size.sh .tmp_vmlinux.kallsyms2.o
+ size2=1981424
+ '[' 1981392 -ne 1981424 ']'
+ kallsyms_step 3
+ kallsymso_prev=.tmp_vmlinux.kallsyms2.o
  LD      .tmp_vmlinux.kallsyms3
+ kallsyms_vmlinux=.tmp_vmlinux.kallsyms3
+ kallsymso=.tmp_vmlinux.kallsyms3.o
+ kallsyms_S=.tmp_vmlinux.kallsyms3.S
+ vmlinux_link .tmp_vmlinux.kallsyms3 .tmp_vmlinux.kallsyms2.o .btf.vmlinux.bin.o
+ local output=.tmp_vmlinux.kallsyms3
+ local objs
+ local libs
+ local ld
+ local ldflags
+ local ldlibs
+ info LD .tmp_vmlinux.kallsyms3
+ printf '  %-7s %s\n' LD .tmp_vmlinux.kallsyms3
+ shift
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ objs=vmlinux.o
+ libs=
+ is_enabled CONFIG_MODULES
+ grep -q '^CONFIG_MODULES=y' include/config/auto.conf
+ objs='vmlinux.o .vmlinux.export.o'
+ objs='vmlinux.o .vmlinux.export.o init/version-timestamp.o'
+ '[' x86 = um ']'
+ wl=
+ ld='ld.lld --icf=none --no-gc-sections'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn'
+ ldlibs=
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds'
+ '[' .tmp_vmlinux.kallsyms3 '!=' 3 ']'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds --strip-debug'
+ is_enabled CONFIG_VMLINUX_MAP
+ grep -q '^CONFIG_VMLINUX_MAP=y' include/config/auto.conf
+ ld.lld --icf=none --no-gc-sections -m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds --strip-debug -o .tmp_vmlinux.kallsyms3 --whole-archive vmlinux.o .vmlinux.export.o init/version-timestamp.o --no-whole-archive --start-group --end-group .tmp_vmlinux.kallsyms2.o .btf.vmlinux.bin.o
  NM      .tmp_vmlinux.kallsyms3.syms
+ mksysmap .tmp_vmlinux.kallsyms3 .tmp_vmlinux.kallsyms3.syms
+ info NM .tmp_vmlinux.kallsyms3.syms
+ printf '  %-7s %s\n' NM .tmp_vmlinux.kallsyms3.syms
+ sh ./scripts/mksysmap .tmp_vmlinux.kallsyms3 .tmp_vmlinux.kallsyms3.syms
+ kallsyms .tmp_vmlinux.kallsyms3.syms .tmp_vmlinux.kallsyms3.S
+ local kallsymopt
+ is_enabled CONFIG_KALLSYMS_ALL
+ grep -q '^CONFIG_KALLSYMS_ALL=y' include/config/auto.conf
+ kallsymopt=' --all-symbols'
+ is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU
+ grep -q '^CONFIG_KALLSYMS_ABSOLUTE_PERCPU=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu'
+ is_enabled CONFIG_KALLSYMS_BASE_RELATIVE
+ grep -q '^CONFIG_KALLSYMS_BASE_RELATIVE=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu --base-relative'
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ kallsymopt=' --all-symbols --absolute-percpu --base-relative --lto-clang'
+ info KSYMS .tmp_vmlinux.kallsyms3.S
  KSYMS   .tmp_vmlinux.kallsyms3.S
+ printf '  %-7s %s\n' KSYMS .tmp_vmlinux.kallsyms3.S
+ scripts/kallsyms --all-symbols --absolute-percpu --base-relative --lto-clang .tmp_vmlinux.kallsyms3.syms
  AS      .tmp_vmlinux.kallsyms3.S
+ info AS .tmp_vmlinux.kallsyms3.S
+ printf '  %-7s %s\n' AS .tmp_vmlinux.kallsyms3.S
+ clang -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -D__KERNEL__ -Qunused-arguments -fmacro-prefix-map=./= -D__ASSEMBLY__ -fno-PIE --target=x86_64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -m64 -fno-lto -g -gz=zstd -c -o .tmp_vmlinux.kallsyms3.o .tmp_vmlinux.kallsyms3.S
+ vmlinux_link vmlinux .tmp_vmlinux.kallsyms3.o .btf.vmlinux.bin.o
+ local output=vmlinux
+ local objs
+ local libs
+ local ld
+ local ldflags
+ local ldlibs
+ info LD vmlinux
  LD      vmlinux
+ printf '  %-7s %s\n' LD vmlinux
+ shift
+ is_enabled CONFIG_LTO_CLANG
+ grep -q '^CONFIG_LTO_CLANG=y' include/config/auto.conf
+ objs=vmlinux.o
+ libs=
+ is_enabled CONFIG_MODULES
+ grep -q '^CONFIG_MODULES=y' include/config/auto.conf
+ objs='vmlinux.o .vmlinux.export.o'
+ objs='vmlinux.o .vmlinux.export.o init/version-timestamp.o'
+ '[' x86 = um ']'
+ wl=
+ ld='ld.lld --icf=none --no-gc-sections'
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn'
+ ldlibs=
+ ldflags='-m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds'
+ '[' vmlinux '!=' vmlinux ']'
+ is_enabled CONFIG_VMLINUX_MAP
+ grep -q '^CONFIG_VMLINUX_MAP=y' include/config/auto.conf
+ ld.lld --icf=none --no-gc-sections -m elf_x86_64 --thinlto-cache-dir=.thinlto-cache -mllvm -import-instr-limit=5 --compress-debug-sections=zstd -z noexecstack --emit-relocs --discard-none -z max-page-size=0x200000 --build-id=sha1 -X --orphan-handling=warn --script=./arch/x86/kernel/vmlinux.lds -o vmlinux --whole-archive vmlinux.o .vmlinux.export.o init/version-timestamp.o --no-whole-archive --start-group --end-group .tmp_vmlinux.kallsyms3.o .btf.vmlinux.bin.o
+ is_enabled CONFIG_DEBUG_INFO_BTF
+ grep -q '^CONFIG_DEBUG_INFO_BTF=y' include/config/auto.conf
+ is_enabled CONFIG_BPF
+ grep -q '^CONFIG_BPF=y' include/config/auto.conf
+ info BTFIDS vmlinux
  BTFIDS  vmlinux
+ printf '  %-7s %s\n' BTFIDS vmlinux
+ ./tools/bpf/resolve_btfids/resolve_btfids vmlinux
FAILED: load BTF from vmlinux: Invalid argument
make[1]: *** [scripts/Makefile.vmlinux:35: vmlinux] Error 255
make[1]: *** Deleting file 'vmlinux'
make: *** [Makefile:1264: vmlinux] Error 2
RPM build warnings:
RPM build errors:
error: Bad exit status from /var/tmp/rpm-tmp.anvNrh (%build)
nathanchance commented 1 year ago

Arch Linux's version of pahole is at the same revision as yours.

$ pacman -Q pahole
pahole 1:1.24+r29+g02d67c5-1

$ clang --version | head -1
ClangBuiltLinux clang version 16.0.0

$ git show -s --format='%h ("%s")'
e128ce12e29c ("Linux 6.2.9")

$ mkdir build

$ curl -LSso build/.config https://github.com/OpenMandrivaAssociation/kernel/raw/master/x86_64-omv-defconfig

$ echo 'CONFIG_CC_IS_CLANG=y
CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
CONFIG_LD_IS_LLD=y
CONFIG_INIT_STACK_NONE=y
# CONFIG_INIT_STACK_ALL_PATTERN is not set
# CONFIG_INIT_STACK_ALL_ZERO is not set
# CONFIG_KCSAN is not set
# CONFIG_SHADOW_CALL_STACK is not set
# CONFIG_LTO_NONE is not set
# CONFIG_LTO_CLANG_FULL is not set
CONFIG_LTO_CLANG_THIN=y
CONFIG_CFI_CLANG=y
CONFIG_CFI_CLANG_SHADOW=y
CONFIG_CFI_PERMISSIVE=y
CONFIG_RELR=y' >>build/.config

$ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 O=build oldconfig all
...

$ file build/vmlinux
build/vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=1771b8274fbffb977cb8d6dc2f551cde8248b25d, with debug_info, not stripped

I wonder if libbpf is involved. I notice that your pahole spec file appears to be missing this libbpf update: https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=3aa68ba050d4ddc4b01f488ed32f594628c66fb4

Could you try upgrading libbpf and rebuilding pahole to see if that resolves this issue?

tpgxyz commented 1 year ago

Our pahole is build internally with libbpf from this commit https://github.com/libbpf/libbpf/commit/d73ecc91e1f9a2f2782e00f010a5a0d6abec09a4 from 2023-01-26

nathanchance commented 1 year ago

Hmmm, guess I was looking at an old revision of your spec file then. I still have not been able to reproduce this locally unfortunately :/

tpgxyz commented 1 year ago

I reverted to 1.1 version of internal libbpf inside pahole, and i rebuild it. Looks like this did not help at all as kernel with new pahole still fails on same error.

ms178 commented 1 year ago

@tpgxyz At one point in the past, I have seen this error, too: https://github.com/ClangBuiltLinux/linux/issues/1762

But with my current Kernel config, pahole-git provided by my distro (CachyOS) and LLVM-17 (3bde144de32dc09a0b227f7afcff94f908ac6739), I cannot reproduce this any longer.

Note that I also compile the bpf package [with GCC] and keep it in sync with the latest Kernel that I use, which is usually a good idea to get the latest fixes, too.

If I remember correctly, my BPF issues went away when I started using a Kernel config more in line with the distro-provided config. Before that, I used a heavily trimmed down version.

tpgxyz commented 1 year ago

Looks like with OBJCOPY=objcopy it works while with OBJCOPY=llvm-objcopy it does not.

nickdesaulniers commented 1 year ago

From the log provided by @tpgxyz , I think the relevant snippets are:

+ LLVM_OBJCOPY=llvm-objcopy
+ pahole -J --btf_gen_floats -j .tmp_vmlinux.btf
libbpf: BTF header not found
pahole: .tmp_vmlinux.btf: Invalid argument
+ llvm-objcopy --only-section=.BTF --set-section-flags .BTF=alloc,readonly --strip-all .tmp_vmlinux.btf .btf.vmlinux.bin.o
...
+ ./tools/bpf/resolve_btfids/resolve_btfids vmlinux
FAILED: load BTF from vmlinux: Invalid argument

so it seems like perhaps pahole failed first...not too sure. Let me ask the maintainer+list of BTF.

nickdesaulniers commented 1 year ago

Sent: https://lore.kernel.org/llvm/CAKwvOdm9PqNBLSZa_t5b=15cdtKvKq4q8WZr3i77W66m4FRAAQ@mail.gmail.com/T/#u

ms178 commented 1 year ago

Just saw this with Clang-17 (e76304d05e56f593a45fd54115e2d1d30a329a11) on Kernel 6.4.8 with linux-api-headers 6.4.8 installed, but with older packages of bpf, pahole and libbpf installed. Normally this should go away when linux-api-headers; bpf, pahole and libbpf versions are in sync.

  AR      drivers/gpu/built-in.a
  AR      drivers/built-in.a
  LD [M]  sound/pci/ac97/snd-ac97-codec.o
  AR      built-in.a
  AR      vmlinux.a
  GEN     .tmp_initcalls.lds
  LD      vmlinux.o
  OBJCOPY modules.builtin.modinfo
  GEN     modules.builtin
  MODPOST Module.symvers
  CC      .vmlinux.export.o
  UPD     include/generated/utsversion.h
  CC      init/version-timestamp.o
  LD      .tmp_vmlinux.btf
  BTF     .btf.vmlinux.bin.o
scripts/link-vmlinux.sh: line 111: 185542 memory access fault  LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1}
  LD      .tmp_vmlinux.kallsyms1
  NM      .tmp_vmlinux.kallsyms1.syms
  KSYMS   .tmp_vmlinux.kallsyms1.S
  AS      .tmp_vmlinux.kallsyms1.S
  LD      .tmp_vmlinux.kallsyms2
  NM      .tmp_vmlinux.kallsyms2.syms
  KSYMS   .tmp_vmlinux.kallsyms2.S
  AS      .tmp_vmlinux.kallsyms2.S
  LD      vmlinux
  BTFIDS  vmlinux
FAILED: load BTF from vmlinux: Invalid argument

Hm, after a re-compile of the other packages, I see SORTTAB bailng out instead now:

AR      drivers/gpu/built-in.a
  AR      drivers/built-in.a
  LD [M]  sound/pci/ac97/snd-ac97-codec.o
  AR      built-in.a
  AR      vmlinux.a
  GEN     .tmp_initcalls.lds
  LD      vmlinux.o
  OBJCOPY modules.builtin.modinfo
  GEN     modules.builtin
  MODPOST Module.symvers
  CC      .vmlinux.export.o
  UPD     include/generated/utsversion.h
  CC      init/version-timestamp.o
  LD      .tmp_vmlinux.btf
  BTF     .btf.vmlinux.bin.o
  LD      .tmp_vmlinux.kallsyms1
  NM      .tmp_vmlinux.kallsyms1.syms
  KSYMS   .tmp_vmlinux.kallsyms1.S
  AS      .tmp_vmlinux.kallsyms1.S
  LD      .tmp_vmlinux.kallsyms2
  NM      .tmp_vmlinux.kallsyms2.syms
  KSYMS   .tmp_vmlinux.kallsyms2.S
  AS      .tmp_vmlinux.kallsyms2.S
  LD      vmlinux
  BTFIDS  vmlinux
  NM      System.map
  SORTTAB vmlinux
scripts/link-vmlinux.sh: line 195: 346085 aborted             ${objtree}/scripts/sorttable ${1}
Failed to sort kernel tables

Fixed that last one by removing-fvisibility=hidden in my makepkg.conf, the Kernel now builds fine. [edit: While the Kernel-PKGBUILD mostly ignores the buildflags set globally in the makepkg.conf file, appearently they are still used for some parts of the Kernel build.]