From patchwork Wed May 17 01:51:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 94997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp816676vqo; Tue, 16 May 2023 18:51:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ49e6ku5LNt050vq9Aziv9CPGMvtCbkxZqCyghS3cI0MlApNewatXFLlczaofgPs1uvusKi X-Received: by 2002:a17:907:7f0c:b0:94e:dc3c:cca2 with SMTP id qf12-20020a1709077f0c00b0094edc3ccca2mr36852932ejc.70.1684288292025; Tue, 16 May 2023 18:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684288292; cv=none; d=google.com; s=arc-20160816; b=q9dF2Meoh8E/XEI9jXj2akcSiE6idHx0XjQlj8M9ScyYWEiPOd20xiS0IYLDpLJdtJ op/0FPmOUqHUivUMpZJ91TyFGQj9nil9SxlqKvtYI2Lc94RwllLHuYbiz8TXlEmIKD8N o8v40dlhzw/HBYtc4SKq0bdVS8vwrmxhPG+O8TbTIFACesbM4xBgSu3Se8SP4TC1zquR mQKtkZyDWwQXiF4j62fuCNqczPZeRJE+i37OVwjZWekPSL3/XtO8ip9J1/ubz/o6PNYK O3tMwl1mMk3/hbI7AMm88KGlAM6nMlYsLkM4xRQWwNDn23hvo2STm51qw9rctKB4Ght7 m9SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=T/ob6T+h2j4U9TVJgreviW5eSHZTeiCwg7utDcGrJpw=; b=GhuxLby/Xh3GQD9PudDZmMbGUtmNTBmbUwNGkWPkxaVheVlmj1po97+BW7LQxToKfT BxCleVu4y0VAkAp9hDSJpM48DBuSBF4T5f0HOnzLryUCaATw0V3g+p5QoGK9Uh+0JK1Y YqcvS62DkWXevjdphoTG+LOV+66wJuy0hsQUqjQlZRFCIj6lgRG9lcGDEtsfQAm/MkwY 0eIAYdgwqtTtd+0L+Ucip+FLgYD3fHwhVW1d1W5/7NJBmFghv14UIcVFaOnpAbUH3WPU 2cE2819wR4OVK/77FK/AAHEp2xR4ky6GcEvkPzMX/odNnWqSFJcY+zUnIsbfi0aZ841d jH9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=MxkKnL6O; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n15-20020aa7c78f000000b005083e031fd0si15081759eds.321.2023.05.16.18.51.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 18:51:32 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=MxkKnL6O; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F21553856DE7 for ; Wed, 17 May 2023 01:51:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F21553856DE7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684288291; bh=T/ob6T+h2j4U9TVJgreviW5eSHZTeiCwg7utDcGrJpw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MxkKnL6ONWmzwbzcrELVu10iQe7U5lTfC4a2FHuh0S8QSvC9Be1of7JunxKHSl0qk JvDleP9MXaBNlkB5B/6ITw9v1Cg9njr5Ld24uBX1BljnuMTlfTlM2pXd2QEE3/QBRZ B4foTDzlBplJyC55js/WWtrEkKuOatix30ufXRu8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id DB7C43858D1E for ; Wed, 17 May 2023 01:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB7C43858D1E Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64384c6797eso123470b3a.2 for ; Tue, 16 May 2023 18:51:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684288279; x=1686880279; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T/ob6T+h2j4U9TVJgreviW5eSHZTeiCwg7utDcGrJpw=; b=MwHOVjG2GR1h0Y6eP3BD8JcThXrifltDtf60t/nl+dBsdEQlCiXs1W0axoTSbe5EQi MwZJJeh3RFOCzdEt3+tWUw8apDjo0148X7biUp72w/iqnANbW4XgLFVTRMyAoJGBOLVT H/U3d1X6lMRr5f7giE2jtgkbQ0f+oqMEi7qmMhTdST1QKScOi06ETRAZvd2KNvui3q5u QSweD3dF+625RBpSk5T6basLmH4BzJdeJoz/b5eDt9FnmV25n2NwBToegazLp+NjPDzg YbCAlaSdRKMXkMKZBn4cdAMY0WpEbLpp7mcRMOSODjVKUoYryeLO9y5wBQgSQScuCXOM zp9Q== X-Gm-Message-State: AC+VfDzkofQm24nJtWX6PYOMbBF3zRPQgfsfbKe9WnMnvuqCtoGUYYh7 fASO93v9iOTnECTUM9TdvvGjln+5a3c= X-Received: by 2002:a05:6a00:9aa:b0:646:59e4:94eb with SMTP id u42-20020a056a0009aa00b0064659e494ebmr43850077pfg.15.1684288279452; Tue, 16 May 2023 18:51:19 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:3c4d:54da:637:3855]) by smtp.gmail.com with ESMTPSA id k18-20020aa792d2000000b0064cca73d911sm1163505pfa.103.2023.05.16.18.51.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 18:51:18 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 1B9E41142CBF; Wed, 17 May 2023 11:21:15 +0930 (ACST) Date: Wed, 17 May 2023 11:21:15 +0930 To: binutils@sourceware.org Subject: PR29961, plugin-api.h: "Could not detect architecture endianess" Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766104280133765110?= X-GMAIL-MSGID: =?utf-8?q?1766104280133765110?= Found when attempting to build binutils on sparc sunos-5.8 where sys/byteorder.h defines _BIG_ENDIAN but not any of the BYTE_ORDER variants. This patch adds the extra tests to cope with the old machine, and tidies the header a little. If you're wondering why I bother with the tidy, it's because the other patches in the PR included sys/byteorder.h (again!) and added tests specific to sunos-5.8 immediately after. No doubt that was following the same practice as for __GLIBC__. If glibc's endian.h had been treated the same as other headers included here, we'd probably have seen better fixes. PR 29961 plugin-api.h: When handling non-gcc or gcc < 4.6.0 include necessary header files before testing macros. Make more use of #elif. Test _LITTLE_ENDIAN and _BIG_ENDIAN in final tests. diff --git a/include/plugin-api.h b/include/plugin-api.h index 395d5bcc598..f3cf2d8101b 100644 --- a/include/plugin-api.h +++ b/include/plugin-api.h @@ -37,7 +37,7 @@ #error cannot find uint64_t type #endif -/* Detect endianess based on __BYTE_ORDER__ macro. */ +/* Detect endianess based on gcc's (>=4.6.0) __BYTE_ORDER__ macro. */ #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_PDP_ENDIAN__) #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ @@ -47,46 +47,47 @@ #elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ #define PLUGIN_PDP_ENDIAN 1 #endif + #else -/* Older GCC releases (<4.6.0) can make detection from glibc macros. */ +/* Include header files to define endian macros. */ #if defined(__GLIBC__) || defined(__GNU_LIBRARY__) || defined(__ANDROID__) #include + +#elif defined(__SVR4) && defined(__sun) +#include + +#elif defined(__FreeBSD__) || defined(__NetBSD__) || \ + defined(__DragonFly__) || defined(__minix) +#include + +#elif defined(__OpenBSD__) +#include +#endif + +/* Detect endianess based on __BYTE_ORDER. */ #ifdef __BYTE_ORDER #if __BYTE_ORDER == __LITTLE_ENDIAN #define PLUGIN_LITTLE_ENDIAN 1 #elif __BYTE_ORDER == __BIG_ENDIAN #define PLUGIN_BIG_ENDIAN 1 #endif -#endif -#endif -/* Include all necessary header files based on target. */ -#if defined(__SVR4) && defined(__sun) -#include -#endif -#if defined(__FreeBSD__) || defined(__NetBSD__) || \ - defined(__DragonFly__) || defined(__minix) -#include -#endif -#if defined(__OpenBSD__) -#include -#endif + /* Detect endianess based on _BYTE_ORDER. */ -#ifdef _BYTE_ORDER +#elif defined _BYTE_ORDER #if _BYTE_ORDER == _LITTLE_ENDIAN #define PLUGIN_LITTLE_ENDIAN 1 #elif _BYTE_ORDER == _BIG_ENDIAN #define PLUGIN_BIG_ENDIAN 1 #endif -#endif + /* Detect based on _WIN32. */ -#if defined(_WIN32) +#elif defined _WIN32 #define PLUGIN_LITTLE_ENDIAN 1 -#endif + /* Detect based on __BIG_ENDIAN__ and __LITTLE_ENDIAN__ */ -#ifdef __LITTLE_ENDIAN__ +#elif defined __LITTLE_ENDIAN__ || defined _LITTLE_ENDIAN #define PLUGIN_LITTLE_ENDIAN 1 -#endif -#ifdef __BIG_ENDIAN__ +#elif defined __BIG_ENDIAN__ || defined _BIG_ENDIAN #define PLUGIN_BIG_ENDIAN 1 #endif #endif