From patchwork Thu Jan 2 19:19:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 854750 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp7930751wrq; Thu, 2 Jan 2025 11:26:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV+5QH55rJ3M8vU+hGmX8QkGWxLfnjjaFOo9ifHGqF2tRZSRf+sDlQSXdVJ3BnKZYQ8kUWvIA==@linaro.org X-Google-Smtp-Source: AGHT+IFVtUXut6RsU7a1XHyGonrty628Zv35felkslbFh0nJNO1rpvtx/6H/dl1cUY3Xh/lYJmL/ X-Received: by 2002:a05:6214:2e47:b0:6d8:893b:2a13 with SMTP id 6a1803df08f44-6dd234dc943mr728166246d6.0.1735846008327; Thu, 02 Jan 2025 11:26:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1735846008; cv=pass; d=google.com; s=arc-20240605; b=PGDyhN4OIEzhFiwxrY0XrQOFGK5pNpdooyHnYGOHRpKhRjcD8SFc6XejSFACPBNQKh KM5igitDItYzu2PasqnTjj0A5GVrpshQ9y3YTSrXaefky5cEjHNSh9MUZsFNStzGklcR tdHCXECtbhKlocKzRS3kFJqnk1jBs8s1N4KFmMuVZQgGGdp9QuJ4sJV9AfUXXriImOdD TXHmZdkUWw5ZJarXMGGBbzsuVVQmbQOWOqw6ujvDvhR9c8Jigy42uWENITqg8fuIodJn ZVOLDJRFwlHp6vR+f4i4A+F/2UJ5vJdHQ6gt2jVC34GJnpkEdh6IBQv0cnu18LB8IjCF deVA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=KaQ30waZnrlRd3KXREfZ08MPXU8G0Ola/SAQBQ+0STI=; fh=JruiOR+n5wiv4jZbtXJYp9lJ8UkedxUHyGOCC37Fjus=; b=S7fWaj4oZ7gLeVtDZCEY5e/Ablwg9zVCOAKp0IC9Gu65gOR159SyyuKn8mpMlUkNje k5xV0AwJC7XOZfucpHb9n0Mpe0uS34fs/q2irfipXKe9tLKSJLcICdzBXh1spyjzZ58g UXhawt9NizdLKG2scLBnx/Zcxi5r07qs8hWec39gIDahnlpnag2UekiiVg6HozJbtRLm yTQhfCMja0xDrbpqWuw113VNWy98xIlhtVdac0r3wR/msbp2B5D2YZO+kQovCxZj9pIg +86AP3hVk4ud9I5BHGIijg3Lgvj8UccKnwHCPzyKbFKHYHm6MNYkBxAkorCb4+4qZVlV r+Mg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xKajBuUi; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 6a1803df08f44-6dd1813724asi369975406d6.150.2025.01.02.11.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 11:26:48 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces~patch=linaro.org@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=@linaro.org header.s=google header.b=xKajBuUi; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF2203858CDA for ; Thu, 2 Jan 2025 19:26:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF2203858CDA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=xKajBuUi X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id AAB3E3858CD1 for ; Thu, 2 Jan 2025 19:20:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AAB3E3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AAB3E3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735845616; cv=none; b=nO+yQmwPm6vniqfO8CbdZSknyIjwCZf47gLM9Tq1ndGrweWe+X3l4Tpnopk+qTl0/OQqRGJXWVlrudYaWyQajhN7i8C6OweMIaBO3v28IlElSViCvoSmMxqmGBcKI2Rg3wZAEh/MZjpTC+y1ZgmBxSR9TzKXhvWzSc7saQc/D0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735845616; c=relaxed/simple; bh=Uyb9meJmXZiksid2eBvI/8F9RP0jYA7HIDTohKy8s4Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NjoR7zRikr+mIP9Tsy37/UUPXVq2F4rbU5xNX1ExUWLRYIBoR6WPbXaYDoO2XQCDON9WVM9MU/bebwFmaYiKZyBaqeDTscm2DoJ7IxKF5c3UmCaSp58qioxJK0J6uVYh2cev7/ixOaBkNY8loU0QlaoI2gODpkdKIT7U0P/PA2I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAB3E3858CD1 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2167141dfa1so156164005ad.1 for ; Thu, 02 Jan 2025 11:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735845615; x=1736450415; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KaQ30waZnrlRd3KXREfZ08MPXU8G0Ola/SAQBQ+0STI=; b=xKajBuUiwu5YFOSNEo+NqmXtNhf7nuxuMfC02+kKPbHWxcirdLqU6HoV4TTjGSwllw +b5q7Sx9N6t5NlbgVrE5+91IrtknQ+39RJiAjAbrjRU4Z3pvflQKG4D56SZxwEt2YRbK N0AsL1ojVmjn0jvpregT1tlCjKjUNkGRzBbofQ5ULqLJ1ZGa4mjxC38ZW3Q4tX+UOCxT zksnLQ3o6nfU+zzZn8HY56P02jyyH43KSFC6eLErYvF+DPBILaX4OUOLj2+G/ZJrA3RZ IOSHVSdIGW+uWyMZ5TR7hnrP7hJRdOxCrUH4cSU+TWoL99ZD4nrI+mIauFXeBmOfRefL y4mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735845615; x=1736450415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KaQ30waZnrlRd3KXREfZ08MPXU8G0Ola/SAQBQ+0STI=; b=JKC8inu/WPYHvV7fT6KKwmk3oYcAkyhanoruPgCu/Ahq5nKLs32MxRlgm9EXG2PyW2 2EE/tlJ7eIsKQ6r2EmkQ7UyX+sQiXVeBO0rLfd4cQ8n0TBYawzFMkD3BCURmJf/w66ZT pXbRju5OYDIeW3czLz8+7bxvKlOqzJ29CD4qTbFw8EtrbCkOpw30bmb1dPlFx7TPCC7A QbMc1DCqZ7/FPlOqjBVe1U00iB40STXGUzMWVFVYNBb6ed/mVfTNEorTqHSbCYmRz6Od D/3vKwj04mW6iL2xyrjEmGkyflDa1VSUU5WHLu3DST/gzv/5GQ21aVENH872tybbw/Gv iDzw== X-Gm-Message-State: AOJu0YxpWVMO0Rwi4R/lbQOuTLex8rhhfrYzgbymT9ZCwZUTlkHYBRXX wgz+ZG3sTGPXrmazhqtQQnLThT5gWILE4jmpmqweUSw4QvulthlNbEc2gqR25yTy74MSJR33sl5 d X-Gm-Gg: ASbGncvb/RetaxHRgp8Gfi98CZ1nowc9alsmHtRdFdRtk7GCg8zxgdkZqwbxlNWflgq WJnnonEiioehSSAiO6ioSnH1IJQv0XZBKM1h2bkM8E3EVndSYdJ9nRXyU4E139iKsYcKgcpDHZQ BOV7ZIxl1Z443OBgCrflgvfZINu1mFR+qJBZCCrB5cKnATlBpkQbdrI2Omx4kc4tSOKs5L6Ei9M uoxjh1twyD9ycKZSqmKPirrJqg7ghrT7xOCtZgZe+mPiSc0vzRZ3makF8JMJyWV2VnRbdg3aLue oYITYAezHljzPoDYmDwxomqoDTP0 X-Received: by 2002:a17:902:da8a:b0:216:11cf:790 with SMTP id d9443c01a7336-219da5f0a54mr732567135ad.16.1735845615260; Thu, 02 Jan 2025 11:20:15 -0800 (PST) Received: from ubuntu-vm.. (201-92-186-201.dsl.telesp.net.br. [201.92.186.201]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-842b85efb58sm22604630a12.34.2025.01.02.11.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 11:20:14 -0800 (PST) From: Adhemerval Zanella To: binutils@sourceware.org Cc: Jeff Xu , "H . J . Lu" Subject: [PATCH v5 2/3] gold: Add GNU_PROPERTY_MEMORY_SEAL gnu property Date: Thu, 2 Jan 2025 16:19:29 -0300 Message-ID: <20250102192006.1318325-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250102192006.1318325-1-adhemerval.zanella@linaro.org> References: <20250102192006.1318325-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patch=linaro.org@sourceware.org Similar to the ld.bfd, with the -z,memory-seal and -z,no-memory-seal which adds the .gnu.attribute GNU_PROPERTY_MEMORY_SEAL. Change-Id: I31e194479912d3f468d5e5132a6eb566ed9aca78 --- elfcpp/elfcpp.h | 1 + gold/NEWS | 3 ++ gold/layout.cc | 4 +++ gold/options.h | 3 ++ gold/testsuite/Makefile.am | 19 ++++++++++++ gold/testsuite/Makefile.in | 26 +++++++++++++++-- gold/testsuite/memory_seal_main.c | 5 ++++ gold/testsuite/memory_seal_shared.c | 7 +++++ gold/testsuite/memory_seal_test.sh | 45 +++++++++++++++++++++++++++++ 9 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 gold/testsuite/memory_seal_main.c create mode 100644 gold/testsuite/memory_seal_shared.c create mode 100755 gold/testsuite/memory_seal_test.sh diff --git a/elfcpp/elfcpp.h b/elfcpp/elfcpp.h index 3ceddbda19c..1b7a1f7f8ac 100644 --- a/elfcpp/elfcpp.h +++ b/elfcpp/elfcpp.h @@ -1023,6 +1023,7 @@ enum { GNU_PROPERTY_STACK_SIZE = 1, GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2, + GNU_PROPERTY_MEMORY_SEAL = 3, GNU_PROPERTY_LOPROC = 0xc0000000, GNU_PROPERTY_X86_COMPAT_ISA_1_USED = 0xc0000000, GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED = 0xc0000001, diff --git a/gold/NEWS b/gold/NEWS index c0f4842e617..7fca7603476 100644 --- a/gold/NEWS +++ b/gold/NEWS @@ -5,6 +5,9 @@ * Remove support for -z bndplt (MPX prefix instructions). +* Add -z memory-seal/-z nomemory-seal options to ELF linker to mark the + object to memory sealed. + Changes in 1.16: * Improve warning messages for relocations that refer to discarded sections. diff --git a/gold/layout.cc b/gold/layout.cc index f690c67618e..8adace07676 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -3277,6 +3277,10 @@ Layout::create_gnu_properties_note() { parameters->target().finalize_gnu_properties(this); + if (parameters->options().memory_seal()) + this->add_gnu_property(elfcpp::NT_GNU_PROPERTY_TYPE_0, + elfcpp::GNU_PROPERTY_MEMORY_SEAL, 0, 0); + if (this->gnu_properties_.empty()) return; diff --git a/gold/options.h b/gold/options.h index 4eb3678e9ec..441ba98acd7 100644 --- a/gold/options.h +++ b/gold/options.h @@ -1546,6 +1546,9 @@ class General_options N_("Keep .text.hot, .text.startup, .text.exit and .text.unlikely " "as separate sections in the final binary."), N_("Merge all .text.* prefix sections.")); + DEFINE_bool(memory_seal, options::DASH_Z, '\0', false, + N_("Mark object be memory sealed"), + N_("Don't mark oject to be memory sealed")); public: diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 8f158ba20cc..f6eddea65fd 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -4476,3 +4476,22 @@ package_metadata_test.o: package_metadata_main.c package_metadata_test$(EXEEXT): package_metadata_test.o gcctestdir/ld $(CXXLINK) package_metadata_test.o -Wl,--package-metadata='{"foo":"bar"}' $(TEST_READELF) --notes $@ | grep -q '{"foo":"bar"}' + +check_SCRIPTS += memory_seal_test.sh +check_DATA += memory_seal_test_1.stdout memory_seal_test_2.stdout +MOSTLYCLEANFILES += memory_seal_test +memory_seal_test_1.stdout: memory_seal_main + $(TEST_READELF) -n $< >$@ +memory_seal_test_2.stdout: memory_seal_shared.so + $(TEST_READELF) -n $< >$@ +memory_seal_main: gcctestdir/ld memory_seal_main.o + gcctestdir/ld -z memory-seal -o $@ memory_seal_main.o +memory_seal_main.o: memory_seal_main.c + $(COMPILE) -c -o $@ $< +memory_seal_shared.so: gcctestdir/ld memory_seal_shared.o + gcctestdir/ld -z memory-seal -shared -o $@ memory_seal_shared.o +memory_seal_shared.o: memory_seal_shared.c + $(COMPILE) -c -fPIC -o $@ $< + + + diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 357dec0d4f9..e95e8ed5d08 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -2888,7 +2888,7 @@ MOSTLYCLEANFILES = *.so *.syms *.stdout *.stderr $(am__append_4) \ $(am__append_88) $(am__append_91) $(am__append_93) \ $(am__append_102) $(am__append_105) $(am__append_108) \ $(am__append_111) $(am__append_114) $(am__append_117) \ - $(am__append_120) $(am__append_121) + $(am__append_120) $(am__append_121) memory_seal_test # We will add to these later, for each individual test. Note # that we add each test under check_SCRIPTS or check_PROGRAMS; @@ -2901,7 +2901,7 @@ check_SCRIPTS = $(am__append_2) $(am__append_21) $(am__append_25) \ $(am__append_89) $(am__append_96) $(am__append_100) \ $(am__append_103) $(am__append_106) $(am__append_109) \ $(am__append_112) $(am__append_115) $(am__append_118) \ - $(am__append_122) + $(am__append_122) memory_seal_test.sh check_DATA = $(am__append_3) $(am__append_22) $(am__append_26) \ $(am__append_32) $(am__append_38) $(am__append_45) \ $(am__append_50) $(am__append_54) $(am__append_58) \ @@ -2910,7 +2910,8 @@ check_DATA = $(am__append_3) $(am__append_22) $(am__append_26) \ $(am__append_90) $(am__append_97) $(am__append_101) \ $(am__append_104) $(am__append_107) $(am__append_110) \ $(am__append_113) $(am__append_116) $(am__append_119) \ - $(am__append_123) + $(am__append_123) memory_seal_test_1.stdout \ + memory_seal_test_2.stdout BUILT_SOURCES = $(am__append_42) TESTS = $(check_SCRIPTS) $(check_PROGRAMS) @@ -6524,6 +6525,13 @@ retain.sh.log: retain.sh --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +memory_seal_test.sh.log: memory_seal_test.sh + @p='memory_seal_test.sh'; \ + b='memory_seal_test.sh'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) object_unittest.log: object_unittest$(EXEEXT) @p='object_unittest$(EXEEXT)'; \ b='object_unittest'; \ @@ -10524,6 +10532,18 @@ package_metadata_test.o: package_metadata_main.c package_metadata_test$(EXEEXT): package_metadata_test.o gcctestdir/ld $(CXXLINK) package_metadata_test.o -Wl,--package-metadata='{"foo":"bar"}' $(TEST_READELF) --notes $@ | grep -q '{"foo":"bar"}' +memory_seal_test_1.stdout: memory_seal_main + $(TEST_READELF) -n $< >$@ +memory_seal_test_2.stdout: memory_seal_shared.so + $(TEST_READELF) -n $< >$@ +memory_seal_main: gcctestdir/ld memory_seal_main.o + gcctestdir/ld -z memory-seal -o $@ memory_seal_main.o +memory_seal_main.o: memory_seal_main.c + $(COMPILE) -c -o $@ $< +memory_seal_shared.so: gcctestdir/ld memory_seal_shared.o + gcctestdir/ld -z memory-seal -shared -o $@ memory_seal_shared.o +memory_seal_shared.o: memory_seal_shared.c + $(COMPILE) -c -fPIC -o $@ $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/gold/testsuite/memory_seal_main.c b/gold/testsuite/memory_seal_main.c new file mode 100644 index 00000000000..77bc677e8eb --- /dev/null +++ b/gold/testsuite/memory_seal_main.c @@ -0,0 +1,5 @@ +int +main(void) +{ + return 0; +} diff --git a/gold/testsuite/memory_seal_shared.c b/gold/testsuite/memory_seal_shared.c new file mode 100644 index 00000000000..8cf7b6143da --- /dev/null +++ b/gold/testsuite/memory_seal_shared.c @@ -0,0 +1,7 @@ +int foo (void); + +int +foo(void) +{ + return 0; +} diff --git a/gold/testsuite/memory_seal_test.sh b/gold/testsuite/memory_seal_test.sh new file mode 100755 index 00000000000..c2194213445 --- /dev/null +++ b/gold/testsuite/memory_seal_test.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# memory_seal_test.sh -- test GNU_PROPERTY_MEMORY_SEAL gnu property + +# Copyright (C) 2018-2024 Free Software Foundation, Inc. + +# This file is part of gold. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +# This script checks that after linking the three object files +# gnu_property_[abc].S, each of which contains a .note.gnu.property +# section, the resulting output has only a single such note section, +# and that the properties have been correctly combined. + +check() +{ + if ! grep -q "$2" "$1" + then + echo "Did not find expected output in $1:" + echo " $2" + echo "" + echo "Actual output below:" + cat "$1" + exit 1 + fi +} + +check memory_seal_test_1.stdout "memory seal" +check memory_seal_test_2.stdout "memory seal" + +exit 0