Bug 11769

Summary: SDK environment-setup CXXFLAGS wrong
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Juro Bystricky <juro.bystricky>
Component: devtools / tool chainAssignee: Rebecca Chang <rebecca.swee.fun.chang>
Status: VERIFIED FIXED QA Contact: nagarajagopal <nagarajagopalx.velu>
Severity: normal    
Priority: Medium CC: brian.avery, ee.peng.yeoh, meta.mr.watcher, meta.watcher, sgw, shashwatx.pandey
Version: 2.4   
Target Milestone: 2.4 M4   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: Regression (Used to work)
Verified: Documentation change: No (bug/feature does not impact docs)

Description Juro Bystricky 2017-07-06 18:20:25 UTC
I just built an SDK:

$ bitbake core-image-minimal -cpopulate_sdk


The SDK environment file contains this:

export CXXFLAGS="${BUILDSDK_CXXFLAGS}"

This does not seem right. There is no definition of BUILDSDK_CXXFLAGS anywhere.
FWIW bitbake.conf has definitions for BUILDSDK_CPPFLAGS, BUILDSDK_CFLAGS but no definition for BUILDSDK_CXXFLAGS.

I filed this as a regression, as in the past I got:

export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types "

(Same as CFLAGS)

The version info is :
Distro: poky
Distro Version: 2.3
Metadata Revision: 754c03006943a219ffd417c36ab909b464f57f67
Timestamp: 20170706170246
Comment 1 brian avery 2017-07-13 14:44:01 UTC
as part of fixing this, could we add a sdk test for all the sdk variables to make sure they expand to something?  There's already a couple of sdk tests so extending them is not too bad.
Comment 2 Rebecca Chang 2017-08-18 03:14:24 UTC
(In reply to comment #0)
> I filed this as a regression, as in the past I got:
> 
> export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types "
> 
> (Same as CFLAGS)
> 
> The version info is :
> Distro: poky
> Distro Version: 2.3
> Metadata Revision: 754c03006943a219ffd417c36ab909b464f57f67
> Timestamp: 20170706170246

Hi Juro,
I have checkout to Metadata Revision: 754c03006943a219ffd417c36ab909b464f57f67 and tried to build a sdk from the revision mentioned above.
But I'm still getting no definition for CXXFLAGS:
export CXXFLAGS="${BUILDSDK_CXXFLAGS}"

So I suspect it might have been broken even earlier.
Comment 3 Juro Bystricky 2017-08-18 16:03:58 UTC
I checked some older SDKs installed on my machine, so this one is OK (buid with MACHINE="qemuarm":

Distro: poky
Distro Version: 2.2+snapshot-20170225
Metadata Revision: 3c83b56309ab419f8cda72c0711479f60f61439a
Timestamp: 20170225001909

It has:
export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types "

Then I have one:
Distro: poky
Distro Version: 2.3
Metadata Revision: f2b91c6e00c5a6de8ef0ac51f9f07e53d1ca9d43
Timestamp: 20170504192226

which is broken (I did not notice this at the time):
export CXXFLAGS="${BUILDSDK_CXXFLAGS}"

I also checked the official yocto releases:
http://downloads.yoctoproject.org/releases/yocto/

Distro: poky
Distro Version: 2.3.1
Metadata Revision: c2ef32ae58737463cf19aab7446d6a30ad81754f
Timestamp: 20170712013505

and the bug is there as well, so it is in 2.3

Distro: poky
Distro Version: 2.3
Metadata Revision: 381897c64069ea43d595380a3ae913bcc79cf7e1
Timestamp: 20170501163737
export CXXFLAGS="${BUILDSDK_CXXFLAGS}"


This one (2.2.1) is OK:
Distro: poky
Distro Version: 2.2.1
Metadata Revision: 6a1f33cc40bfac33cf030fe41e1a8efd1e5fad6f
Timestamp: 20170208201852
export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types "


I only randomly checked some SDKs (extended & standard), but I think it is fairly safe to state that 2.2 is OK and 2.3 is broken.
Comment 4 Rebecca Chang 2017-08-21 07:11:16 UTC
(In reply to comment #3)
> I only randomly checked some SDKs (extended & standard), but I think it is
> fairly safe to state that 2.2 is OK and 2.3 is broken.

Thanks Juro, I was also building a few SDK on the major milestone tags to check.
Given that you have narrow down to between 2.2 and 2.3, I will start bisecting from here.
Comment 5 Rebecca Chang 2017-08-22 08:33:55 UTC
Git bisecting went bad from commit 863b6d4f80869b0388fd9ef5c0ead38993c3b2b5
(cross-canadian.bbclass: override TARGET_* flags).

CXXFLAGS in SDK environment file is not set correctly at this point.

I did a grep on Poky, BUILDSDK_* flags was set in both:
meta/classes/cross-canadian.bbclass:TARGET_CXXFLAGS = "${BUILDSDK_CXXFLAGS}"
meta/classes/nativesdk.bbclass:TARGET_CXXFLAGS = "${BUILDSDK_CXXFLAGS}"

I think this is how BUILDSDK_CXXFLAGS came about and we are lack of definition of BUILDSDK_CXXFLAGS in bitbake.conf.

I'm proposing adding definition to BUILDSDK_CXXFLAGS in bitbake.conf.

diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 3110b9c..8ce6c9f 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -542,6 +542,7 @@ export CFLAGS = "${TARGET_CFLAGS}"
 export TARGET_CFLAGS = "${TARGET_CPPFLAGS} ${SELECTED_OPTIMIZATION}"
 
 export BUILD_CXXFLAGS = "${BUILD_CFLAGS}"
+BUILDSDK_CXXFLAGS = "${BUILDSDK_CFLAGS}"
 export CXXFLAGS = "${TARGET_CXXFLAGS}"
 export TARGET_CXXFLAGS = "${TARGET_CFLAGS}"

By referring to BUILDSDK_CFLAGS, it has a definition in bitbake.conf.
This is how I came about adding a definition for BUILDSDK_CXXFLAGS.

Any comments?
Comment 6 Rebecca Chang 2017-08-30 05:15:59 UTC
Submitted patch to mailing list for review.

http://lists.openembedded.org/pipermail/openembedded-core/2017-August/141587.html
Comment 7 Rebecca Chang 2017-09-04 00:18:30 UTC
OE-Core rev: 073ca1cbd1b70d5b36618584a8c88cbba391a259
Comment 8 nagarajagopal 2017-10-12 06:45:09 UTC
Verification logs:

1) Checkout to master branch

2) Check SDK toolchain installed in machine. 

3) Check environment setup file configured as " export CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types "

4) Crosscheck "export CFLAGS" and "export CXXFLAGS" configure should be same.

5) Below find build configuration,

Build Configuration:
BB_VERSION        = "1.35.0"
BUILD_SYS         = "x86_64-linux"
NATIVELSBSTRING   = "universal"
TARGET_SYS        = "i586-poky-linux"
MACHINE           = "qemux86"
DISTRO            = "poky"
DISTRO_VERSION    = "2.4"
TUNE_FEATURES     = "m32 i586"
TARGET_FPU        = ""

6) compile the test CPP file and should compile without error.
Comment 9 nagarajagopal 2017-10-24 01:17:09 UTC
  Verification log ,
  
   clone poky
   source oe-init-build-env
   bitbake core-image-minimal -cpopulate_sdk
   Install SDK
   setup source the SDK environment,
   . /home/raj/SDK_test_cpp/environment-setup-i586-poky-linux
   compile test CPP code,
   ${CXX} ${CXXFLAGS} testplus.cpp -o test
   It should pass all the time.
Comment 10 Shashwat Pandey 2017-11-09 07:11:11 UTC
Verified, issue is fixed.