From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <37ZEeYgcKCKIOCUMTCaIQQING.EQODKPWVKNUUQWTEGYCTG.QTI@flex--maskray.bounces.google.com> Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 0096C3858D39 for ; Tue, 1 Mar 2022 21:36:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0096C3858D39 Received: by mail-yb1-xb49.google.com with SMTP id w6-20020a25c706000000b006287a0164f2so3336465ybe.1 for ; Tue, 01 Mar 2022 13:36:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=t4ZLW/wOYc2dLyWJkE1BVXQUNhvuSCTQcK2uwNhJZNI=; b=RUPu1XzJocSiC8UTNDPyBnYWQVq1wjo8f/PW7nDmfKrGYlqi5hq2awLpVsTId8Ue2i FibmS7IKSXeSVBElYtgY4Pk1e32RQ7IeXvEhamiELaDwRk8RS3jcpJ8mnHaQxUx31/Lm 1/Doiu+pXchl2sInhAnEYp0rYWc4tIW3FfJ5wsZCzRcp1JIQaKLpSXdOGJ2Fwg6DXrm5 pGj8fBuY1eRyrLjFeAeruiuFhlvhYiEiR0rdHY9jqNmHAMrPW5LFRXIDzdasAIquZY0Q OU1J+ar9cTDzuJfwkML7Ca5Tp/kLNDt0bwjruY9llglk1a0uC+9LzCqByNWxyAyTsm1C OsFw== X-Gm-Message-State: AOAM532MPWgdAK8WlOBuyE8XBseUXzBLf3l7e7JzkNVs7gwxz0jxjJoN LOFhomRCgPhoHZfkvOdYUQIkLaXyhG6U+63eNzmhmj6oA8+GuqFIjVImrZhb2nU7vcI0rGPSDgZ cCCEmJ7d/p5HP0+jugE3wybJaoOt+3kzLiCiMWAGhEP7YyRguZ5rocEKZtqhsliErlg== X-Google-Smtp-Source: ABdhPJyQXVoaOFrXGoTqwfz/EzCm116s6BIJx5wpohCm6AWbR/w6fQNjZxiHns1UoITbyAJgOIPyl3Z25qos X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:200:88f6:4b70:bdc0:5a68]) (user=maskray job=sendgmr) by 2002:a81:6685:0:b0:2d6:275f:9fd3 with SMTP id a127-20020a816685000000b002d6275f9fd3mr27000396ywc.104.1646170605429; Tue, 01 Mar 2022 13:36:45 -0800 (PST) Date: Tue, 1 Mar 2022 13:36:06 -0800 Message-Id: <20220301213606.259903-1-maskray@google.com> Mime-Version: 1.0 Subject: [PATCH] objcopy --weaken-symbol: apply to STB_GNU_UNIQUE symbols From: Fangrui Song To: binutils@sourceware.org, Alan Modra , Nick Clifton Cc: Fangrui Song Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-20.1 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 01 Mar 2022 21:36:47 -0000 PR binutils/28926 * objcopy.c (filter_symbols): Apply weaken to STB_GNU_UNIQUE symbols * NEWS: Mention feature. * testsuite/binutils-all/objcopy.exp (objcopy_test_symbol_manipulation): New test. * testsuite/binutils-all/weaken-gnu-unique.s: New. --- binutils/NEWS | 3 +++ binutils/objcopy.c | 4 ++-- binutils/testsuite/binutils-all/objcopy.exp | 4 ++++ binutils/testsuite/binutils-all/weaken-gnu-unique.d | 8 ++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 binutils/testsuite/binutils-all/weaken-gnu-unique.d diff --git a/binutils/NEWS b/binutils/NEWS index c188b469a77..06f34c9a992 100644 --- a/binutils/NEWS +++ b/binutils/NEWS @@ -1,5 +1,8 @@ -*- text -*- +* objcopy --weaken, --weaken-symbol, and --weaken-symbols now make ELF + STB_GNU_UNIQUE symbols weak. + Changes in 2.38: * elfedit: Add --output-abiversion option to update ABIVERSION. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index d53aa5c6000..aaa5aa9b2af 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -1681,11 +1681,11 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms, if (keep) { - if (((flags & BSF_GLOBAL) != 0 + if (((flags & (BSF_GLOBAL | BSF_GNU_UNIQUE)) || undefined) && (weaken || is_specified_symbol (name, weaken_specific_htab))) { - sym->flags &= ~ BSF_GLOBAL; + sym->flags &= ~ (BSF_GLOBAL | BSF_GNU_UNIQUE); sym->flags |= BSF_WEAK; } diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index 32c76a11f3b..9a5dad5384e 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -1144,6 +1144,10 @@ proc objcopy_test_symbol_manipulation {} { verbose [file rootname $t] run_dump_test [file rootname $t] } + + if { [supports_gnu_unique] } { + run_dump_test "weaken-gnu-unique" + } } proc objcopy_test_elf_common_symbols {} { diff --git a/binutils/testsuite/binutils-all/weaken-gnu-unique.d b/binutils/testsuite/binutils-all/weaken-gnu-unique.d new file mode 100644 index 00000000000..b0e60c4ff80 --- /dev/null +++ b/binutils/testsuite/binutils-all/weaken-gnu-unique.d @@ -0,0 +1,8 @@ +#name: weaken STB_GNU_UNIQUE symbols +#PROG: objcopy +#objcopy: -W foo +#source: unique.s +#readelf: -s + +#... + +[0-9]+: +[0-9a-f]+ +[0-9]+ +OBJECT +WEAK +DEFAULT +[1-9] foo -- 2.35.1.574.g5d30c73bfb-goog