Skip to contentSkip to conversation

oeqa/poisoning: fix gcc include poisoning test

PATCH In review Ross Burton 2 participants 5 messages Jan 21, 2025 – Jan 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 oeqa/poisoning: fix gcc include poisoning test

The test code in poison was flawed: as long as one CPP/CC/CXX has fatal poisoning enabled then the test passes. However, at the moment due to a bad rebase only CPP has fatal poisoning and CC/CXX do not.

Rewrite the do_compile() task to more carefully check the output so the test harness itself just has to bitbake the recipe.

Note that this results in the test failing:

ERROR: poison-1.0-r0 do_compile: C Compiler is not poisoned.
Exit status 0, output: cc1: warning: include location "/usr/include" is unsafe for cross-compilation [-Wpoison-system-directories]
ERROR: poison-1.0-r0 do_compile: C++ Compiler is not poisoned.
Exit status 0, output: cc1plus: warning: include location "/usr/include" is unsafe for cross-compilation [-Wpoison-system-directories]

---
 meta-selftest/recipes-test/poison/poison.bb  | 26 ++++++++++++++------
 meta/lib/oeqa/selftest/cases/buildoptions.py |  5 ++--
 2 files changed, 21 insertions(+), 10 deletions(-)
meta-selftest/recipes-test/poison/poison.bb +19 -7
index e9eee0cdbab..771113acf32 100644
@@ -8,13 +8,25 @@ inherit nopackages
 # This test confirms that compiling code that searches /usr/include for headers
 # will result in compiler errors.  This recipe should will fail to build and
 # oe-selftest has a test that verifies that.
-do_compile() {
-    bbnote Testing preprocessor
-    echo "int main(int argc, char** argv) {}" | ${CPP} -I/usr/include -
-    bbnote Testing C compiler
-    echo "int main(int argc, char** argv) {}" | ${CC} -x c -I/usr/include -
-    bbnote Testing C++ compiler
-    echo "int main(int argc, char** argv) {}" | ${CC} -x c++ -I/usr/include -
+python do_compile() {
+    import subprocess
+
+    tests = {
+        "Preprocessor": "${CPP} -I/usr/include -",
+        "C Compiler": "${CC} -I/usr/include -x c -",
+        "C++ Compiler": "${CXX} -I/usr/include -x c++ -",
+    }
+
+    for name, cmd in tests.items():
+        cmd = d.expand(cmd)
+        bb.note("Test command: " + cmd)
+        testcode = "int main(int argc, char** argv) {}"
+        proc = subprocess.run(cmd, shell=True, input=testcode, capture_output=True, text=True)
+
+        if proc.returncode != 0 and "is unsafe for cross-compilation" in proc.stderr:
+            bb.note(f"{name} passed: {proc.stderr}")
+        else:
+            bb.error(f"{name} is not poisoned. Exit status {proc.returncode}, output: {proc.stdout} {proc.stderr}")
 }
 
 EXCLUDE_FROM_WORLD = "1"
meta/lib/oeqa/selftest/cases/buildoptions.py +2 -3
index 09272314bb8..b509bcf951c 100644
@@ -234,6 +234,5 @@ PREMIRRORS = "\\
 
 class Poisoning(OESelftestTestCase):
     def test_poisoning(self):
-        res = bitbake("poison", ignore_status=True)
-        self.assertNotEqual(res.status, 0)
-        self.assertTrue("is unsafe for cross-compilation" in res.output)
+        # The poison recipe fails if the poisoning didn't work
+        bitbake("poison")
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 gcc: make include poisoning fatal again in gcc/g++

We have a patch to allow us to 'poison' system include directories, which are warnings by default but we make them fatal in cross builds.

However, in the 13.1 upgrade[1] the patch to make the warnings fatal was dropped in the compiler invocation, so it only took effect for pure preprocessor calls. This was not noticed at the time as the test case was flawed, but this has now been fixed.

Add back the fatal poisoning, and restructure the patch slightly so it is less invasive.

[1] oe-core bea46612fd9106cc5b46eb1d81623b6492563c13

---
 .../0002-gcc-poison-system-directories.patch  | 35 +++++++++++++------
 1 file changed, 25 insertions(+), 10 deletions(-)
meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch +25 -10
index 367c9e3821b..d8b3d4a9984 100644
@@ -160,10 +160,21 @@ index f82f7d2817b..1da91813b0e 100644
  @opindex Wno-float-equal
  @item -Wfloat-equal
 diff --git a/gcc/gcc.cc b/gcc/gcc.cc
-index 728332b8153..343e4915097 100644
+index 728332b8153..a63f128cb95 100644
 --- a/gcc/gcc.cc
 +++ b/gcc/gcc.cc
-@@ -1159,6 +1159,8 @@ proper position among the other output files.  */
+@@ -902,6 +902,10 @@ proper position among the other output files.  */
+ #define ASM_MAP ""
+ #endif
+ 
++#ifdef POISON_BY_DEFAULT
++#define POISON_IS_ERROR " -Werror=poison-system-directories"
++#endif
++
+ /* Assembler options for compressed debug sections.  */
+ #if HAVE_LD_COMPRESS_DEBUG == 0
+ /* Reject if the linker cannot write compressed debug sections.  */
+@@ -1159,6 +1163,8 @@ proper position among the other output files.  */
     "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
     "%X %{o*} %{e*} %{N} %{n} %{r}\
      %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
@@ -172,20 +183,24 @@ index 728332b8153..343e4915097 100644
      %{static|no-pie|static-pie:} %@{L*} %(link_libgcc) " \
      VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \
      %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
-@@ -1260,8 +1262,11 @@ static const char *cpp_unique_options =
- static const char *cpp_options =
+@@ -1261,7 +1267,7 @@ static const char *cpp_options =
  "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
   %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\
-- %{!fno-working-directory:-fworking-directory}}} %{O*}\
+  %{!fno-working-directory:-fworking-directory}}} %{O*}\
 - %{undef} %{save-temps*:-fpch-preprocess}";
-+ %{!fno-working-directory:-fworking-directory}}} %{O*}"
-+#ifdef POISON_BY_DEFAULT
-+ " -Werror=poison-system-directories"
-+#endif
-+ " %{undef} %{save-temps*:-fpch-preprocess}";
++ %{undef} %{save-temps*:-fpch-preprocess}" POISON_IS_ERROR;
  
  /* Pass -d* flags, possibly modifying -dumpdir, -dumpbase et al.
  
+@@ -1290,7 +1296,7 @@ static const char *cc1_options =
+  %{coverage:-fprofile-arcs -ftest-coverage}\
+  %{fprofile-arcs|fcondition-coverage|fprofile-generate*|coverage:\
+    %{!fprofile-update=single:\
+-     %{pthread:-fprofile-update=prefer-atomic}}}";
++     %{pthread:-fprofile-update=prefer-atomic}}}" POISON_IS_ERROR;
+ 
+ static const char *asm_options =
+ "%{-target-help:%:print-asm-header()} "
 diff --git a/gcc/incpath.cc b/gcc/incpath.cc
 index 64cdd2f4a..89f42900d 100644
 --- a/gcc/incpath.cc
Signature · 1 line
2.43.0
#2 lore raw

Re: [OE-core] [PATCH 2/2] gcc: make include poisoning fatal again in gcc/g++

Quoted 11 lines · Ross Burton via lists.openembedded.org

We have a patch to allow us to 'poison' system include directories, which are warnings by default but we make them fatal in cross builds.

However, in the 13.1 upgrade[1] the patch to make the warnings fatal was dropped in the compiler invocation, so it only took effect for pure preprocessor calls. This was not noticed at the time as the test case was flawed, but this has now been fixed.

Add back the fatal poisoning, and restructure the patch slightly so it is less invasive.

Quoted 6 lines

[1] oe-core bea46612fd9106cc5b46eb1d81623b6492563c13

---
 .../0002-gcc-poison-system-directories.patch  | 35 +++++++++++++------

 1 file changed, 25 insertions(+), 10 deletions(-)

Sadly this causes a ton of failures:

https://autobuilder.yoctoproject.org/valkyrie/#/builders/29/builds/857

The patch is right but we're going to have to dig in and clean up the issues before it can merge.

Cheers,

Richard

#3 lore raw

Re: [OE-core] [PATCH 2/2] gcc: make include poisoning fatal again in gcc/g++

In reply to Ross Burton
Quoted 31 lines · Ross Burton via lists.openembedded.org

We have a patch to allow us to 'poison' system include directories, which are warnings by default but we make them fatal in cross builds.

However, in the 13.1 upgrade[1] the patch to make the warnings fatal was dropped in the compiler invocation, so it only took effect for pure preprocessor calls. This was not noticed at the time as the test case was flawed, but this has now been fixed.

Add back the fatal poisoning, and restructure the patch slightly so it is less invasive.

[1] oe-core bea46612fd9106cc5b46eb1d81623b6492563c13

---
 .../0002-gcc-poison-system-directories.patch  | 35 +++++++++++++------

 1 file changed, 25 insertions(+), 10 deletions(-)
meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch +0 -0
index 367c9e3821b..d8b3d4a9984 100644
@@ -160,10 +160,21 @@ index f82f7d2817b..1da91813b0e 100644

  @opindex Wno-float-equal
  @item -Wfloat-equal
 diff --git a/gcc/gcc.cc b/gcc/gcc.cc

meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch +1 -1
-index 728332b8153..343e4915097 100644
+index 728332b8153..a63f128cb95 100644

 --- a/gcc/gcc.cc
 +++ b/gcc/gcc.cc
-@@ -1159,6 +1159,8 @@ proper position among the other output files.  */

Quoted 8 lines

+@@ -902,6 +902,10 @@ proper position among the other output files.  */
+ #define ASM_MAP ""
+ #endif
+
++#ifdef POISON_BY_DEFAULT
++#define POISON_IS_ERROR " -Werror=poison-system-directories" ++#endif
++

I think this needs to be:

+#ifdef POISON_BY_DEFAULT
+#define POISON_IS_ERROR " -Werror=poison-system-directories" +#else
+#define POISON_IS_ERROR
+#endif

otherwwise POISON_IS_ERROR is undefined and leads to failures building target gcc and gcc-cross-canadian. Fixup in -next I can squash in if you agree.

Cheers,

Richard

#4 lore raw

Re: [OE-core] [PATCH 2/2] gcc: make include poisoning fatal again in gcc/g++

Quoted 11 lines · Richard Purdie

I think this needs to be:

(quoted diff) +5 -0
+#ifdef POISON_BY_DEFAULT
+#define POISON_IS_ERROR " -Werror=poison-system-directories"
+#else
+#define POISON_IS_ERROR
+#endif

otherwwise POISON_IS_ERROR is undefined and leads to failures building target gcc and gcc-cross-canadian. Fixup in -next I can squash in if you agree.

Please do. Apologies, my C is rustier than I thought. :(

Ross