Openembedded Devel Discussions
 help / color / mirror / Atom feed
From: "André Draszik" <git@andred.net>
To: openembedded-devel@lists.openembedded.org
Subject: [meta-java][PATCH 4/9] openjdk-8: fix infrastructure for version host gcc != cross gcc (again)
Date: Mon, 13 Aug 2018 11:09:31 +0100	[thread overview]
Message-ID: <20180813100936.23663-5-git@andred.net> (raw)
In-Reply-To: <20180813100936.23663-1-git@andred.net>

From: André Draszik <andre.draszik@jci.com>

Building OpenJDK-8 (target) with an older host compiler (gcc < 6) does
not work as the build errors with error messages regarding unrecognized
gcc command line options.

As part of the (cross) build particularly, OpenJDK-8 builds a host tool
(adlc) using the host gcc. We have a patch, openjdk8-fix-adlc-flags.patch,
that tries to make the adlc build use the correct / intended compiler
flags.

This doesn't work right now, as that build still sees compiler flags
intended for / understood by the gcc version used for the actual cross
compile only.

The reason is that while we have infrastructure in place to add compiler
flags based on the compiler version, we add all of them unconditionally to
CFLAGS / CXXFLAGS directly but above patch uses TARGET_CFLAGS /
TARGET_CXXFLAGS to  filter out unwanted BUILD_CFLAGS / BUILD_CXXFLAGS from
CFLAGS / CXXFLAGS, In other words above patch cannot do what it intends to
do and all compiler version specific flags (-fno-lifetime-dse &
-fno-delete-null-pointer-checks) end up in CFLAGS / CXXFLAGS.

So far, this was only affecting people using host gcc < 6, but upcoming
patches adding support for gcc >= 8 will add even more compiler flags that
even gcc < 7 don't support - it's time to finally address this.

We fix the issue by adding the compiler version specific flags to
BUILD_CFLAGS / BUILD_CXXFLAGS and TARGET_CFLAGS / TARGET_CXXFLAGS as
necessary, so that above patch can work as intended.

We now support all necessary combinations:
* -native builds
* -target builds
* host tools built using the native compiler during the -target build

A similar but different patch existed here before as
commit 6801f6d4e19c ("openjdk-8-common: Fix the issue of building
failed adlc on host with gcc < 6") but was reverted subsequently
due to reportedly still(?) having (new?) issues with older compilers.
This patch here is different from the older patch in that it
*doesn't* set the cflags during a python_anonymous() function, and
thus it guarantees deterministic execution order.

This change here was tested to work using host gcc versions 4.8.4 and
6.3.0 and 7.3.0

Signed-off-by: André Draszik <andre.draszik@jci.com>
---
 recipes-core/openjdk/openjdk-8-common.inc     | 55 +++++++++++--------
 .../openjdk/openjdk-8-release-16xbyy.inc      |  3 +-
 2 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/recipes-core/openjdk/openjdk-8-common.inc b/recipes-core/openjdk/openjdk-8-common.inc
index 4e52448..fb97e97 100644
--- a/recipes-core/openjdk/openjdk-8-common.inc
+++ b/recipes-core/openjdk/openjdk-8-common.inc
@@ -224,32 +224,39 @@ FLAGS_GCC7 = "-fno-lifetime-dse -fno-delete-null-pointer-checks"
 # version is and only add the flags that are appropriate for that GCC
 # version.
 
-def version_specific_cflags(d):
-    import re
-
-    extraflags = None
-    version = None
+def get_cflags_by_cc_version(d, version):
+    if version.isdigit():
+        return d.getVar('FLAGS_GCC%d' % int(version)) or ''
+    return ''
 
-    if bb.data.inherits_class('native', d):
+def get_build_cflags(d):
+    def get_build_cc_version(build_cc):
         from subprocess import Popen, PIPE
-
-        cmd = d.expand('${CC} -dumpversion').split()
+        cmd = d.expand('%s -dumpversion' % build_cc).split()
         cc = Popen(cmd, stdout=PIPE, stderr=PIPE)
-        version = cc.communicate()[0].decode('utf-8')[0]
-    else:
-        # in the cross case, trust that GCCVERSION is correct. This won't
-        # work if the native toolchain is Clang, but as of this writing that
-        # doesn't work anyway.
-        version = d.getVar('GCCVERSION', expand=True)[0]
-        # skip non digit characters at the beginning, e.g. from "linaro-6.2%"
-        match = re.search("\d", version)
-        if match:
-            version = version[match.start():]
+        return cc.communicate()[0].decode('utf-8')[0]
 
-    if version.isdigit():
-        extraflags = d.getVar('FLAGS_GCC%d' % int(version), True) or ''
-        return extraflags
-    return ''
+    build_cc = d.getVar('BUILD_CC')
+    version = get_build_cc_version(build_cc)
+    return get_cflags_by_cc_version(d, version)
+
+def get_target_cflags(d):
+    import re
 
-CFLAGS_append = " ${@version_specific_cflags(d)}"
-CXXFLAGS_append = " ${@version_specific_cflags(d)}"
+    # in the cross case, trust that GCCVERSION is correct. This won't
+    # work if the native toolchain is Clang, but as of this writing that
+    # doesn't work anyway.
+    version = d.getVar('GCCVERSION')[0]
+    # skip non digit characters at the beginning, e.g. from "linaro-6.2%"
+    match = re.search("\d", version)
+    if match:
+        version = version[match.start():]
+    return get_cflags_by_cc_version(d, version)
+
+
+# flags for -native, and for bits that need a host-tool during -cross
+BUILD_CFLAGS_append = " ${@get_build_cflags(d)}"
+BUILD_CXXFLAGS_append = " ${@get_build_cflags(d)}"
+# flags for -cross
+TARGET_CFLAGS_append = " ${@get_target_cflags(d)}"
+TARGET_CXXFLAGS_append = " ${@get_target_cflags(d)}"
diff --git a/recipes-core/openjdk/openjdk-8-release-16xbyy.inc b/recipes-core/openjdk/openjdk-8-release-16xbyy.inc
index fd95e95..36ce073 100644
--- a/recipes-core/openjdk/openjdk-8-release-16xbyy.inc
+++ b/recipes-core/openjdk/openjdk-8-release-16xbyy.inc
@@ -54,7 +54,8 @@ ARM_INSTRUCTION_SET_armv4t = "ARM"
 
 # readdir_r was deprecated in glibc-2.24. Ignore the error for now
 # NOTE: When updating the recipe, please check if this is still needed
-CFLAGS_append = " -Wno-error=deprecated-declarations"
+BUILD_CFLAGS_append = " -Wno-error=deprecated-declarations"
+TARGET_CFLAGS_append = " -Wno-error=deprecated-declarations"
 
 # Enable zero mode for arm based builds, as normal hotspot fails to build
 PACKAGECONFIG_append_arm = " zero"
-- 
2.18.0



  parent reply	other threads:[~2018-08-13 10:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-13 10:09 [meta-java] OpenJDK-8 fixes and updates André Draszik
2018-08-13 10:09 ` [meta-java][PATCH 1/9] gitignore: ignore new python byte-code files André Draszik
2018-08-13 10:09 ` [meta-java][PATCH 2/9] openjdk-8: speed-up do_install() (pack200) André Draszik
2018-08-13 10:09 ` [meta-java][PATCH 3/9] openjdk-8: remove superfluous compiler flag (-std=gnu++98) André Draszik
2018-08-13 10:09 ` André Draszik [this message]
2018-08-13 13:53   ` [meta-java][PATCH 4/9] openjdk-8: fix infrastructure for version host gcc != cross gcc (again) Richard Leitner
2018-08-13 10:09 ` [meta-java][PATCH 5/9] openjdk-8: gcc-8 fix #1: backport patch to fix misuses of strncpy/strncat André Draszik
2018-08-13 10:09 ` [meta-java][PATCH 6/9] openjdk-8: gcc-8 fix #2: silence build warnings/errors (return-type) André Draszik
2018-08-13 13:03   ` Richard Leitner
2018-08-13 14:25     ` André Draszik
2018-08-13 10:09 ` [meta-java][PATCH 7/9] Revert "openjdk-8: fix build for gcc8.x" André Draszik
2018-08-13 10:09 ` [meta-java][PATCH 8/9] openjdk-8: gcc-8 fix #3: working binaries André Draszik
2018-08-13 10:09 ` [meta-java][PATCH 9/9] openjdk-8: update to 8u172b11 André Draszik
2018-08-13 10:41 ` [meta-java] OpenJDK-8 fixes and updates Richard Leitner
2018-08-13 14:53 ` Richard Leitner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180813100936.23663-5-git@andred.net \
    --to=git@andred.net \
    --cc=openembedded-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox