From patchwork Mon Feb 6 12:36: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: 53216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2208558wrn; Mon, 6 Feb 2023 04:36:29 -0800 (PST) X-Google-Smtp-Source: AK7set8bJDkuguYowYOfMiovix2AvltPxEqQuO9Js2Ir+8WlAvoAV4LKaN99jsP5OEqrU8NShy0+ X-Received: by 2002:a17:907:7e9d:b0:88f:9c9a:81f with SMTP id qb29-20020a1709077e9d00b0088f9c9a081fmr15130336ejc.45.1675686989088; Mon, 06 Feb 2023 04:36:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675686989; cv=none; d=google.com; s=arc-20160816; b=qvEJ1riz+8CfLFpWyjw2OZRpSjRrynpzhz6x8R2zt0arymOEd7TUJEIakBOX6IY8Vu pJ4VVn0M6DyvVXVX1l/+/OleGRzfbEWBu3fLDUJqD1WESCFKigMDJcCvhW7H388Seexy +1oK95ptNQ8W33cmzbSDp2CtIY8+2V/C+1xbvJPojbFp197AXSFr11pisdzRxtN87hYV gnnxw65Z0nqhn9AtQaXmybdCY3EGfQY+FOUtyLeu+SaDCijyqPjoFJuoP7MPdKjSOq6t ILsVht6idM3xRU5nAaGO43jWNc0jKWSBV61bLN5dph3t1qNtTzV9mw1ZP7ddT6gjzQZt 3sqw== 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=jaeNEfX1VzdnxmBLCtyfYe0mVgWeD8bprVT36U59SBs=; b=F8AapDpSiPYf8if6o6AnRSPCwbi41xLkoFfIxquX8YUP94lOh1woArP8ZWRsRFv84I TOambki9p+J+2OZ5eRc329bOjOsKtwYIPTdf7cvgdNQUkpBAJn9Bt/hs7uvM5TlKsNBQ h4O+uB+gbW+lRbd90Kq4W8fHAmrm6Zux+3dOclFnbDLIx8OrwpRdUQySZcAnIahAFwjk S7y3hOCiRryQ1jEP4xVzI0SiY6+cyjSojRRdiGvp9IXl2XComxnYGjFxKo0e4b5jSBQu LU9tKKn7oVzTgJ2p5AfcUglGo6+kL3WEtZi9tbREnAlMv+B0yNNq6EG4vvJdqUM/xvLN /3Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qcThxoOA; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id vg13-20020a170907d30d00b00890ac8da46asi10124022ejc.832.2023.02.06.04.36.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 04:36:29 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qcThxoOA; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 DD7E53858C83 for ; Mon, 6 Feb 2023 12:36:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD7E53858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675686987; bh=jaeNEfX1VzdnxmBLCtyfYe0mVgWeD8bprVT36U59SBs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qcThxoOAflYnTvAypcOuozsydLNRo/Lp0asH8TRNeBHZ5Znrwn+QHnKG0ITiUDrZk FC31v7rduUi460D7Ek9RW+/ZNmmQShOLMC5Y7jjgSiFl7UlVQ30NaDTjgK9uzgmW9z /+Ef7KCkeiKK3jmPljAkzXpnO1d4Aw8RFiAK3lz8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id 530833858D1E for ; Mon, 6 Feb 2023 12:36:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 530833858D1E Received: by mail-pj1-x102c.google.com with SMTP id f16-20020a17090a9b1000b0023058bbd7b2so10531830pjp.0 for ; Mon, 06 Feb 2023 04:36:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=jaeNEfX1VzdnxmBLCtyfYe0mVgWeD8bprVT36U59SBs=; b=FLoSpy3eKT8+k9YX8spxuu625ih4Kh0mHCdQPGvcS+Z0XhcsrWTQuQjUwKTlloxvU0 aBBzG3rLJbqTFvd5MIS6tSsKGb9ocI3uhrHXL80yiKDT55VkHJFw82F1gTSYy8UcltCk pI/b967T6tKgrRCarJECCU4w56US9MBWeUJNNxX5MSaLzbqs+pl2EYjs7zoISnJp2bup YAyZ/66n1tk2avgZ6rRz1///dnBqRl0GRenUyg6+rG9ElSNDvGQMCnds9g9UdVnI9Bfh HnUnNFv/lIbaBT4sa2nM1+1vwmikkjwqFqsK6Rqht8dOvcLQtzBOTSoVc6b+VCTgynEZ MfTw== X-Gm-Message-State: AO0yUKUA0VVX49A7SWzqs8Zbk19Eewo0ugEr3DvUNwp2CVgG7j966xDr UOK1491/26GtSdmtlPUtdsWJQAx2o2w= X-Received: by 2002:a05:6a20:6a82:b0:be:b3c5:dabe with SMTP id bi2-20020a056a206a8200b000beb3c5dabemr19278480pzb.41.1675686978139; Mon, 06 Feb 2023 04:36:18 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:8595:7eb:ede9:c45]) by smtp.gmail.com with ESMTPSA id k6-20020a633d06000000b004d09bbd023csm6049517pga.88.2023.02.06.04.36.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 04:36:17 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 9634F1142DDD; Mon, 6 Feb 2023 23:06:15 +1030 (ACDT) Date: Mon, 6 Feb 2023 23:06:15 +1030 To: binutils@sourceware.org Subject: ppc32 and "LOAD segment with RWX permissions" Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.0 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: 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?1757085160165706000?= X-GMAIL-MSGID: =?utf-8?q?1757085160165706000?= When using a bss-plt we'll always trigger the RWX warning, which disturbs gcc test results. On the other hand, there may be reason to want the warning when gcc is configured with --enable-secureplt. So turning off the warning entirely for powerpc might not be the best solution. Instead, we'll turn off the warning whenever a bss-plt is generated, unless the user explicitly asked for the warning. bfd/ * elf32-ppc.c (ppc_elf_select_plt_layout): Set no_warn_rwx_segments on generating a bss plt, unless explicity enabled by the user. Also show the bss-plt warning when --warn-rwx-segments is given without --bss-plt. include/ * bfdlink.h (struct bfd_link_info): Add user_warn_rwx_segments. ld/ * lexsup.c (parse_args): Set user_warn_rwx_segments. * testsuite/ld-elf/elf.exp: Pass --secure-plt for powerpc to the rwx tests. diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index a8234f27a8a..833bc744563 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -4020,12 +4020,19 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED, htab->plt_type = plt_type; } } - if (htab->plt_type == PLT_OLD && htab->params->plt_style == PLT_NEW) + if (htab->plt_type == PLT_OLD) { - if (htab->old_bfd != NULL) - _bfd_error_handler (_("bss-plt forced due to %pB"), htab->old_bfd); - else - _bfd_error_handler (_("bss-plt forced by profiling")); + if (!info->user_warn_rwx_segments) + info->no_warn_rwx_segments = 1; + if (htab->params->plt_style == PLT_NEW + || (htab->params->plt_style != PLT_OLD + && !info->no_warn_rwx_segments)) + { + if (htab->old_bfd != NULL) + _bfd_error_handler (_("bss-plt forced due to %pB"), htab->old_bfd); + else + _bfd_error_handler (_("bss-plt forced by profiling")); + } } BFD_ASSERT (htab->plt_type != PLT_VXWORKS); diff --git a/include/bfdlink.h b/include/bfdlink.h index 26c459c3815..840790a298c 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -501,6 +501,9 @@ struct bfd_link_info /* TRUE if warnings should not be generated for TLS segments with eXecute permission or LOAD segments with RWX permissions. */ unsigned int no_warn_rwx_segments: 1; + /* TRUE if the user gave either --warn-rwx-segments or + --no-warn-rwx-segments. */ + unsigned int user_warn_rwx_segments: 1; /* TRUE if the stack can be made executable because of the absence of a .note.GNU-stack section in an input file. Note - even if this field diff --git a/ld/lexsup.c b/ld/lexsup.c index c5960385572..a1c6140100d 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -936,9 +936,11 @@ parse_args (unsigned argc, char **argv) break; case OPTION_WARN_RWX_SEGMENTS: link_info.no_warn_rwx_segments = 0; + link_info.user_warn_rwx_segments = 1; break; case OPTION_NO_WARN_RWX_SEGMENTS: link_info.no_warn_rwx_segments = 1; + link_info.user_warn_rwx_segments = 1; break; case 'e': lang_add_entry (optarg, true); diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp index 1a160d084e0..a4f7f60fefc 100644 --- a/ld/testsuite/ld-elf/elf.exp +++ b/ld/testsuite/ld-elf/elf.exp @@ -238,6 +238,12 @@ if { [istarget *-*-*linux*] return $text } + set curr_ldflags $LDFLAGS + if { [istarget powerpc*-*-*] && ![istarget powerpc64*-*-*] } { + # Don't generate an executable .plt section + set LDFLAGS "$LDFLAGS --secure-plt" + } + # Since the warnings can be disabled by configure, ensure consistency # of the first test by forcing the flags. run_ld_link_tests [list \ @@ -285,6 +291,8 @@ if { [istarget *-*-*linux*] "rwx-segments-3.exe"] \ ] + set LDFLAGS $curr_ldflags + if { [target_defaults_to_execstack] } { run_ld_link_tests [list \ [list "PR ld/29072 (warn about absent .note.GNU-stack)" \