llvm/clang: fix some syntax issues in llvm-project-source
v2 cover llvm/clang: fix some syntax issues in llvm-project-source
Hello,
I faced some strange build issues when switching from one distro to another (i.e. DISTRO="poky" to DISTRO="foobar"), even after adding "foobar" ("foobar:foobar" actually) to CLANG_EXTRA_OE_DISTRO. I started investigating what was wrong, and I believe the order of pathes in this series reflects pretty well what specific issue I stumbled upon and what was the next one, on and on.
The error message was:
/src/build/tmp/work/riscv64imafdc-foobar-linux/libcxx/22.1.3/recipe-sysroot-native/usr/bin/riscv64-foobar-linux/riscv64-foobar-linux-ld: cannot find crtbeginS.o: No such file or directory /src/build/tmp/work/riscv64imafdc-foobar-linux/libcxx/22.1.3/recipe-sysroot-native/usr/bin/riscv64-foobar-linux/riscv64-foobar-linux-ld: cannot find -lstdc++: No such file or directory /src/build/tmp/work/riscv64imafdc-foobar-linux/libcxx/22.1.3/recipe-sysroot-native/usr/bin/riscv64-foobar-linux/riscv64-foobar-linux-ld: cannot find -lgcc: No such file or directory riscv64-foobar-linux-clang++: error: linker command failed with exit code 1 (use -v to see invocation)
As far as I understand, this is precisely what do_preconfigure (+ some patches) is supposed to handle, so at first it looked like a regression, but it seems the error only reproduces when switching distros.
For some context, I was building something with PREFERRED_TOOLCHAIN_TARGET="clang", using wrynose branch. If I use the custom distro from the beginning (so no switching), everything works fine (as expected).
Best regards,
Changes in v2:
- squashed the patch* into 0016-llvm-clang-Insert-anchor-for-adding-OE-distro-vendor.patch
- added vardeps to do_unpack as well (5th patch)
* 0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch
João Marcos Costa (5):
llvm-project-source.inc: fix string replacements in do_preconfigure llvm-project-source.inc: fix end of line in triple variable clang/llvm: add missing instance of Distro class in Linux.cpp llvm-project-source.inc: add vardeps to do_preconfigure llvm-project-source.inc: add vardeps to do_unpack
...t-anchor-for-adding-OE-distro-vendor.patch | 35 ++++++++++++++----- .../clang/llvm-project-source.inc | 8 +++-- 2 files changed, 31 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/5 llvm-project-source.inc: fix string replacements in do_preconfigure
Both CLANG_EXTRA_OE_DISTRO_CASE and CLANG_EXTRA_OE_DISTRO_TRIPLE are added by the same patch:
0016-llvm-clang-Insert-anchor-for-adding-OE-distro-vendor.patch
and they are supposed to be replaced by a couple of sed commands in do_preconfigure. However, sed looks for CLANG_EXTRA_OE_DISTRO_CASES (and CLANG_EXTRA_OE_DISTRO_TRIPLES) and since none is found, the code is left with the dangling comment like so:
@ clang/lib/Driver/ToolChains/Linux.cpp
82 if (TargetEnvironment == llvm::Triple::GNUX32)
83 return "x86_64-linux-gnux32";
84 //CLANG_EXTRA_OE_DISTRO_TRIPLE
85 return "x86_64-linux-gnu";
Fix that by removing the 'S' in the end of ..._CASES and ..._TRIPLES.
Another way to fix this would be to directly change the patch, but simply changing do_preconfigure feels cleaner.
--- meta/recipes-devtools/clang/llvm-project-source.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
meta/recipes-devtools/clang/llvm-project-source.inc +2 -2
@@ -82,9 +82,9 @@ python do_preconfigure() { subprocess.check_output(cmd, stderr=subprocess.STDOUT) cmd = ['sed', '-i', 's#//CLANG_EXTRA_OE_DISTRO_CHECK#%s#g' % check, source + '/clang/include/clang/Driver/Distro.h'] subprocess.check_output(cmd, stderr=subprocess.STDOUT) - cmd = ['sed', '-i', 's#//CLANG_EXTRA_OE_DISTRO_TRIPLES#%s#g' % triple, source + '/clang/lib/Driver/ToolChains/Linux.cpp'] + cmd = ['sed', '-i', 's#//CLANG_EXTRA_OE_DISTRO_TRIPLE#%s#g' % triple, source + '/clang/lib/Driver/ToolChains/Linux.cpp'] subprocess.check_output(cmd, stderr=subprocess.STDOUT) - cmd = ['sed', '-i', 's#//CLANG_EXTRA_OE_DISTRO_CASES#%s#g' % case, source + '/clang/lib/Driver/Distro.cpp'] + cmd = ['sed', '-i', 's#//CLANG_EXTRA_OE_DISTRO_CASE#%s#g' % case, source + '/clang/lib/Driver/Distro.cpp'] subprocess.check_output(cmd, stderr=subprocess.STDOUT) }
Signature · 1 line
2.43.0
PATCH v2 2/5 llvm-project-source.inc: fix end of line in triple variable
In reply to João Marcos CostaAfter the return statement, a "," is present while a ";" is expected.
This leads to something like:
...return "x86_64-poky-linux",
Fix this syntax error by replacing "," with a ";".
--- meta/recipes-devtools/clang/llvm-project-source.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-devtools/clang/llvm-project-source.inc +1 -1
@@ -71,7 +71,7 @@ python do_preconfigure() { distro_id = distro.split(":")[0].replace('-','_') distro_triple = distro.split(":")[1] case += '\\n .Case("' + distro_id + '", Distro::' + distro_id.upper() + ')' - triple += '\\n if (Distro.Is' + distro_id.upper() + '())\\n return "x86_64-' + distro_triple + '-linux",' + triple += '\\n if (Distro.Is' + distro_id.upper() + '())\\n return "x86_64-' + distro_triple + '-linux";' name += '\\n '+ distro_id.upper() + ',' check += '\\nbool Is' + distro_id.upper() + '() const { return DistroVal == ' + distro_id.upper() + '; }' oe_names += distro_id.upper() + ' ||'
Signature · 1 line
2.43.0
PATCH v2 3/5 clang/llvm: add missing instance of Distro class in Linux.cpp
In reply to João Marcos CostaThis instance will be used to perform the checks added by do_preconfigure task, such as "Distro.IsOpenEmbedded()", or "Distro.IsPOKY()".
Without such instance, the compiler raises an "expected unqualified-id" error.
Something similar is performed by another patch, by the way:
0009-clang-Define-releative-gcc-installation-dir.patch:+ Distro Distro(D.getVFS(), TargetTriple);
0009-clang-Define-releative-gcc-installation-dir.patch:+ Distro.IsOpenEmbedded()},
--- ...t-anchor-for-adding-OE-distro-vendor.patch | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-)
meta/recipes-devtools/clang/clang/0016-llvm-clang-Insert-anchor-for-adding-OE-distro-vendor.patch +26 -9
@@ -1,7 +1,10 @@ -From b14d66e6250566fb0b7786af92e3e83bade51c90 Mon Sep 17 00:00:00 2001 +From 259d8eb2ed82c9248387a3cbb1befee358ecbb8e Mon Sep 17 00:00:00 2001 From: Hongxu Jia <[email protected]> Date: Mon, 25 Jan 2021 16:14:35 +0800 Subject: [PATCH] llvm/clang: Insert anchor for adding OE distro vendor names +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit This helps in making right detection for OE built gcc toolchains
@@ -82,22 +85,25 @@ b59da142f2b0:$ /path/to/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot programs: =/build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin libraries: =/build/tmp-glibc/work/x84_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/lib/clang/13.0.1:/usr/lib/x86_64-wrs-linux/10.2.0://lib/x86_64-wrs-linux://usr/lib/x86_64-wrs-linux:/build/tmp-glibc/work/x86_64-linux/compiler-rt-native/13.0.1-r0/recipe-sysroot-native/usr/bin/../lib://lib://usr/lib +[JM: add missing instance of Distro class in getMultiarchTriple(), at Linux.cpp] + Upstream-Status: Inappropriate [oe specific] Signed-off-by: Martin Jansa <[email protected]> Signed-off-by: Hongxu Jia <[email protected]> Signed-off-by: Changqing Li <[email protected]> Signed-off-by: Khem Raj <[email protected]> +Signed-off-by: João Marcos Costa <[email protected]> --- clang/include/clang/Driver/Distro.h | 2 ++ clang/lib/Driver/Distro.cpp | 1 + clang/lib/Driver/ToolChains/Gnu.cpp | 1 + - clang/lib/Driver/ToolChains/Linux.cpp | 1 + + clang/lib/Driver/ToolChains/Linux.cpp | 2 ++ llvm/lib/TargetParser/Triple.cpp | 2 +- - 5 files changed, 6 insertions(+), 1 deletion(-) + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/Distro.h b/clang/include/clang/Driver/Distro.h -index 0e17b30eb7e8..b449a62dc299 100644 +index 0e17b30eb..b449a62dc 100644 --- a/clang/include/clang/Driver/Distro.h +++ b/clang/include/clang/Driver/Distro.h @@ -45,6 +45,7 @@ public:
@@ -117,7 +123,7 @@ index 0e17b30eb7e8..b449a62dc299 100644 }; diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp -index df10458d092d..61dc127a4574 100644 +index df10458d0..61dc127a4 100644 --- a/clang/lib/Driver/Distro.cpp +++ b/clang/lib/Driver/Distro.cpp @@ -43,6 +43,7 @@ static Distro::DistroType DetectOsRelease(llvm::vfs::FileSystem &VFS) {
@@ -129,7 +135,7 @@ index df10458d092d..61dc127a4574 100644 return Version; } diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp -index c80980a7fb09..80fd8058bd98 100644 +index c80980a7f..80fd8058b 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2370,6 +2370,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
@@ -141,10 +147,18 @@ index c80980a7fb09..80fd8058bd98 100644 static const char *const X32Triples[] = {"x86_64-linux-gnux32", "x86_64-pc-linux-gnux32"}; diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp -index 7b608a84a66e..4a0adedce09a 100644 +index 7b608a84a..585a86a2d 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp -@@ -81,6 +81,7 @@ std::string Linux::getMultiarchTriple(const Driver &D, +@@ -45,6 +45,7 @@ std::string Linux::getMultiarchTriple(const Driver &D, + bool IsAndroid = TargetTriple.isAndroid(); + bool IsMipsR6 = TargetTriple.getSubArch() == llvm::Triple::MipsSubArch_r6; + bool IsMipsN32Abi = TargetTriple.getEnvironment() == llvm::Triple::GNUABIN32; ++ Distro Distro(D.getVFS(), TargetTriple); + + // For most architectures, just use whatever we have rather than trying to be + // clever. +@@ -81,6 +82,7 @@ std::string Linux::getMultiarchTriple(const Driver &D, return "x86_64-linux-android"; if (TargetEnvironment == llvm::Triple::GNUX32) return "x86_64-linux-gnux32";
@@ -153,7 +167,7 @@ index 7b608a84a66e..4a0adedce09a 100644 case llvm::Triple::aarch64: if (IsAndroid) diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp -index a4f9dd42c0fe..86b74451ec0d 100644 +index a4f9dd42c..86b74451e 100644 --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -702,7 +702,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) {
@@ -165,3 +179,6 @@ index a4f9dd42c0fe..86b74451ec0d 100644 .Default(Triple::UnknownVendor); } +-- +2.39.5 +
Signature · 1 line
2.43.0
PATCH v2 4/5 llvm-project-source.inc: add vardeps to do_preconfigure
In reply to João Marcos CostaThe task's signature should change if CLANG_EXTRA_OE_DISTRO and/or CLANG_EXTRA_OE_VENDORS, considering the couple of for loops in do_preconfigure iterate over their values.
By adding them to 'vardeps', bitbake will correctly detect if do_preconfigure needs to be executed.
--- meta/recipes-devtools/clang/llvm-project-source.inc | 1 + 1 file changed, 1 insertion(+)
meta/recipes-devtools/clang/llvm-project-source.inc +1 -0
@@ -90,4 +90,5 @@ python do_preconfigure() { do_patch[vardepsexclude] += "MULTILIBS MULTILIB_VARIANTS" addtask do_preconfigure after do_patch +do_preconfigure[vardeps] += "CLANG_EXTRA_OE_DISTRO CLANG_EXTRA_OE_VENDORS" do_create_spdx[depends] += "${PN}:do_preconfigure"
Signature · 1 line
2.43.0
Re: [OE-core] [PATCH v2 4/5] llvm-project-source.inc: add vardeps to do_preconfigure
Quoted 17 lines · Joao Marcos Costa via lists.openembedded.org
The task's signature should change if
CLANG_EXTRA_OE_DISTROand/orCLANG_EXTRA_OE_VENDORS, considering the couple of for loops indo_preconfigureiterate over their values.By adding them to 'vardeps', bitbake will correctly detect if
do_preconfigureneeds to be executed.Signed-off-by João Marcos Costa <[email protected]>---
meta/recipes-devtools/clang/llvm-project-source.inc | 1 +1 file changed, 1 insertion(+)meta/recipes-devtools/clang/llvm-project-source.inc +0
-0@@ -90,4 +90,5 @@ python do_preconfigure() {
Quoted 5 lines
do_patch[vardepsexclude] += "MULTILIBSMULTILIB_VARIANTS" addtaskdo_preconfigureafterdo_patch+do_preconfigure[vardeps] += "CLANG_EXTRA_OE_DISTROCLANG_EXTRA_OE_VENDORS" do_create_spdx[depends] += "${PN}:do_preconfigure"
We require that tasks can run in isolation and that can happen for many different reasons. Your fix does improve things a bit but it doesn't fix the underlying problem.
Ideally we'd change the search/replace expressions so that they always change/update the required entries. That does sometimes need a bit more thought about how the expressions work and it means you can't use replacement tokens (unless as a comment on the line above?).
Another less optimal way to improve things is to change do_preconfigure into a postfunc for do_unpack, but it wouldn't be able to change things altered by do_patch. You can't make it a do_patch postfunc as it could still have the current issues with the changes not being updated.
Cheers,
Richard
Re: [OE-core] [PATCH v2 4/5] llvm-project-source.inc: add vardeps to do_preconfigure
Hello, Richard
Quoted 33 lines · Richard Purdie via lists.openembedded.org
Quoted 17 lines · Joao Marcos Costa via lists.openembedded.org
The task's signature should change if
CLANG_EXTRA_OE_DISTROand/orCLANG_EXTRA_OE_VENDORS, considering the couple of for loops indo_preconfigureiterate over their values.By adding them to 'vardeps', bitbake will correctly detect if
do_preconfigureneeds to be executed.Signed-off-by João Marcos Costa <[email protected]>--- meta/recipes-devtools/clang/llvm-project-source.inc | 1 + 1 file changed, 1 insertion(+)meta/recipes-devtools/clang/llvm-project-source.inc +0
-0meta/recipes-devtools/clang/llvm-project-source.inc python do_preconfigure() { · line 94
Quoted 5 lines
meta/recipes-devtools/clang/llvm-project-source.inc +1
-0@@ -90,4 +90,5 @@ python do_preconfigure() { do_patch[vardepsexclude] += "MULTILIBS MULTILIB_VARIANTS" addtask do_preconfigure after do_patch +do_preconfigure[vardeps] += "CLANG_EXTRA_OE_DISTRO CLANG_EXTRA_OE_VENDORS" do_create_spdx[depends] += "${PN}:do_preconfigure"We require that tasks can run in isolation and that can happen for many different reasons. Your fix does improve things a bit but it doesn't fix the underlying problem.
Ideally we'd change the search/replace expressions so that they always change/update the required entries. That does sometimes need a bit more thought about how the expressions work and it means you can't use replacement tokens (unless as a comment on the line above?).
Quoted 8 lines
Another less optimal way to improve things is to change
do_preconfigureinto a postfunc fordo_unpack, but it wouldn't be able to change things altered bydo_patch. You can't make it ado_patchpostfunc as it could still have the current issues with the changes not being updated.Cheers,
Richard
I see your point. I'd be more eager to have a reproducible search/replace strategy than using postfuncs, but this would require some more time, and I will soon be OOO for a few days.
What is the perspective for this series? Does it heavily depend on this last part? I would prefer not to delay this fix any longer, and I could send another series later to add some testing (to avoid regressions in the future), and a more solid search/replace in do_preconfigure.
Signature · 2 lines
Best regards, João Marcos Costa
Re: [OE-core] [PATCH v2 4/5] llvm-project-source.inc: add vardeps to do_preconfigure
Quoted 43 lines · Joao Marcos Costa
Quoted 33 lines · Richard Purdie via lists.openembedded.org
Quoted 17 lines · Joao Marcos Costa via lists.openembedded.org
The task's signature should change if
CLANG_EXTRA_OE_DISTROand/orCLANG_EXTRA_OE_VENDORS, considering the couple of for loops indo_preconfigureiterate over their values.By adding them to 'vardeps', bitbake will correctly detect if
do_preconfigureneeds to be executed.Signed-off-by João Marcos Costa <[email protected]>---
meta/recipes-devtools/clang/llvm-project-source.inc | 1 +1 file changed, 1 insertion(+)meta/recipes-devtools/clang/llvm-project-source.inc +0
-0@@ -90,4 +90,5 @@ python do_preconfigure() {Quoted 5 lines
do_patch[vardepsexclude] += "MULTILIBSMULTILIB_VARIANTS" addtaskdo_preconfigureafterdo_patch+do_preconfigure[vardeps] += "CLANG_EXTRA_OE_DISTROCLANG_EXTRA_OE_VENDORS" do_create_spdx[depends] += "${PN}:do_preconfigure"We require that tasks can run in isolation and that can happen for many different reasons. Your fix does improve things a bit but it doesn't fix the underlying problem.
Ideally we'd change the search/replace expressions so that they always change/update the required entries. That does sometimes need a bit more thought about how the expressions work and it means you can't use replacement tokens (unless as a comment on the line above?).
Quoted 8 lines
Another less optimal way to improve things is to change
do_preconfigureinto a postfunc fordo_unpack, but it wouldn't be able to change things altered bydo_patch. You can't make it ado_patchpostfunc as it could still have the current issues with the changes not being updated.Cheers,
Richard
Quoted 8 lines
I see your point. I'd be more eager to have a reproducible search/replace strategy than using postfuncs, but this would require some more time, and I will soon be OOO for a few days.
What is the perspective for this series? Does it heavily depend on this last part? I would prefer not to delay this fix any longer, and I could send another series later to add some testing (to avoid regressions in the future), and a more solid search/replace in
do_preconfigure.
I've merged the first 3 patches, those makes sense on their own. I'm a bit more reluctant for the last two as I really would like to fix the issue correctly...
Cheers,
Richard
Re: [OE-core] [PATCH v2 4/5] llvm-project-source.inc: add vardeps to do_preconfigure
Hello,
Quoted 7 lines · Richard Purdie
I've merged the first 3 patches, those makes sense on their own. I'm a bit more reluctant for the last two as I really would like to fix the issue correctly...
Cheers,
Richard
I'll add that to my to-do list then. Thanks!
Signature · 2 lines
Best regards, João Marcos Costa
PATCH v2 5/5 llvm-project-source.inc: add vardeps to do_unpack
In reply to João Marcos CostaThe do_preconfigure task performs some string replacements, and the patterns searched by sed are no longer there if they were replaced during a previous (successful) execution.
This means we need to unpack the sources again, and apply the patches, before running do_preconfigure again. Regarding do_patch, it is already handled by the addtask line. However, even if we define a dependency (e.g. with deptask flag) between do_preconfigure and do_unpack, bitbake will not reexecute do_unpack because the stamp is still there.
The only workaround I see - not so elegant, yes - is to make sure do_unpack's signature also depends on CLANG_EXTRA_OE_DISTRO and CLANG_EXTRA_OE_VENDORS.
--- meta/recipes-devtools/clang/llvm-project-source.inc | 1 + 1 file changed, 1 insertion(+)
meta/recipes-devtools/clang/llvm-project-source.inc +1 -0
@@ -91,4 +91,5 @@ python do_preconfigure() { do_patch[vardepsexclude] += "MULTILIBS MULTILIB_VARIANTS" addtask do_preconfigure after do_patch do_preconfigure[vardeps] += "CLANG_EXTRA_OE_DISTRO CLANG_EXTRA_OE_VENDORS" +do_unpack[vardeps] += "CLANG_EXTRA_OE_DISTRO CLANG_EXTRA_OE_VENDORS" do_create_spdx[depends] += "${PN}:do_preconfigure"
Signature · 1 line
2.43.0