perf clang: Fixes for more recent LLVM/clang
Hi
We build perf with clang also recently, but unlucky that failed with following errors:
```
In file included from /usr/lib/llvm-7/include/llvm/ADT/STLExtras.h:21,
from /usr/lib/llvm-7/include/llvm/ADT/StringRef.h:13,
from /usr/lib/llvm-7/include/clang/Basic/Version.h:20,
from test-clang.cpp:2:
/usr/lib/llvm-7/include/llvm/ADT/SmallVector.h: In instantiation of 'void llvm::SmallVectorTemplateBase<T, true>::push_back(const T&) [with T = clang::driver::OffloadUnbundlingJobAction::DependentActionInfo]':
/usr/lib/llvm-7/include/clang/Driver/Action.h:579:61: required from here
/usr/lib/llvm-7/include/llvm/ADT/SmallVector.h:313:11: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct clang::driver::OffloadUnbundlingJobAction::DependentActionInfo' with no trivial copy-assignment; use copy-initialization instead [-Werror=class-memaccess]
memcpy(this->end(), &Elt, sizeof(T));
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/lib/llvm-7/include/clang/Driver/Driver.h:15,
from test-clang.cpp:6:
/usr/lib/llvm-7/include/clang/Driver/Action.h:549:10: note: 'struct clang::driver::OffloadUnbundlingJobAction::DependentActionInfo' declared here
struct DependentActionInfo final {
^~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
```llvm version: 7
rootfs: Debian10
kernel: v5.8 v5.11 v5.15
reproduce:
$ cd linux/tools/perf $ make LIBCLANGLLVM=1 ARCH= EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address'
Would you please kindly point out what's wrong with our steps? Or can you give us your command to make perf with clang?
Thanks
Ma Xinjian
Quoted 37 lines · Ma Xinjian
Hi
We build perf with clang also recently, but unlucky that failed with following errors:
``` In file included from /usr/lib/llvm-7/include/llvm/ADT/STLExtras.h:21, from /usr/lib/llvm-7/include/llvm/ADT/StringRef.h:13, from /usr/lib/llvm-7/include/clang/Basic/Version.h:20, from test-clang.cpp:2: /usr/lib/llvm-7/include/llvm/ADT/SmallVector.h: In instantiation of 'void llvm::SmallVectorTemplateBase<T, true>::push_back(const T&) [with T = clang::driver::OffloadUnbundlingJobAction::DependentActionInfo]': /usr/lib/llvm-7/include/clang/Driver/Action.h:579:61: required from here /usr/lib/llvm-7/include/llvm/ADT/SmallVector.h:313:11: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct clang::driver::OffloadUnbundlingJobAction::DependentActionInfo' with no trivial copy-assignment; use copy-initialization instead [-Werror=class-memaccess] memcpy(this->end(), &Elt, sizeof(T)); ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/lib/llvm-7/include/clang/Driver/Driver.h:15, from test-clang.cpp:6: /usr/lib/llvm-7/include/clang/Driver/Action.h:549:10: note: 'struct clang::driver::OffloadUnbundlingJobAction::DependentActionInfo' declared here struct DependentActionInfo final { ^~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors ```llvm version: 7
rootfs: Debian10
kernel: v5.8 v5.11 v5.15
reproduce:
Quoted 6 lines
$ cd linux/tools/perf $ make LIBCLANGLLVM=1 ARCH= EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address'Would you please kindly point out what's wrong with our steps? Or can you give us your command to make perf with clang?
Hi Xinjian,
As the bug is in LLVM 7 there is little we can do in Linux perf to fix the issue. I haven't got LLVM 7 on my machine to test with, but I see the same problem with LLVM 6 - both of which are of course quite old. My workaround is to add to the make command line "CXXFLAGS=-Wno-error=class-memaccess". My full command line is:
make -C tools/perf O=/tmp/perf DESTDIR=/tmp/perf-install DEBUG=1 LIBPFM4=1 NO_LIBBFD=1 LIBCLANGLLVM=1 LLVM_CONFIG=/usr/lib/llvm-6.0/bin/llvm-config CXXFLAGS=-Wno-error=class-memaccess
I know Intel is keen on testing. Related to this code are the BPF tests in "perf test". I frequently see flakes on these tests that count the number of times a system call is called. The flakes are an under or over count by 1. The over count by 1 I can explain if during the test another process happens to use the same system call. The under counting is harder to explain and is possibly an indication of a data race. I'd be happy for any suggestions to fix these flakes.
Thanks,
Ian
Quoted 2 lines
Thanks
Ma Xinjian
Em Fri, Nov 12, 2021 at 06:24:44PM +0800, Ma Xinjian escreveu:
Quoted 36 lines
Hi
We build perf with clang also recently, but unlucky that failed with following errors:
``` In file included from /usr/lib/llvm-7/include/llvm/ADT/STLExtras.h:21, from /usr/lib/llvm-7/include/llvm/ADT/StringRef.h:13, from /usr/lib/llvm-7/include/clang/Basic/Version.h:20, from test-clang.cpp:2: /usr/lib/llvm-7/include/llvm/ADT/SmallVector.h: In instantiation of 'void llvm::SmallVectorTemplateBase<T, true>::push_back(const T&) [with T = clang::driver::OffloadUnbundlingJobAction::DependentActionInfo]': /usr/lib/llvm-7/include/clang/Driver/Action.h:579:61: required from here /usr/lib/llvm-7/include/llvm/ADT/SmallVector.h:313:11: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct clang::driver::OffloadUnbundlingJobAction::DependentActionInfo' with no trivial copy-assignment; use copy-initialization instead [-Werror=class-memaccess] memcpy(this->end(), &Elt, sizeof(T)); ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/lib/llvm-7/include/clang/Driver/Driver.h:15, from test-clang.cpp:6: /usr/lib/llvm-7/include/clang/Driver/Action.h:549:10: note: 'struct clang::driver::OffloadUnbundlingJobAction::DependentActionInfo' declared here struct DependentActionInfo final { ^~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors ```llvm version: 7
rootfs: Debian10
kernel: v5.8 v5.11 v5.15
reproduce:
Quoted 6 lines
$ cd linux/tools/perf $ make LIBCLANGLLVM=1 ARCH= EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address'Would you please kindly point out what's wrong with our steps? Or can you give us your command to make perf with clang?
This is just for building it with clang embedded, is that strictly required?
I.e. you can still use perf to build bpf by calling clang, etc.
Or are you trying to _build_ perf using clang?
To build perf with clang:
⬢[acme@toolbox perf]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf ; ⬢[acme@toolbox perf]$ make -C tools/perf CC=clang O=/tmp/build/perf
End result:
⬢[acme@toolbox perf]$ perf -v
perf version 5.15.gf8b114cfd541
⬢[acme@toolbox perf]$ readelf -wi /tmp/build/perf/perf | grep -m5 DW_AT_producer
<c> DW_AT_producer : (indirect string, offset: 0x0): clang version 13.0.0 (https://github.com/llvm/llvm-project e8991caea8690ec2d17b0b7e1c29bf0da6609076) <a6b> DW_AT_producer : (indirect string, offset: 0x0): clang version 13.0.0 (https://github.com/llvm/llvm-project e8991caea8690ec2d17b0b7e1c29bf0da6609076) <76f0> DW_AT_producer : (indirect string, offset: 0x0): clang version 13.0.0 (https://github.com/llvm/llvm-project e8991caea8690ec2d17b0b7e1c29bf0da6609076) <823d> DW_AT_producer : (indirect string, offset: 0x0): clang version 13.0.0 (https://github.com/llvm/llvm-project e8991caea8690ec2d17b0b7e1c29bf0da6609076) <121a8> DW_AT_producer : (indirect string, offset: 0x0): clang version 13.0.0 (https://github.com/llvm/llvm-project e8991caea8690ec2d17b0b7e1c29bf0da6609076)
⬢[acme@toolbox perf]$
- Arnaldo