From patchwork Thu Oct 26 07:26:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 158426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp486633vqb; Thu, 26 Oct 2023 00:27:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKrFORvSCwssBUuZWZpH6REMai7W2lYIE45KMKvnXD6C0B1ZXrVeGKltlmE4BNNsoo1QvW X-Received: by 2002:a05:620a:1794:b0:765:aac3:7667 with SMTP id ay20-20020a05620a179400b00765aac37667mr19161069qkb.0.1698305229772; Thu, 26 Oct 2023 00:27:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698305229; cv=pass; d=google.com; s=arc-20160816; b=OSF2JekpEJ3FYUzDDgzkPJPlQZ5YUb62WyPunl9IB+Ch7w0nonoKnKLSzi0ZcXotid EzvhtLgOeyQFsCJby+4WPq/nq2vA+VNKCn50PTf5PwKkWstNjLf5y0u4earjymitIs3r QPiUhkFLpZw/d3QXKCbS58GMGpxYrMSLaXkLXIwnFhXjYvSXqlKyfGsO+fQfGJ3Q4J49 aIfPFt1k9hDHHrZIhkEWyOJwhbgc52z8+6vbe9h5V4wHAuHiJ7eXvFcnseYXgVVs7sOa cUGNSgSMN2II+M4SIJJiP+ZdwhNacEUpBJfFZsJ0EjpMy7qVjuERIoHLXyEoklj3jcss A7dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=W52+sAV828/0r/wl51L7cjYDcJ++iNLsUpY8m00Mjfk=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=X0jjNAUN/sfHrwKcqovzJB0NpLUSuYizaR27Ar1aQmzUPkvyyhLOApZHToYkjdZX6Z GW72t8GuzPQr03Qg5EU+J0MjsKRHjVl5r1ljw1imgzCNf+UH0Bflk1jAWtbkcKrf0/5e w08dhlZBrFBYtlJNaII0Q3YeBVuFqIatxRn9aFh5M2bIUdfoeAjYT1L0g9blJwB6T649 0O1WXmLsahI+zqW+UoRMFaLA/8J0jg9GCyfGayYTOcE9sleMkAbtV/VTyklTp3b8BY9b A7Q2kb8+x4l6WY5wuh1Z9aYYuVIFBQosTUmZMOQ6wmWGbUWbBqEXS4aItQZXuM5jYUhP G4dA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=e1d0NQLN; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bs37-20020a05620a472500b00778b2ed7e06si7822219qkb.84.2023.10.26.00.27.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 00:27:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=e1d0NQLN; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BC613857703 for ; Thu, 26 Oct 2023 07:27:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id C66473858D37 for ; Thu, 26 Oct 2023 07:26:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C66473858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C66473858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698305205; cv=none; b=X5Rp1lgFdDhyV7lkiwPpBaqs1+utxtlEZB3xLmFvvZfZl+VLxEtC4bW/192wTtG3iXWZ0JZfQok4PaHxGgJSNFlO/fN5AHAudw0xl0027vhTenJLhpSNEDGqyDRLvsNgt1IDQB49C0BUYISoiDgmoeXCYQjzl52efeyl4DJK0F0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698305205; c=relaxed/simple; bh=ig3AuNao4MoSM4+WRrEPigUyj/27SFviMOAiyyDlLrI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gIt+2rQOGy6OZ25FS9ezH62+X6ZCtP1iNXtAiV4KYqpJKhukmpx9OXqPK2hv2BEHCzTDTFcC9pZlf/aKgfegsUJvWsdRLSCnWlr4oDyTZrccEmjc9GX1ufb7+Oy5eYHHbNGMbby9F91SN86wkdhBXiQSFz6L0IBraBUwuFLyacg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c54c8934abso8431581fa.0 for ; Thu, 26 Oct 2023 00:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698305200; x=1698910000; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=W52+sAV828/0r/wl51L7cjYDcJ++iNLsUpY8m00Mjfk=; b=e1d0NQLNOqCrDwLLxxQg17lEXo+fxPcbwS1nlU4EYgl4LKR34hSKbWWKUpzr1NlKup lrvHN1/FlB3CTIZILBXZ0WCVGgAY7mobTd/fLYwZFCAF6/5b7cgtZ9Qe94zAGO+y9GV9 0G0GxGfssvHCMSrZ32Az8mHL9n1B1MEGCksBpviD9jWeyJJq5wDUHxDb1D4mOi+ts6vN EOWt4VgV6AZxBCBnwKXTrktsSNDlZNLFm54McBTIAaFNDrMYwmm8FnmO7F/baNlS5o2/ ewjLk7/VVxsC2JpxUF5VZcMTvuj9Z4sktBaoHgWhW7N03XnigLzv5pjAwRf3VLLwrijk HAIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698305200; x=1698910000; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=W52+sAV828/0r/wl51L7cjYDcJ++iNLsUpY8m00Mjfk=; b=WKsN1bwfrbkjps/1CPNI+eVKpPZtWeyj/xrMHuphvS5cD5+t/T2k1N0GQ1mpHCrg43 yr8EdsLgMIczr8W+8XzUs9QCB/wcPPyXSsp5RRvmWmNgvcx5z2hy4TevnWL4GnQsL2Cq vciIHIQ2DrCVq7/CIh+wc/dz1sYB5mFexnL0mjXN9a8Qb3shldzLD7t1Jo6TRC0g+0R/ Ws8P4n0jSA2goFHe/qBS7PthNUUa1A6nWK/8LVt5Luex8JLA3oa00/B+g4gvinofdHTy somSFwqSbv7QQC1Uxe7p6VwTFLQiyQO7mAsEdoRgEpV+bBrkeUiJfO6O4WwcXJuVwG39 O2DQ== X-Gm-Message-State: AOJu0YwI3ss73aWzTYS1c5Nr7+lS1wflbWtDGzuiT5mdKRZOr/dcnjhN 2Pop+7tz/55cRTAvNJMXAaPk1CrD0N4= X-Received: by 2002:a05:651c:4d2:b0:2c0:52e:eafa with SMTP id e18-20020a05651c04d200b002c0052eeafamr17804925lji.29.1698305200014; Thu, 26 Oct 2023 00:26:40 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id t3-20020a1c7703000000b004042dbb8925sm1721941wmi.38.2023.10.26.00.26.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 26 Oct 2023 00:26:39 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] Darwin: Handle the fPIE option specially. Date: Thu, 26 Oct 2023 08:26:38 +0100 Message-Id: <20231026072638.96201-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.4 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 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780802104230952698 X-GMAIL-MSGID: 1780802104230952698 Testing the fhardened patch prompted checking of what the Xcode tools actually emit for -fPIE. This patch makes the GCC port follow the same pattern. Tested on x86_64, i686-darwin, pushed to trunk, thanks, Iain --- 8< --- For Darwin, PIE requires PIC codegen, but otherwise is only a link-time change. For almost all Darwin, we do not report __PIE__; the exception is 32bit X86 and from Darwin12 to 17 only (32 bit is no longer supported after Darwin17). gcc/ChangeLog: * config/darwin.cc (darwin_override_options): Handle fPIE. Signed-off-by: Iain Sandoe --- gcc/config/darwin.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc index a80b6caf95a..621a94d74a2 100644 --- a/gcc/config/darwin.cc +++ b/gcc/config/darwin.cc @@ -3325,6 +3325,8 @@ darwin_override_options (void) { if (strverscmp (darwin_macosx_version_min, "10.14") >= 0) generating_for_darwin_version = 18; + else if (strverscmp (darwin_macosx_version_min, "10.8") >= 0) + generating_for_darwin_version = 12; else if (strverscmp (darwin_macosx_version_min, "10.7") >= 0) generating_for_darwin_version = 11; else if (strverscmp (darwin_macosx_version_min, "10.6") >= 0) @@ -3495,8 +3497,17 @@ darwin_override_options (void) && dwarf_debuginfo_p ()) flag_var_tracking_uninit = flag_var_tracking; - /* Final check on PCI options; for Darwin these are not dependent on the PIE - ones, although PIE does require PIC to support it. */ + if (OPTION_SET_P (flag_pie) && flag_pie) + { + /* This is a little complicated, to match Xcode tools. + For Darwin, PIE requires PIC codegen, but otherwise is only a link- + time change. For almost all Darwin, we do not report __PIE__; the + exception is Darwin12-17 and for 32b only. */ + flag_pie = generating_for_darwin_version >= 12 && !TARGET_64BIT ? 2 : 0; + flag_pic = 2; /* We always set this. */ + } + + /* Final check on PIC options. */ if (MACHO_DYNAMIC_NO_PIC_P) { if (flag_pic)