From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102c.google.com with SMTP id f16-20020a17090a9b1000b0023058bbd7b2so10531830pjp.0 for ; Mon, 06 Feb 2023 04:36:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=jaeNEfX1VzdnxmBLCtyfYe0mVgWeD8bprVT36U59SBs=; b=qdE5/+DfOGGq4Ktk0VqUncjp8x/xnEFT9+hRrCSWI+IVXskkJp5xSy07KaOH5UjW5o UeissySfMpIQyaSq66TtJmX42lJkpjMvkReX83TfsfAw6EvnVMstnLcfYU8WLgs1vZta iDp8opmMCoznVQpG3nBQLhyNvJorxnJBMAGO2wdHmSCxicmQjNlIzW2ie7/ATfbDV/fu 4rBT40TYsK7WwjSMC2K8TEFEo8a3a0iUdGH5YCvJ3F1aBQVI5q85SspDNp49LVc3Ae8W DhUKVf4gIx8gTEH6tg3y59XnJ4RpbHhkdGWOBXfuGBJh5aIxKiLDtrKKoVEcYfnmFyoa HZEg== 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-Google-Smtp-Source: AK7set80bNYCxKrdPPpihQv3xeXNPq/0ODcA3GCQwXUHMdvidsr5i7HWpbsK0gDmkRQxoRnVBhHdRQ== 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 From: Alan Modra To: binutils@sourceware.org Subject: ppc32 and "LOAD segment with RWX permissions" Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 List-Id: 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)" \ -- Alan Modra Australia Development Lab, IBM