Panu Matilainen 88f620
From b1c99cc21dd8dc984734cd2a66e48a5676280dee Mon Sep 17 00:00:00 2001
Panu Matilainen 88f620
Message-ID: <b1c99cc21dd8dc984734cd2a66e48a5676280dee.1692617135.git.pmatilai@redhat.com>
Panu Matilainen 88f620
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 88f620
Date: Mon, 21 Aug 2023 13:42:43 +0300
Panu Matilainen 88f620
Subject: [PATCH] Behave more consistently when target arch %optflags are not
Panu Matilainen 88f620
 defined
Panu Matilainen 88f620
Panu Matilainen 88f620
You're about to fall into a deep dark hole, proceed at your own risk.
Panu Matilainen 88f620
Panu Matilainen 88f620
When building for a target architecture with no defined %optflags
Panu Matilainen 88f620
(such as noarch), one would think that %optflags would be empty. Not so in
Panu Matilainen 88f620
rpm, instead we get %optflags for the detected architecture, and there
Panu Matilainen 88f620
are packages which rely on this behavior. And in this particular dark
Panu Matilainen 88f620
corner, buildarchtranslate is not applied so one can get drastically
Panu Matilainen 88f620
different %optflags than you'd get without an explicit --target, on the
Panu Matilainen 88f620
same system. Which can break builds.
Panu Matilainen 88f620
Panu Matilainen 88f620
None of this makes any sense whatsoever, but lets at least try to be
Panu Matilainen 88f620
consistent about it. When we fall back to detected architecture
Panu Matilainen 88f620
%optflags, at least use the ones after buildarchtranslate to return
Panu Matilainen 88f620
consistent data within a host.
Panu Matilainen 88f620
Panu Matilainen 88f620
This supposedly fixes the case where our newly added x86_64
Panu Matilainen 88f620
subarchitecture definitions haven't been overridden in vendor config and
Panu Matilainen 88f620
somebody's noarch package uses cmake to install data, and falls over due
Panu Matilainen 88f620
to nonsensical optflags from rpm. Or something like that.
Panu Matilainen 88f620
Panu Matilainen 88f620
Initial report: https://bugzilla.redhat.com/show_bug.cgi?id=2231727
Panu Matilainen 88f620
---
Panu Matilainen 88f620
 lib/rpmrc.c | 7 +++++++
Panu Matilainen 88f620
 1 file changed, 7 insertions(+)
Panu Matilainen 88f620
Panu Matilainen 88f620
diff --git a/lib/rpmrc.c b/lib/rpmrc.c
Panu Matilainen 88f620
index 8a829709b..f8a7aee8c 100644
Panu Matilainen 88f620
--- a/lib/rpmrc.c
Panu Matilainen 88f620
+++ b/lib/rpmrc.c
Panu Matilainen 88f620
@@ -1685,6 +1685,13 @@ static void rpmRebuildTargetVars(rpmrcCtx ctx,
Panu Matilainen 88f620
  * XXX Make sure that per-arch optflags is initialized correctly.
Panu Matilainen 88f620
  */
Panu Matilainen 88f620
   { const char *optflags = rpmGetVarArch(ctx, RPMVAR_OPTFLAGS, ca);
Panu Matilainen 88f620
+    /*
Panu Matilainen 88f620
+     * If not defined for the target arch, fall back to current arch
Panu Matilainen 88f620
+     * definitions, with buildarchtranslate applied.
Panu Matilainen 88f620
+     */
Panu Matilainen 88f620
+    if (optflags == NULL) {
Panu Matilainen 88f620
+	optflags = rpmGetVarArch(ctx, RPMVAR_OPTFLAGS, NULL);
Panu Matilainen 88f620
+    }
Panu Matilainen 88f620
     if (optflags != NULL) {
Panu Matilainen 88f620
 	rpmPopMacro(NULL, "optflags");
Panu Matilainen 88f620
 	rpmPushMacro(NULL, "optflags", NULL, optflags, RMIL_RPMRC);
Panu Matilainen 88f620
-- 
Panu Matilainen 88f620
2.41.0
Panu Matilainen 88f620