From patchwork Tue Jan 14 16:34:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 857258 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp2010833wrc; Tue, 14 Jan 2025 08:36:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXBmyUhBFAztKtfPsZP48xdCcMPevylUsizkOlqSjbM3vUg5EcGH9fFFHNUqfSI+1ypkOWfMg==@linaro.org X-Google-Smtp-Source: AGHT+IHbph5NUkJ2ATklFHZEI3R2DDHwXDwNUiJyPyR2LLb+uUh1kQeYkFU3abVISOAOY1HfDuIV X-Received: by 2002:a05:6122:458b:b0:518:8bfe:d5f0 with SMTP id 71dfb90a1353d-51c6c2b3d25mr19642072e0c.0.1736872581642; Tue, 14 Jan 2025 08:36:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1736872581; cv=pass; d=google.com; s=arc-20240605; b=X2XKtbXy+FiZqKD1i7XSYAQTetlIhQUggziXxuaOnrFLAWGNlyWP1e03hDb2uTFsKt Bx6Fcq1Gdhm6lxvAgXe5L9tC95DRH8mqjVypyDKMYdHiM06Eq4G5MwXHRQQaf3jXhYYY +9K+ocU6VAiPrWZnUdcnBz1F7JDxTBrAoTtoCmH5JYZL8ghnpNVJQJrLkcyHt276Zeq7 j6aAsVM6kSyjcR3bWFazOeL1sgAtRtxEPYg8ppEQR60NafkcOXg4nZaOgUKlVtRQi/+2 2L2Iy5PBDyT0WWM7VMCR0OQbC84aM4cdNzc+T3WI68KTBEw1yhU+tVnvSDCL3gRAVx6b aqLA== 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:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=zELVFukgKcjnmyz+6Z5ww0VB8deCfY8ec3Xl2zUOVCI=; fh=lt+ZMB3/oj0VbHgvFzrf68q+2N0gmZ3IX/cxzlwPYAM=; b=iVJwqxJShKYYp65kVi5UeubmBeaq/jAronCYtkeUOgHJpp/ulHEEDtVle89BVuKOkk FRpwUah8QKSuOzK70Vu4aWN4qgmiRby/Dswt+4swRx8WDiBdH1c/TT8VqHSTH2UoPz9H hEklUlbWzdh4iDNF2e28NpJ5aV+wIagJFWKfYeJ6UgNdQQgOANPTlcRFT21R3K8x6Mnj L6U2uja+jNXI7VOSa0rwFLvYef2tsUOB8/1Dqzi29t7ejajq48zSB6kbiHFtJ3EreYBM oW+NCsSLUUUOFtLJptt6QPnyLGDLGjlIZ699sYgDwomWsuU7Mu3/cyDomJCNifQKM5L1 3qeA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v6CUEj4w; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 71dfb90a1353d-51c7fedbae1si4125533e0c.264.2025.01.14.08.36.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 08:36:21 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces~patch=linaro.org@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=@linaro.org header.s=google header.b=v6CUEj4w; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 2CC41385B527 for ; Tue, 14 Jan 2025 16:36:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CC41385B527 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=v6CUEj4w X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by sourceware.org (Postfix) with ESMTPS id 6E283385B515 for ; Tue, 14 Jan 2025 16:34:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E283385B515 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 6E283385B515 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736872487; cv=none; b=bA5U+4zN8FVFv7c8aQ4H/A5CzbHlXkjfMWlXyF4twalplQQ4HM5hwX75qC9fMBA3rmfWrOIWs4RdIPacD5jPlWizc2uIPZxd58YSXs0Z8MFRN2rMOA/RHZcAYXt9LKflkjTLRtWvufHMX0bTDcGIJQM5INdQ+gQLDq2+x9Bx3eo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736872487; c=relaxed/simple; bh=X9LN9id5iKoqo83e7x9ZfphV3DGmt2uu/R2CjXdEcUQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=x4iwEYJPnHeGvcSKil7CzDXceB02uyy5qgQzHv0Lef72Nd/j+diycxnyrgcJstuy39NWlrtiGz/9j4CYKECJILsvqFwUVCG0VZcAUq376NAw0MmUpEsBGiWBlH+S4QkwuTdr7fpLJgx8E6jQgXSYhuzgUL3yQyUy5aCOivQs86M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E283385B515 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5f6ab7e0bd6so2756087eaf.0 for ; Tue, 14 Jan 2025 08:34:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736872486; x=1737477286; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zELVFukgKcjnmyz+6Z5ww0VB8deCfY8ec3Xl2zUOVCI=; b=v6CUEj4wgMNlQt1vRB8F0kBDquUvedyStLGjmNu7P85sEV1lbl6x4MVhX3rycwGLNz bm7uB5Pfk9R1CPkTRmWon8PV4enHJutZYHCAwWhXmqKuZqFBtTiedRmaXu7p+qbssJ5F NcvM//spco8O0hjBSAHYCqi5U66PenYR6E/+b4GFJsEOfbh2y5S+sPpJ4HiA5uewgNAq dMpYRp7WKABrSYB6dWF0hLJhlmmxvYPv41jseA0u0M3Bivv4+saFbAhn4A+/uN2WSQT2 Vx8WCzsYZpF22f/pDLufpmgbS1yK+UDde7/NvPvZa18EmkSyb/uRszBh87xQBzTsXlbd Y8zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736872486; x=1737477286; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zELVFukgKcjnmyz+6Z5ww0VB8deCfY8ec3Xl2zUOVCI=; b=lQXG2EWDfoturChklUywPFRbAWDNfMf/rUdhkOTbKlMypFZJSDEyWpJZkzpfvt8g03 7RJgNGowYa5qtrvnKgUJcntI2kUj/bT+yX1fAXglbQSjCLW7arIxwdPdMgLdPfFWdwbB Q/6yd+MjyMidhVuVcpC1En+gZoRbq8kRntOQV9ZQM1CWCif7klLzRXYRa5zEQq9VaoaC dVe1F/2W7vazPTaXZyeeelVBy88eulbCXh8SUxgZkufEdpf5FUTuFZAuS7kjF+AErG1/ BAKslwuVbLo49ltChaQX1Y8Q7Jwxc7VYagEO9cIReA5BHlQTBDHVyoyKAFFgxUz6tw55 KAEw== X-Gm-Message-State: AOJu0YycNkv14245X8LWT+B8XhnpKet6jMcNCJCxpYCcWKxKQyKPiVNX /nUEJQ+xXwNBt8O3lHjlNGTdmo2wUe6AI8GIKGJdoWy45fo7nhEaST7cTtXp5jZWCWZ6Ofpw18X 2 X-Gm-Gg: ASbGnctWdONL7FILy6Cnk9WDfrVRw5M8KPFOf5XDLXVkNCUEdbTA+kE9f0z70Tq9CNR 94OKGu02EGHPvqNGCtK6FnOk8P+x4m9EWpDYYxE9VrWP4/LK7aZYDnRjUk8gm101xBwPwAlQ9ZK dg/2tkIMtr//J5wnU8wjWGq58VNLYGxb3UuJVf2cnZHYp2jDRwj4ij3FEqy7rslCOoJnSOvaN88 xx/+SJrB7APIhNh4h7PoJWNTal7mvhv88/hRYZ/yzI+zidDw4hUdQy1Ocio3M6wnOtK8Q== X-Received: by 2002:a05:6870:6b0a:b0:29e:70c7:a3f7 with SMTP id 586e51a60fabf-2aa065118b7mr15996376fac.4.1736872486202; Tue, 14 Jan 2025 08:34:46 -0800 (PST) Received: from ubuntu-vm.. ([191.23.120.207]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2ad804afe70sm5194986fac.6.2025.01.14.08.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 08:34:45 -0800 (PST) From: Adhemerval Zanella To: binutils@sourceware.org Cc: "H . J . Lu" Subject: [PATCH v6] gold: Add GNU_PROPERTY_MEMORY_SEAL gnu property Date: Tue, 14 Jan 2025 13:34:24 -0300 Message-ID: <20250114163441.2071464-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 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 Changes from v5: * Add more tests. --- elfcpp/elfcpp.h | 1 + gold/NEWS | 3 ++ gold/layout.cc | 4 ++ gold/options.h | 3 ++ gold/testsuite/Makefile.am | 24 ++++++++++++ gold/testsuite/Makefile.in | 42 +++++++++++++++++--- gold/testsuite/memory_seal_main.c | 5 +++ gold/testsuite/memory_seal_shared.c | 7 ++++ gold/testsuite/memory_seal_test.sh | 60 +++++++++++++++++++++++++++++ gold/testsuite/property_seal_1.S | 22 +++++++++++ 10 files changed, 165 insertions(+), 6 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 create mode 100644 gold/testsuite/property_seal_1.S 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..0de31e287aa 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -4384,6 +4384,30 @@ MOSTLYCLEANFILES += split_s390_z1 split_s390_z2 split_s390_z3 \ endif DEFAULT_TARGET_S390 +check_SCRIPTS += memory_seal_test.sh +check_DATA += memory_seal_test_1.stdout memory_seal_test_2.stdout \ + memory_seal_test_3.stdout memory_seal_test_4.stdout +MOSTLYCLEANFILES += memory_seal_test +memory_seal_test_1.stdout: memory_seal_main_1 + $(TEST_READELF) -n $< >$@ +memory_seal_test_2.stdout: memory_seal_shared_1.so + $(TEST_READELF) -n $< >$@ +memory_seal_test_3.stdout: memory_seal_main_2 + $(TEST_READELF) -n $< >$@ +memory_seal_test_4.stdout: memory_seal_shared_2.so + $(TEST_READELF) -n $< >$@ +memory_seal_main_1: gcctestdir/ld memory_seal_main.o property_seal_1.o + gcctestdir/ld -o $@ memory_seal_main.o +memory_seal_main_2: gcctestdir/ld memory_seal_main.o property_seal_1.o + gcctestdir/ld -z memory-seal -o $@ memory_seal_main.o property_seal_1.o +memory_seal_shared_1.so: gcctestdir/ld memory_seal_shared.o property_seal_1.o + gcctestdir/ld -shared -o $@ memory_seal_shared.o +memory_seal_shared_2.so: gcctestdir/ld memory_seal_shared.o property_seal_1.o + gcctestdir/ld -zmemory-seal -shared -o $@ memory_seal_shared.o property_seal_1.o +property_seal_1.o: property_seal_1.S + $(COMPILE) -c -o $@ $< + + endif NATIVE_OR_CROSS_LINKER # Tests for the dwp tool. diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 357dec0d4f9..1eeab03b411 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -1138,11 +1138,16 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @DEFAULT_TARGET_S390_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ split_s390x_z1_ns split_s390x_z2_ns split_s390x_z3_ns \ @DEFAULT_TARGET_S390_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ split_s390x_z4_ns split_s390x_n1_ns split_s390x_n2_ns split_s390x_r -@DEFAULT_TARGET_X86_64_TRUE@am__append_121 = *.dwo *.dwp pr26936a \ +@NATIVE_OR_CROSS_LINKER_TRUE@am__append_121 = memory_seal_test.sh +@NATIVE_OR_CROSS_LINKER_TRUE@am__append_122 = memory_seal_test_1.stdout memory_seal_test_2.stdout \ +@NATIVE_OR_CROSS_LINKER_TRUE@ memory_seal_test_3.stdout memory_seal_test_4.stdout + +@NATIVE_OR_CROSS_LINKER_TRUE@am__append_123 = memory_seal_test +@DEFAULT_TARGET_X86_64_TRUE@am__append_124 = *.dwo *.dwp pr26936a \ @DEFAULT_TARGET_X86_64_TRUE@ pr26936b retain_1 retain_2 -@DEFAULT_TARGET_X86_64_TRUE@am__append_122 = dwp_test_1.sh \ +@DEFAULT_TARGET_X86_64_TRUE@am__append_125 = dwp_test_1.sh \ @DEFAULT_TARGET_X86_64_TRUE@ dwp_test_2.sh pr26936.sh retain.sh -@DEFAULT_TARGET_X86_64_TRUE@am__append_123 = dwp_test_1.stdout \ +@DEFAULT_TARGET_X86_64_TRUE@am__append_126 = dwp_test_1.stdout \ @DEFAULT_TARGET_X86_64_TRUE@ dwp_test_2.stdout pr26936a.stdout \ @DEFAULT_TARGET_X86_64_TRUE@ pr26936b.stdout retain_1.out \ @DEFAULT_TARGET_X86_64_TRUE@ retain_2.out @@ -2888,7 +2893,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_123) $(am__append_124) # We will add to these later, for each individual test. Note # that we add each test under check_SCRIPTS or check_PROGRAMS; @@ -2901,7 +2906,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_121) $(am__append_125) 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 +2915,7 @@ 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_122) $(am__append_126) BUILT_SOURCES = $(am__append_42) TESTS = $(check_SCRIPTS) $(check_PROGRAMS) @@ -6496,6 +6501,13 @@ split_s390.sh.log: split_s390.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) dwp_test_1.sh.log: dwp_test_1.sh @p='dwp_test_1.sh'; \ b='dwp_test_1.sh'; \ @@ -10454,6 +10466,24 @@ uninstall-am: @DEFAULT_TARGET_S390_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_OBJDUMP) -d $< > $@ @DEFAULT_TARGET_S390_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@split_s390x_r.stdout: split_s390x_1_z1.o split_s390x_2_ns.o ../ld-new @DEFAULT_TARGET_S390_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ ../ld-new -r split_s390x_1_z1.o split_s390x_2_ns.o -o split_s390x_r > $@ 2>&1 || exit 0 +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_test_1.stdout: memory_seal_main_1 +@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_READELF) -n $< >$@ +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_test_2.stdout: memory_seal_shared_1.so +@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_READELF) -n $< >$@ +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_test_3.stdout: memory_seal_main_2 +@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_READELF) -n $< >$@ +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_test_4.stdout: memory_seal_shared_2.so +@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_READELF) -n $< >$@ +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_main_1: gcctestdir/ld memory_seal_main.o property_seal_1.o +@NATIVE_OR_CROSS_LINKER_TRUE@ gcctestdir/ld -o $@ memory_seal_main.o +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_main_2: gcctestdir/ld memory_seal_main.o property_seal_1.o +@NATIVE_OR_CROSS_LINKER_TRUE@ gcctestdir/ld -z memory-seal -o $@ memory_seal_main.o property_seal_1.o +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_shared_1.so: gcctestdir/ld memory_seal_shared.o property_seal_1.o +@NATIVE_OR_CROSS_LINKER_TRUE@ gcctestdir/ld -shared -o $@ memory_seal_shared.o +@NATIVE_OR_CROSS_LINKER_TRUE@memory_seal_shared_2.so: gcctestdir/ld memory_seal_shared.o property_seal_1.o +@NATIVE_OR_CROSS_LINKER_TRUE@ gcctestdir/ld -zmemory-seal -shared -o $@ memory_seal_shared.o property_seal_1.o +@NATIVE_OR_CROSS_LINKER_TRUE@property_seal_1.o: property_seal_1.S +@NATIVE_OR_CROSS_LINKER_TRUE@ $(COMPILE) -c -o $@ $< # Tests for the dwp tool. # We don't want to rely yet on GCC support for -gsplit-dwarf, 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..91aa2abf9b4 --- /dev/null +++ b/gold/testsuite/memory_seal_test.sh @@ -0,0 +1,60 @@ +#!/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_not() +{ + if grep -q "$2" "$1" + then + echo "Found unexpected output in $1:" + echo " $2" + echo "" + echo "Actual output below:" + cat "$1" + exit 1 + fi +} + +check_not memory_seal_test_1.stdout "memory seal" +check_not memory_seal_test_2.stdout "memory seal" +check memory_seal_test_3.stdout "memory seal" +check memory_seal_test_4.stdout "memory seal" + +exit 0 diff --git a/gold/testsuite/property_seal_1.S b/gold/testsuite/property_seal_1.S new file mode 100644 index 00000000000..346f734edd2 --- /dev/null +++ b/gold/testsuite/property_seal_1.S @@ -0,0 +1,22 @@ +#define GNU_PROPERTY_MEMORY_SEAL 3 + +#define NT_GNU_PROPERTY_TYPE_0 5 + +#if __SIZEOF_PTRDIFF_T__ == 8 +# define ALIGN 3 +#elif __SIZEOF_PTRDIFF_T__ == 4 +# define ALIGN 2 +#endif + + .section ".note.gnu.property", "a" + .p2align ALIGN + + .long 1f - 0f /* name length */ + .long 3f - 2f /* data length */ + .long NT_GNU_PROPERTY_TYPE_0 /* note type */ +0: .asciz "GNU" /* vendor name */ +1: + .p2align ALIGN +2: .long GNU_PROPERTY_MEMORY_SEAL /* pr_type. */ + .long 0 /* pr_datasz. */ +3: