<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>11587</bug_id>
          
          <creation_ts>2017-05-27 19:46:21 +0000</creation_ts>
          <short_desc>add &quot;fence flag&quot; to cross toolchain</short_desc>
          <delta_ts>2017-08-30 23:24:06 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>devtools / tool chain</component>
          <version>2.4</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>2.4 M3</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="brian avery">brian.avery</reporter>
          <assigned_to name="Juro Bystricky">juro.bystricky</assigned_to>
          <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>randy.macleod</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>73541</commentid>
    <comment_count>0</comment_count>
    <who name="brian avery">brian.avery</who>
    <bug_when>2017-05-27 19:46:21 +0000</bug_when>
    <thetext>Suppose we have an autotools project that looks like it is using the cross compiler but is actually reaching out to the host compiler instead. On an x86-64 build, you may not even notice.

Option: add a &quot;fence flag&quot; like --using-cross-compiler to the cross compiler we build and add it to the default flags.  host gcc will die on this, allowing us to catch cross contamination. This is also part of the binary reproducibility push.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73611</commentid>
    <comment_count>1</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-06-01 15:42:47 +0000</bug_when>
    <thetext>We already have a GCC flag in poky/oe-core that is pretty much guaranteed not to exist in the host GCC (we patch the GCC to get this functionality). So if all we want is the host GCC to barf when it is invoked by a mistake, we can use the flag ffile-prefix-map. Something like this should have no additional side effects (remapping a string into itself):

-ffile-prefix-map=string=string</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73615</commentid>
    <comment_count>2</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-06-01 15:50:17 +0000</bug_when>
    <thetext>If the overall goal is to achieve binary reproducibility, then the recipes should use the flag -file-prefix-map anyway. It allows remapping the string as specified by __FILE__ macro. The purpose is to get rid off the host build system references from __FILE__.

For example, calling GCC with :

 -ffile-prefix-map=${S}=/kernel-source/

will replace the (to be embedded) string

/​data/​master/​build-​repro/​tmp/​work-​shared/​qemux86/​kernel-​source/​drivers/​media/​v4l2-​core/​videobuf2-​core.​c
    
with a reproducible value:
    
/kernel-source/drivers/media/v4l2-core/videobuf2-core.c.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73616</commentid>
    <comment_count>3</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-06-01 15:52:04 +0000</bug_when>
    <thetext>see

http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=jurob/reproducible_binaries&amp;id=5bd62e7b2f5f61c26ea0ca679c2d4db65e376102</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73624</commentid>
    <comment_count>4</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2017-06-01 19:38:03 +0000</bug_when>
    <thetext>Since Hongxu has submitted this patch to gcc and opened a gcc bug [1] as well, the flag -ffile-prefix-map=from-string=to-string *could* show up in the version of gcc used on the host. It&apos;s not clear what will be implemented [2].

An explicit flag that is only present if the compiler was configured as a cross-compiler would be better. 

Playing devil&apos;s advocate, I&apos;ll point out that this only catches the common case of a single toolchain being installed on the host. I don&apos;t think that we can or should make this impervious to arbitrary build host configurations with, for example, additional cross-compilers available.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70268
[2] https://reproducible-builds.org/specs/build-path-prefix-map/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73631</commentid>
    <comment_count>5</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-06-01 22:23:59 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; Since Hongxu has submitted this patch to gcc and opened a gcc bug [1] as
&gt; well, the flag -ffile-prefix-map=from-string=to-string *could* show up in
&gt; the version of gcc used on the host. It&apos;s not clear what will be implemented
&gt; [2].
&gt; 
&gt; An explicit flag that is only present if the compiler was configured as a
&gt; cross-compiler would be better. 
&gt; 
&gt; Playing devil&apos;s advocate, I&apos;ll point out that this only catches the common
&gt; case of a single toolchain being installed on the host. I don&apos;t think that
&gt; we can or should make this impervious to arbitrary build host configurations
&gt; with, for example, additional cross-compilers available.
&gt; 
&gt; [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70268
&gt; [2] https://reproducible-builds.org/specs/build-path-prefix-map/

Yes, there is a non-zero possibility the host compiler supports the flag.
This can be tested by querying the gcc:

$ gcc -Q --help=joined | grep ffile-prefix-map

I suspect the patch, if accepted, will be not backported and will end up in gcc 7.x . My point was, that in order to achieve binary reproducibility (which was an implied objective here), they should have used the flag anyway. If the host gcc dies in the process, even better.

But I will come up with a gcc-cross specific/unique flag patch as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75124</commentid>
    <comment_count>6</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-07-18 22:48:05 +0000</bug_when>
    <thetext>sent a patch to the mailing list:
http://lists.openembedded.org/pipermail/openembedded-core/2017-July/139806.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75145</commentid>
    <comment_count>7</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-07-19 17:17:35 +0000</bug_when>
    <thetext>Implemented as a new warning flag in GCC &quot;Wnot-cross-compiler&quot;.

In cross-compiler it does absolutely nothing, the warning will be triggered if used not in cross-compiler. It can be used to force an error when used as host compiler:

 -Wnot-cross-compiler -Werror=not-cross-compiler 

If the host uses (unpatched) GCC, it will also generate an error:

gcc -Wnot-cross-compiler hello_world.c
gcc: error: unrecognized command line option ‘-Wnot-cross-compiler’


So far the feedback from the mailing list is not very positive, the concern
seems to be that if the host compiler is not GCC, it MAY silently ignore 
any unknown command line options.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>76369</commentid>
    <comment_count>8</comment_count>
    <who name="Juro Bystricky">juro.bystricky</who>
    <bug_when>2017-08-30 23:24:06 +0000</bug_when>
    <thetext>The patch was sent to the mailing list. It does what it is supposed to do.
The final verdict regarding inclusion has not been done yet. For now, I am closing this as RESOLVED/WORKSFORME. The ticket can be re-opened if needed.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>