Skip to contentSkip to conversation

llvm/clang: fix some syntax issues in llvm-project-source

PATCH Superseded João Marcos Costa 2 participants 7 messages Jun 22 – Jun 23

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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,

João Marcos Costa (4):
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

 ...istro-instance-to-getMultiarchTriple.patch | 35 +++++++++++++++++++
 meta/recipes-devtools/clang/common.inc        |  1 +
 .../clang/llvm-project-source.inc             |  7 ++--
 3 files changed, 40 insertions(+), 3 deletions(-)
 create mode 100644 meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch
Signature · 1 line
2.47.0
#1 lore raw

PATCH 1/4 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
index ba6cbf9a8d..6540d1cc7c 100644
@@ -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.47.0
#2 lore raw

PATCH 2/4 llvm-project-source.inc: fix end of line in triple variable

In reply to João Marcos Costa

After 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
index 6540d1cc7c..85b5ef06dc 100644
@@ -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.47.0
#3 lore raw

PATCH 3/4 clang/llvm: add missing instance of Distro class in Linux.cpp

In reply to João Marcos Costa

As in the own patch's message:

This 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()},

---
 ...istro-instance-to-getMultiarchTriple.patch | 35 +++++++++++++++++++
 meta/recipes-devtools/clang/common.inc        |  1 +
 2 files changed, 36 insertions(+)
 create mode 100644 meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch
meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch new file +35 -0
new file mode 100644
index 0000000000..90dd51865b
@@ -0,0 +1,35 @@
+From ef7b8a5409c9a1789c6e6679a7e67e8cebe7ab6f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Costa?= <[email protected]>
+Date: Sun, 21 Jun 2026 17:33:10 +0000
+Subject: [PATCH] llvm/clang: Add Distro instance to getMultiarchTriple()
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This 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.
+
+Upstream-Status: Inappropriate [oe-core specific]
+
+Signed-off-by: João Marcos Costa <[email protected]>
+---
+ clang/lib/Driver/ToolChains/Linux.cpp | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
+index c6d6e20db..52c27f559 100644
+--- a/clang/lib/Driver/ToolChains/Linux.cpp
++++ b/clang/lib/Driver/ToolChains/Linux.cpp
+@@ -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.
+-- 
+2.39.5
+
meta/recipes-devtools/clang/common.inc +1 -0
index 441ea099a9..19b43d6613 100644
@@ -60,6 +60,7 @@ SRC_URI = "\
     file://0039-Rename-UNUSED-and-UNKNOWN-elements-of-OffloadArch-enum.patch \
     file://0040-libcxxabi-declare-__gnu_unwind_frame-in-cxa_personal.patch \
     file://0041-Consolidate-and-fix-sysroot-based-compiler-rt-search.patch \
+    file://0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch \
 "
 # Fallback to no-PIE if not set
 GCCPIE ??= ""
Signature · 1 line
2.47.0
#4 lore raw

Re: [PATCH 3/4] clang/llvm: add missing instance of Distro class in Linux.cpp

I wonder if this patch should be squashed
into 0016-llvm-clang-Insert-anchor-for-adding-OE-distro-vendor.patch since that patch is causing to need this change.

Quoted 94 lines · João Marcos Costa

As in the own patch's message:

This 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()},

---
 ...istro-instance-to-getMultiarchTriple.patch | 35 +++++++++++++++++++
 meta/recipes-devtools/clang/common.inc        |  1 +
 2 files changed, 36 insertions(+)
 create mode 100644

meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch

diff --git a/meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch b/meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch new file mode 100644
index 0000000000..90dd51865b
--- /dev/null
+++
b/meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch

(quoted diff) +2 -0
@@ -0,0 +1,35 @@
+From ef7b8a5409c9a1789c6e6679a7e67e8cebe7ab6f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Costa?= <

[email protected]>

meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch new file +10 -0
+Date: Sun, 21 Jun 2026 17:33:10 +0000
+Subject: [PATCH] llvm/clang: Add Distro instance to getMultiarchTriple()
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This 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.

meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch new file +9 -0
+
+Upstream-Status: Inappropriate [oe-core specific]
+
+Signed-off-by: João Marcos Costa <[email protected]>
+---
+ clang/lib/Driver/ToolChains/Linux.cpp | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/clang/lib/Driver/ToolChains/Linux.cpp

b/clang/lib/Driver/ToolChains/Linux.cpp

meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch new file +6 -0
+index c6d6e20db..52c27f559 100644
+--- a/clang/lib/Driver/ToolChains/Linux.cpp
++++ b/clang/lib/Driver/ToolChains/Linux.cpp
+@@ -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);

(quoted diff) +2 -0
+
+   // For most architectures, just use whatever we have rather than

trying to be

meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch new file +4 -0
+   // clever.
+--
+2.39.5
+
meta/recipes-devtools/clang/common.inc +1 -0
index 441ea099a9..19b43d6613 100644
@@ -60,6 +60,7 @@ SRC_URI = "\
 
 file://0039-Rename-UNUSED-and-UNKNOWN-elements-of-OffloadArch-enum.patch \
 
 file://0040-libcxxabi-declare-__gnu_unwind_frame-in-cxa_personal.patch \
 
 file://0041-Consolidate-and-fix-sysroot-based-compiler-rt-search.patch \
+

file://0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch \
"
# Fallback to no-PIE if not set
GCCPIE ??= ""
--
2.47.0

#5 lore raw

PATCH 4/4 llvm-project-source.inc: add vardeps to do_preconfigure

In reply to João Marcos Costa

The 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
index 85b5ef06dc..84d4bae0ab 100644
@@ -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.47.0
#6 lore raw
In reply to João Marcos Costa

Thanks João, the patchset looks solid, I have one comment if you can address that we are good to go

Quoted 53 lines · João Marcos Costa

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,

João Marcos Costa (4):
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

 ...istro-instance-to-getMultiarchTriple.patch | 35 +++++++++++++++++++
 meta/recipes-devtools/clang/common.inc        |  1 +
 .../clang/llvm-project-source.inc             |  7 ++--
 3 files changed, 40 insertions(+), 3 deletions(-)
 create mode 100644

meta/recipes-devtools/clang/clang/0001-llvm-clang-Add-Distro-instance-to-getMultiarchTriple.patch

--
2.47.0