Boost C++ Libraries: Ticket #10505: Use gcc/clang built-in endianity macros (too) https://svn.boost.org/trac10/ticket/10505 <p> Endian detection in <code>boost/predef/other/endian.h</code> does consider the gcc/clang built-in <code>__BYTE_ORDER__</code> macros and consequently fails to detect endianity of some (usually mobile) platforms. </p> <p> E.g. on Android I get <code>_BYTE_ORDER</code> defined to <code>_LITTLE_ENDIAN</code>, but <code>_LITTLE_ENDIAN</code> is <strong>not</strong> defined, leading to all three conditions (<code>_BYTE_ORDER == _BIG_ENDIAN</code>, <code>_BYTE_ORDER == _LITTLE_ENDIAN</code> and <code>_BYTE_ORDER == _PDP_ENDIAN</code> being satisfied and yielding conflicting definitions. </p> <p> The <code>__BYTE_ORDER__</code> is provided by gcc and clang compilers themselves and therefore should always be there no matter how broken the rest of standard library is. What I am not sure is whether they should be used in preference to any other method or as a fallback (in which case definedness of the <code>_BIG_ENDIAN</code>, <code>_LITTLE_ENDIAN</code> etc. macros also has to be tested before trying to use them) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10505 Trac 1.4.3 Jan Hudec <bulb@…> Mon, 15 Sep 2014 10:22:23 GMT <link>https://svn.boost.org/trac10/ticket/10505#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10505#comment:1</guid> <description> <p> I was looking wrong. Apparently it does fall back to those macros, but because the preceding code does not check that the complete suite of macros (not just <code>_BYTE_ORDER</code>, but also <code>_BIG_ENDIAN</code>/<code>_LITTLE_ENDIAN</code>/<code>_PDP_ENDIAN</code>), it is never used. </p> </description> <category>Ticket</category> </item> <item> <author>Jan Hudec <bulb@…></author> <pubDate>Mon, 15 Sep 2014 10:26:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10505#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10505#comment:2</guid> <description> <p> Ah, and the code using the built-in macros is the same as I had to patch in the earlier versions anyway as it still does not use <code>__BYTE_ORDER__</code> anyway. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>René Rivera</dc:creator> <pubDate>Tue, 30 Dec 2014 05:28:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10505#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10505#comment:3</guid> <description> <p> I don't understand what you are saying in the comments. What is the root of the problem? Can you check the current develop branch to see if addresses the issues? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>René Rivera</dc:creator> <pubDate>Tue, 30 Dec 2014 05:28:42 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/10505#comment:4 https://svn.boost.org/trac10/ticket/10505#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket René Rivera Mon, 18 May 2015 15:56:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10505#comment:5 https://svn.boost.org/trac10/ticket/10505#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">obsolete</span> </li> </ul> <p> Closing for lack of followup. </p> Ticket anonymous Mon, 18 May 2015 20:13:13 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/10505#comment:6 https://svn.boost.org/trac10/ticket/10505#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">obsolete</span> </li> </ul> <p> The current version fixes the part of the problem that the checks on in <code>endian.h</code> lines 72-99 now won't trigger in the errorneous Bionic libc case when <code>_BYTE_ORDER</code> is defined, but <code>_LITTLE_ENDIAN</code> is not. </p> <p> However, the gcc 4.6 toolchain (which we still need, because binaries built with newer ones don't work on Android &lt; 2.3 and our code otherwise works on 2.1 just fine) does <em>not</em> define <code>__LITTLE_ENDIAN__</code>, so the fallbacks further down on lines 106 and 124 don't trigger on x86 (on arm the <code>__ARMEL__</code> define is found). </p> <p> So I would still suggest adding the test for the older gcc macros: </p> <pre class="wiki">#if defined(__BYTE_ORDER__) &amp;&amp; defined(__ORDER_BIG_ENDIAN__) &amp;&amp; \ defined(__ORDER_LITTLE_ENDIAN__) &amp;&amp; defined(__ORDER_PDP_ENDIAN__) # if (__BYTE_ORDER == __ORDER_BIG_ENDIAN__) # undef BOOST_ENDIAN_BIG_BYTE # define BOOST_ENDIAN_BIG_BYTE BOOST_VERSION_NUMBER_AVAILABLE # endif # if (__BYTE_ORDER == __ORDER_LITTLE_ENDIAN__) # undef BOOST_ENDIAN_LITTLE_BYTE # define BOOST_ENDIAN_LITTLE_BYTE BOOST_VERSION_NUMBER_AVAILABLE # endif # if (__BYTE_ORDER == __ORDER_PDP_ENDIAN__) # undef BOOST_ENDIAN_LITTLE_WORD # define BOOST_ENDIAN_LITTLE_WORD BOOST_VERSION_NUMBER_AVAILABLE # endif #endif </pre><p> Since things depend on these in the gcc-provided headers, they should be reliable in gcc and clang. </p> <p> Sorry, I missed the question on new year's eve. </p> <p> PS: I wanted to make the line references to github, but trac won't accept it. </p> Ticket René Rivera Thu, 02 Jul 2015 21:27:39 GMT <link>https://svn.boost.org/trac10/ticket/10505#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10505#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10505#comment:6" title="Comment 6">anonymous</a>: </p> <blockquote class="citation"> <p> The current version fixes the part of the problem that the checks on in <code>endian.h</code> lines 72-99 now won't trigger in the errorneous Bionic libc case when <code>_BYTE_ORDER</code> is defined, but <code>_LITTLE_ENDIAN</code> is not. </p> <p> However, the gcc 4.6 toolchain (which we still need, because binaries built with newer ones don't work on Android &lt; 2.3 and our code otherwise works on 2.1 just fine) does <em>not</em> define <code>__LITTLE_ENDIAN__</code>, so the fallbacks further down on lines 106 and 124 don't trigger on x86 (on arm the <code>__ARMEL__</code> define is found). </p> <p> So I would still suggest adding the test for the older gcc macros: </p> <pre class="wiki">#if defined(__BYTE_ORDER__) &amp;&amp; defined(__ORDER_BIG_ENDIAN__) &amp;&amp; \ defined(__ORDER_LITTLE_ENDIAN__) &amp;&amp; defined(__ORDER_PDP_ENDIAN__) # if (__BYTE_ORDER == __ORDER_BIG_ENDIAN__) # undef BOOST_ENDIAN_BIG_BYTE # define BOOST_ENDIAN_BIG_BYTE BOOST_VERSION_NUMBER_AVAILABLE # endif # if (__BYTE_ORDER == __ORDER_LITTLE_ENDIAN__) # undef BOOST_ENDIAN_LITTLE_BYTE # define BOOST_ENDIAN_LITTLE_BYTE BOOST_VERSION_NUMBER_AVAILABLE # endif # if (__BYTE_ORDER == __ORDER_PDP_ENDIAN__) # undef BOOST_ENDIAN_LITTLE_WORD # define BOOST_ENDIAN_LITTLE_WORD BOOST_VERSION_NUMBER_AVAILABLE # endif #endif </pre><p> Since things depend on these in the gcc-provided headers, they should be reliable in gcc and clang. </p> <p> Sorry, I missed the question on new year's eve. </p> <p> PS: I wanted to make the line references to github, but trac won't accept it. </p> </blockquote> <p> I still how your code above works. You are checking for <code>defined(__BYTE_ORDER__)</code>. But are actually checking for <code>__BYTE_ORDER</code> equality to the <code>__ORDER_*</code> macros. Is the whole thing supposed to be a third alternative in the GNU libc branch? As in <code>__BYTE_ORDER__</code> should get used if neither <code>__BYTE_ORDER</code> nor <code>_BYTE_ORDER</code> are defined? </p> </description> <category>Ticket</category> </item> <item> <author>Jan Hudec <bulb@…></author> <pubDate>Wed, 15 Jul 2015 17:18:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10505#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10505#comment:8</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10505#comment:7" title="Comment 7">grafik</a>: </p> <blockquote class="citation"> <p> I still how your code above works. You are checking for <code>defined(__BYTE_ORDER__)</code>. But are actually checking for <code>__BYTE_ORDER</code> equality to the <code>__ORDER_*</code> macros. Is the whole thing supposed to be a third alternative in the GNU libc branch? As in <code>__BYTE_ORDER__</code> should get used if neither <code>__BYTE_ORDER</code> nor <code>_BYTE_ORDER</code> are defined? </p> </blockquote> <p> Yes, exactly, it's a third alternative. It is exactly analogous to the first two, but its advantage is that it is built into (sufficiently recent versions of) the gcc and clang compilers themselves, so it works even on systems that don't define the <code>_BYTE_ORDER</code> and <code>__BYTE_ORDER</code> or don't define them completely as is the case of Android. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>James E. King, III</dc:creator> <pubDate>Wed, 04 Oct 2017 03:35:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10505#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10505#comment:9</guid> <description> <p> This issue should be resolved or moved into github issues. </p> </description> <category>Ticket</category> </item> </channel> </rss>