Skip to contentSkip to conversation

tools: Bump minimum LLVM C++ std to GNU++14

PATCH Superseded Ian Rogers 2 participants 5 messages Oct 11, 2021 – Oct 12, 2021 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/2 tools: Bump minimum LLVM C++ std to GNU++14

LLVM 9 (current release is LLVM 13) moved the minimum C++ version to GNU++14. Bump the version numbers in the feature test and perf build.

---
 tools/build/feature/Makefile | 6 +++---
 tools/perf/Makefile.config   | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/build/feature/Makefile +3 -3
index d024b5204ba0..19f145a35a43 100644
@@ -300,7 +300,7 @@ $(OUTPUT)test-jvmti-cmlr.bin:
 	$(BUILD)
 
 $(OUTPUT)test-llvm.bin:
-	$(BUILDXX) -std=gnu++11 				\
+	$(BUILDXX) -std=gnu++14 				\
 		-I$(shell $(LLVM_CONFIG) --includedir) 		\
 		-L$(shell $(LLVM_CONFIG) --libdir)		\
 		$(shell $(LLVM_CONFIG) --libs Core BPF)		\
@@ -308,12 +308,12 @@ $(OUTPUT)test-llvm.bin:
 		> $(@:.bin=.make.output) 2>&1
 
 $(OUTPUT)test-llvm-version.bin:
-	$(BUILDXX) -std=gnu++11 				\
+	$(BUILDXX) -std=gnu++14					\
 		-I$(shell $(LLVM_CONFIG) --includedir)		\
 		> $(@:.bin=.make.output) 2>&1
 
 $(OUTPUT)test-clang.bin:
-	$(BUILDXX) -std=gnu++11 				\
+	$(BUILDXX) -std=gnu++14					\
 		-I$(shell $(LLVM_CONFIG) --includedir) 		\
 		-L$(shell $(LLVM_CONFIG) --libdir)		\
 		-Wl,--start-group -lclangBasic -lclangDriver	\
tools/perf/Makefile.config +1 -1
index 0ae2e3d8b832..86be3f6ec018 100644
@@ -285,7 +285,7 @@ CORE_CFLAGS += -Wall
 CORE_CFLAGS += -Wextra
 CORE_CFLAGS += -std=gnu99
 
-CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
+CXXFLAGS += -std=gnu++14 -fno-exceptions -fno-rtti
 CXXFLAGS += -Wall
 CXXFLAGS += -fno-omit-frame-pointer
 CXXFLAGS += -ggdb3
Signature · 1 line
2.33.0.882.g93a45727a2-goog
author reviewer
#1 lore raw

PATCH 2/2 perf clang: Fixes for more recent LLVM/clang

The parameters to two functions and the location of a variable have changed in more recent LLVM/clang releases.

Tested with LLVM 6, 8, 9, 10 and 11.

---
 tools/perf/util/c++/clang.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/c++/clang.cpp +13 -7
index c8885dfa3667..756200cb80b1 100644
@@ -44,7 +44,6 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
 		"-triple", "bpf-pc-linux",
 		"-fsyntax-only",
 		"-ferror-limit", "19",
-		"-fmessage-length", "127",
 		"-O2",
 		"-nostdsysteminc",
 		"-nobuiltininc",
@@ -55,7 +54,11 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
 		"-x", "c"};
 
 	CCArgs.append(CFlags.begin(), CFlags.end());
-	CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs);
+	CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs
+#if CLANG_VERSION_MAJOR >= 11
+                                                        ,/*BinaryName=*/nullptr
+#endif
+                                                        );
 
 	FrontendOptions& Opts = CI->getFrontendOpts();
 	Opts.Inputs.clear();
@@ -151,13 +154,16 @@ getBPFObjectFromModule(llvm::Module *Module)
 
 	legacy::PassManager PM;
 	bool NotAdded;
-#if CLANG_VERSION_MAJOR < 7
-	NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream,
-						      TargetMachine::CGFT_ObjectFile);
+	NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream
+#if CLANG_VERSION_MAJOR >= 7
+                                                      , /*DwoOut=*/nullptr
+#endif
+#if CLANG_VERSION_MAJOR < 10
+                                                      , TargetMachine::CGFT_ObjectFile
 #else
-	NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream, nullptr,
-						      TargetMachine::CGFT_ObjectFile);
+                                                      , llvm::CGFT_ObjectFile
 #endif
+                                                      );
 	if (NotAdded) {
 		llvm::errs() << "TargetMachine can't emit a file of this type\n";
 		return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
Signature · 1 line
2.33.0.882.g93a45727a2-goog
author reviewer
#2 lore raw

Re: [PATCH 2/2] perf clang: Fixes for more recent LLVM/clang

Quoted 16 lines · Ian Rogers

The parameters to two functions and the location of a variable have changed in more recent LLVM/clang releases.

Tested with LLVM 6, 8, 9, 10 and 11.

---
 tools/perf/util/c++/clang.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/c++/clang.cpp +0 -0
index c8885dfa3667..756200cb80b1 100644

tools/perf/util/c++/clang.cpp createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path, · line 47

Quoted 4 lines
tools/perf/util/c++/clang.cpp +0 -1
@@ -44,7 +44,6 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
                "-triple", "bpf-pc-linux",
                "-fsyntax-only",
                "-ferror-limit", "19",
-               "-fmessage-length", "127",

Sorry, missed from the commit message. I removed this flag to format output down to 127 columns as with clang 11 I see in perf test:

58: builtin clang support :
58.1: builtin clang compile C source to IR :
--- start ---
test child forked, pid 279307
error: unknown argument: '-fmessage-length'
1 error generated.
test child finished with -1

The flag isn't necessary for correct operation.

Thanks,
Ian

Quoted 41 lines
tools/perf/util/c++/clang.cpp +13 -7
                "-O2",
                "-nostdsysteminc",
                "-nobuiltininc",
@@ -55,7 +54,11 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
                "-x", "c"};
 
        CCArgs.append(CFlags.begin(), CFlags.end());
-       CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs);
+       CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs
+#if CLANG_VERSION_MAJOR >= 11
+                                                        ,/*BinaryName=*/nullptr
+#endif
+                                                        );
 
        FrontendOptions& Opts = CI->getFrontendOpts();
        Opts.Inputs.clear();
@@ -151,13 +154,16 @@ getBPFObjectFromModule(llvm::Module *Module)
 
        legacy::PassManager PM;
        bool NotAdded;
-#if CLANG_VERSION_MAJOR < 7
-       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream,
-                                                     TargetMachine::CGFT_ObjectFile);
+       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream
+#if CLANG_VERSION_MAJOR >= 7
+                                                      , /*DwoOut=*/nullptr
+#endif
+#if CLANG_VERSION_MAJOR < 10
+                                                      , TargetMachine::CGFT_ObjectFile
 #else
-       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream, nullptr,
-                                                     TargetMachine::CGFT_ObjectFile);
+                                                      , llvm::CGFT_ObjectFile
 #endif
+                                                      );
        if (NotAdded) {
                llvm::errs() << "TargetMachine can't emit a file of this type\n";
                return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
--

2.33.0.882.g93a45727a2-goog

#3 lore raw

Re: [PATCH 2/2] perf clang: Fixes for more recent LLVM/clang

Quoted 34 lines · Ian Rogers
Quoted 16 lines · Ian Rogers

The parameters to two functions and the location of a variable have changed in more recent LLVM/clang releases.

Tested with LLVM 6, 8, 9, 10 and 11.

---
 tools/perf/util/c++/clang.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/c++/clang.cpp +0 -0
index c8885dfa3667..756200cb80b1 100644

tools/perf/util/c++/clang.cpp createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path, · line 47

Quoted 4 lines
tools/perf/util/c++/clang.cpp +0 -1
@@ -44,7 +44,6 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
                "-triple", "bpf-pc-linux",
                "-fsyntax-only",
                "-ferror-limit", "19",
-               "-fmessage-length", "127",

Sorry, missed from the commit message. I removed this flag to format output down to 127 columns as with clang 11 I see in perf test:

58: builtin clang support :
58.1: builtin clang compile C source to IR :
--- start ---
test child forked, pid 279307
error: unknown argument: '-fmessage-length'
1 error generated.
test child finished with -1

Quoted 1 line

The flag isn't necessary for correct operation.

Right, I changed the -cc1 option from Separate-form -fmessage-length to -fmessage-length= in 2020-03.
-ferror-limit can be deleted as well.

Quoted 36 lines

Thanks,
Ian

Quoted 33 lines
tools/perf/util/c++/clang.cpp +12 -6
                "-O2",
                "-nostdsysteminc",
                "-nobuiltininc",
@@ -55,7 +54,11 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
                "-x", "c"};
 
        CCArgs.append(CFlags.begin(), CFlags.end());
-       CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs);
+       CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs
+#if CLANG_VERSION_MAJOR >= 11
+                                                        ,/*BinaryName=*/nullptr
+#endif
+                                                        );
 
        FrontendOptions& Opts = CI->getFrontendOpts();
        Opts.Inputs.clear();
@@ -151,13 +154,16 @@ getBPFObjectFromModule(llvm::Module *Module)
 
        legacy::PassManager PM;
        bool NotAdded;
-#if CLANG_VERSION_MAJOR < 7
-       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream,
-                                                     TargetMachine::CGFT_ObjectFile);
+       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream
+#if CLANG_VERSION_MAJOR >= 7
+                                                      , /*DwoOut=*/nullptr
+#endif
+#if CLANG_VERSION_MAJOR < 10
+                                                      , TargetMachine::CGFT_ObjectFile
 #else
-       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream, nullptr,
-                                                     TargetMachine::CGFT_ObjectFile);
+                                                      , llvm::CGFT_ObjectFile
Quoted 8 lines
Quoted 8 lines
tools/perf/util/c++/clang.cpp +1 -1
 #endif
+                                                      );
        if (NotAdded) {
                llvm::errs() << "TargetMachine can't emit a file of this type\n";
                return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
--

2.33.0.882.g93a45727a2-goog

Related, does it make sense to drop CLANG_VERSION_MAJOR<7 support?

author reviewer
#4 lore raw

Re: [PATCH 2/2] perf clang: Fixes for more recent LLVM/clang

Quoted 36 lines · Fāng-ruì Sòng
Quoted 34 lines · Ian Rogers
Quoted 16 lines · Ian Rogers

The parameters to two functions and the location of a variable have changed in more recent LLVM/clang releases.

Tested with LLVM 6, 8, 9, 10 and 11.

---
 tools/perf/util/c++/clang.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/perf/util/c++/clang.cpp +0 -0
index c8885dfa3667..756200cb80b1 100644

tools/perf/util/c++/clang.cpp createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path, · line 47

Quoted 4 lines
tools/perf/util/c++/clang.cpp +0 -1
@@ -44,7 +44,6 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
                "-triple", "bpf-pc-linux",
                "-fsyntax-only",
                "-ferror-limit", "19",
-               "-fmessage-length", "127",

Sorry, missed from the commit message. I removed this flag to format output down to 127 columns as with clang 11 I see in perf test:

58: builtin clang support :
58.1: builtin clang compile C source to IR :
--- start ---
test child forked, pid 279307
error: unknown argument: '-fmessage-length'
1 error generated.
test child finished with -1

Quoted 5 lines
Quoted 1 line

The flag isn't necessary for correct operation.

Right, I changed the -cc1 option from Separate-form -fmessage-length to -fmessage-length= in 2020-03.
-ferror-limit can be deleted as well.

Done in v2 (please consider adding Acked-by, Reviewed-by, etc).

Quoted 38 lines
Quoted 38 lines

Thanks,
Ian

Quoted 35 lines
tools/perf/util/c++/clang.cpp +13 -6
                "-O2",
                "-nostdsysteminc",
                "-nobuiltininc",
@@ -55,7 +54,11 @@ createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
                "-x", "c"};
 
        CCArgs.append(CFlags.begin(), CFlags.end());
-       CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs);
+       CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs
+#if CLANG_VERSION_MAJOR >= 11
+                                                        ,/*BinaryName=*/nullptr
+#endif
+                                                        );
 
        FrontendOptions& Opts = CI->getFrontendOpts();
        Opts.Inputs.clear();
@@ -151,13 +154,16 @@ getBPFObjectFromModule(llvm::Module *Module)
 
        legacy::PassManager PM;
        bool NotAdded;
-#if CLANG_VERSION_MAJOR < 7
-       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream,
-                                                     TargetMachine::CGFT_ObjectFile);
+       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream
+#if CLANG_VERSION_MAJOR >= 7
+                                                      , /*DwoOut=*/nullptr
+#endif
+#if CLANG_VERSION_MAJOR < 10
+                                                      , TargetMachine::CGFT_ObjectFile
 #else
-       NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream, nullptr,
-                                                     TargetMachine::CGFT_ObjectFile);
+                                                      , llvm::CGFT_ObjectFile
 #endif
+                                                      );
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
tools/perf/util/c++/clang.cpp +0 -1
        if (NotAdded) {
                llvm::errs() << "TargetMachine can't emit a file of this type\n";
                return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
--

2.33.0.882.g93a45727a2-goog

Related, does it make sense to drop CLANG_VERSION_MAJOR<7 support?

Arnaldo can likely best comment. Clang 6.0.1 was released on July 5th 2018 so it may still be in his build tests.

Thanks!
Ian