public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/PR94249-lto-plugin-v3)] Improve endianess detection. Date: Tue, 24 Mar 2020 08:13:35 +0000 (GMT) [thread overview] Message-ID: <20200324081335.1F4D4385B834@sourceware.org> (raw) https://gcc.gnu.org/g:d7699407e3133651e6b8753ccd4dab71915dd6a9 commit d7699407e3133651e6b8753ccd4dab71915dd6a9 Author: Martin Liska <mliska@suse.cz> Date: Tue Mar 24 09:12:50 2020 +0100 Improve endianess detection. include/ChangeLog: 2020-03-24 Martin Liska <mliska@suse.cz> PR lto/94249 * plugin-api.h: Add more robust endianess detection. Diff: --- include/plugin-api.h | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/include/plugin-api.h b/include/plugin-api.h index 673f136ce68..a530cb08e2b 100644 --- a/include/plugin-api.h +++ b/include/plugin-api.h @@ -42,6 +42,44 @@ extern "C" { #endif +/* Detect endianess based on __BYTE_ORDER__ macro. */ +#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && defined(__ORDER_LITTLE_ENDIAN__) +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define PLUGIN_LITTLE_ENDIAN 1 +#endif +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define PLUGIN_BIG_ENDIAN 1 +#endif +#else +/* Include all necessary header files based on target. */ +#if defined(__SVR4) && defined(__sun) +#include <sys/byteorder.h> +#endif +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__minix) +#include <sys/endian.h> +#endif +#if defined(__OpenBSD__) +#include <machine/endian.h> +#endif +/* Detect endianess based on _BYTE_ORDER. */ +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define PLUGIN_LITTLE_ENDIAN 1 +#elif _BYTE_ORDER == _BIG_ENDIAN +#define PLUGIN_BIG_ENDIAN 1 +#endif +/* Detect based on _WIN32. */ +#if defined(_WIN32) +#define PLUGIN_LITTLE_ENDIAN 1 +#endif +/* Fallback to __BIG_ENDIAN__ and __LITTLE_ENDIAN__ */ +#ifdef __LITTLE_ENDIAN__ +#define PLUGIN_LITTLE_ENDIAN 1 +#endif +#ifdef __BIG_ENDIAN__ +#define PLUGIN_BIG_ENDIAN 1 +#endif +#endif + /* Status code returned by most API routines. */ enum ld_plugin_status @@ -89,16 +127,18 @@ struct ld_plugin_symbol char *version; /* This is for compatibility with older ABIs. The older ABI defined only 'def' field. */ -#ifdef __BIG_ENDIAN__ +#if PLUGIN_BIG_ENDIAN == 1 char unused; char section_kind; char symbol_type; char def; -#else +#elif PLUGIN_LITTLE_ENDIAN == 1 char def; char symbol_type; char section_kind; char unused; +#else +#error "Could not detect architecture endianess" #endif int visibility; uint64_t size;
next reply other threads:[~2020-03-24 8:13 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-24 8:13 Martin Liska [this message] 2020-03-24 8:15 Martin Liska 2020-03-24 8:45 Martin Liska 2020-03-24 10:30 Martin Liska
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=20200324081335.1F4D4385B834@sourceware.org \ --to=marxin@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.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: linkBe 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; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).