• Yonghong Song's avatar
    samples/bpf: Change Makefile to cope with latest llvm · 9618bde4
    Yonghong Song authored
    With latest llvm trunk, bpf programs under samples/bpf
    directory, if using CORE, may experience the following
    errors:
    
    LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
    PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
    Stack dump:
    0.      Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
    1.      Running pass 'Function Pass Manager' on module '<stdin>'.
    2.      Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
     #0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
        (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
    ...
     #7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
     #8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
        (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
     #9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
        unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)
    ...
    Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
    
    The reason is due to llvm change https://reviews.llvm.org/D87153
    where the CORE relocation global generation is moved from the beginning
    of target dependent optimization (llc) to the beginning
    of target independent optimization (opt).
    
    Since samples/bpf programs did not use vmlinux.h and its clang compilation
    uses native architecture, we need to adjust arch triple at opt level
    to do CORE relocation global generation properly. Otherwise, the above
    error will appear.
    
    This patch fixed the issue by introduce opt and llvm-dis to compilation chain,
    which will do proper CORE relocation global generation as well as O2 level
    optimization. Tested with llvm10, llvm11 and trunk/llvm12.
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
    Link: https://lore.kernel.org/bpf/20201006043427.1891742-1-yhs@fb.com
    9618bde4
Makefile 10.8 KB