From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 8211D385800A for ; Thu, 16 Mar 2023 10:17:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8211D385800A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x336.google.com with SMTP id m18-20020a05600c3b1200b003ed2a3d635eso695769wms.4 for ; Thu, 16 Mar 2023 03:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1678961868; 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=57qp1MwyV8zL/v+Fg3v3GSnjUjCMYrSz4KjNk/cdWmY=; b=DPa52EjwHCGqCU8yFnRrQo+GY0racv8ESyq7ySrypTJzrusrwLNZaMe0DN4NDGdAdg wDS6Be+JOuwujRHw6JW/bTZggJITg9ZzO5HDqeBSYC2/g1fC8U5D78Ed3f/V/MniB5Gr A9d/IRHKUpDvT/rBNHKfxzqf/S0S28IaLbhuLJ0uGlcKkFgquV72YydHr3yVFDGQMW0z WhJFx7CBtjVTDTtbOeHkFx9uBwFAiHDUv972IET2p8YkjkkEWjWl2Y2gd+/QDVki8UwE 604fmkQP5lyoVHxE9PFyZrS14XEfskiP4lueG/6DcPuLbYPrUUfthJaNMbPSsOMsYbZ9 Uo1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678961868; 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=57qp1MwyV8zL/v+Fg3v3GSnjUjCMYrSz4KjNk/cdWmY=; b=bqRa8yBh4amcYstt0cxq2KWOrVW+VhncVl36qnRJf2ejZLbVDuk2OcB2Pk41Wh4BVP bFefAmT3Ub4EakBP1U5C56nqII1N/GWdoovsZGWvSXvToSF20e+yCmb0kdGUZquuekuv 5U+JtiTUQ3xqQHo8eNer8BUp9pQwqGtGNUasinHkAelcNqjZY6STLz8fpCep+kcVZ9AS 9OiuzJXnTIQoAjibayPu9nmoHITY49KHF5O6wmcpBH65/NNOmQmNz88qv1NZb2zy4U6Q 9/nghGHJt7KtNg3oDiakWTEkVT6KttHP1WLiP/chlfFM8BVsCpjjl0UWygkBNyRjAslO yWKQ== X-Gm-Message-State: AO0yUKWxDLy6PCA2ebNGSVEco3LzWDezVdZBGn4S1kcROiZcxJZPSTwF 2GFVEKAnxxgGqMyqRrqECxgxMYX6elHfrpaZSHo= X-Google-Smtp-Source: AK7set9VVPqORoVKsrj+CLr5PBK2t3PkdvpgOBCj6N6MubcqjdO5Ap8pQmmvKHXWjhnBFweg0zTmhQ== X-Received: by 2002:a05:600c:c06:b0:3e1:feb9:5a33 with SMTP id fm6-20020a05600c0c0600b003e1feb95a33mr20821955wmb.9.1678961868026; Thu, 16 Mar 2023 03:17:48 -0700 (PDT) Received: from chigot-Dell.home ([2a01:cb15:8123:8100:ae34:31dc:b564:f3da]) by smtp.gmail.com with ESMTPSA id t10-20020a05600c450a00b003e7c89b3514sm4592563wmo.23.2023.03.16.03.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 03:17:47 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= To: binutils@sourceware.org Cc: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Subject: [PATCH 3/5] ld: add support of QNX stack arguments for aarch64nto Date: Thu, 16 Mar 2023 11:17:34 +0100 Message-Id: <20230316101736.482737-4-chigot@adacore.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230316101736.482737-1-chigot@adacore.com> References: <20230316101736.482737-1-chigot@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: QNX is handling the stack argument using a .note section. Generate it according to ELF argument -zexecstack, -zstack-size and a new NTO argument --lazy-stack. Another NTO argument --stack mimicking -zstack-size is added in order to ensure compatibility with previously made NTO linkers. This requires a new emultempl nto.em which is applied above the default ${ARCH}elf.em. ld/ChangeLog: * emulparams/aarch64nto.sh: Move to nto.em. * emultempl/nto.em: New file. * testsuite/ld-aarch64/aarch64-nto.exp: New test. * testsuite/ld-aarch64/nto-stack-note-1.d: New test. * testsuite/ld-aarch64/nto-stack-note-2.d: New test. * testsuite/ld-aarch64/start.s: New test. --- ld/emulparams/aarch64nto.sh | 2 +- ld/emultempl/nto.em | 163 +++++++++++++++++++++ ld/testsuite/ld-aarch64/aarch64-nto.exp | 28 ++++ ld/testsuite/ld-aarch64/nto-stack-note-1.d | 12 ++ ld/testsuite/ld-aarch64/nto-stack-note-2.d | 12 ++ ld/testsuite/ld-aarch64/start.s | 4 + 6 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 ld/emultempl/nto.em create mode 100644 ld/testsuite/ld-aarch64/aarch64-nto.exp create mode 100644 ld/testsuite/ld-aarch64/nto-stack-note-1.d create mode 100644 ld/testsuite/ld-aarch64/nto-stack-note-2.d create mode 100644 ld/testsuite/ld-aarch64/start.s diff --git a/ld/emulparams/aarch64nto.sh b/ld/emulparams/aarch64nto.sh index 4f0657def55..5138e335ccc 100644 --- a/ld/emulparams/aarch64nto.sh +++ b/ld/emulparams/aarch64nto.sh @@ -10,7 +10,7 @@ LITTLE_OUTPUT_FORMAT="elf64-littleaarch64" NO_REL_RELOCS=yes TEMPLATE_NAME=elf -EXTRA_EM_FILE=aarch64elf +EXTRA_EM_FILE=nto GENERATE_SHLIB_SCRIPT=yes GENERATE_PIE_SCRIPT=yes diff --git a/ld/emultempl/nto.em b/ld/emultempl/nto.em new file mode 100644 index 00000000000..b38fddd251c --- /dev/null +++ b/ld/emultempl/nto.em @@ -0,0 +1,163 @@ +# This shell script emits a C file. -*- C -*- +# Copyright 2023 Free Software Foundation, Inc. +# +# This file is part of GLD, the Gnu Linker. +# +# 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 2 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 file is sourced from elf.em, and defines extra Neutrino +# specific routines. + +# NTO templates aims to refine the default ${ARCH}elf.em template. +. "${srcdir}/emultempl/${ARCH}elf.em" + +cat >>e${EMULATION_NAME}.c <\n")); + return; + } + + flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS + | SEC_IN_MEMORY | SEC_LINKER_CREATED); + note_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd, ".note", flags); + if (! note_sec) + { + einfo (_("%F%P: failed to create .note section\n")); + return; + } + + size = offsetof (Elf_External_Note, name[sizeof "QNX"]); + size = (size + 3) & -(bfd_size_type) 4; + h_size = size; + size += sizeof (struct nto_stack_note); + note_sec->size = size; + + elf_section_type (note_sec) = SHT_NOTE; + note_sec->contents = xmalloc (note_sec->size); + e_note = (Elf_External_Note *) note_sec->contents; + bfd_h_put_32 (stub_file->the_bfd, sizeof "QNX", &e_note->namesz); + bfd_h_put_32 (stub_file->the_bfd, sizeof (struct nto_stack_note), &e_note->descsz); + bfd_h_put_32 (stub_file->the_bfd, QNT_STACK, &e_note->type); + memcpy (e_note->name, "QNX", sizeof "QNX"); + + + /* Generate .note content.*/ + n_note = (struct nto_stack_note *) (note_sec->contents + h_size); + bfd_h_put_32 (stub_file->the_bfd, link_info.stacksize, &n_note->stacksize); + + if (nto_lazy_stack) + bfd_h_put_32 (stub_file->the_bfd, 4096, &n_note->stackalloc); + else + bfd_h_put_32 (stub_file->the_bfd, link_info.stacksize, &n_note->stackalloc); + + if (link_info.execstack != link_info.noexecstack && link_info.execstack) + bfd_h_put_32 (stub_file->the_bfd, 0, &n_note->execstack); + else + bfd_h_put_32 (stub_file->the_bfd, 1, &n_note->execstack); + +} + +static void +nto_create_output_section_statements (void) +{ + ${ARCH}_elf_create_output_section_statements (); + nto_add_note_section(); +} + +EOF + +# Define some shell vars to insert bits of code into the standard elf +# parse_args and list_options functions. +# + +PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}' +enum nto_options +{ + OPTION_STACK = 500, + OPTION_LAZY_STACK, +}; +' + +PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' + { "stack", required_argument, NULL, OPTION_STACK }, + { "lazy-stack", no_argument, NULL, OPTION_LAZY_STACK }, +' + +PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}' + fprintf (file, _("\ + --stack Set size of the initial stack\n\ + --lazy-stack Set lazy allocation of stack\n\ +")); +' + +PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' + case OPTION_STACK: + { + char *end; + link_info.stacksize = strtoul (optarg, &end, 0); + if (*end || link_info.stacksize < 0) + einfo (_("%F%P: invalid stack size `%s'\''\n"), optarg + 11); + if (!link_info.stacksize) + /* Use -1 for explicit no-stack, because zero means + 'default'. */ + link_info.stacksize = -1; + break; + } + case OPTION_LAZY_STACK: + nto_lazy_stack = true; + break; +' + +# Put these extra Neutrino routines in ld_${EMULATION_NAME}_emulation +# + +LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=nto_create_output_section_statements diff --git a/ld/testsuite/ld-aarch64/aarch64-nto.exp b/ld/testsuite/ld-aarch64/aarch64-nto.exp new file mode 100644 index 00000000000..4fd6245e9a2 --- /dev/null +++ b/ld/testsuite/ld-aarch64/aarch64-nto.exp @@ -0,0 +1,28 @@ + +# Expect script for various AARCH64 NTO tests. +# Copyright (C) 2009-2022 Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# 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. + +# Exclude non-aarch64-NTO targets. +if { ![istarget "aarch64*-*-nto*"] } { + return +} + +run_dump_test "nto-stack-note-1" +run_dump_test "nto-stack-note-2" diff --git a/ld/testsuite/ld-aarch64/nto-stack-note-1.d b/ld/testsuite/ld-aarch64/nto-stack-note-1.d new file mode 100644 index 00000000000..d85dbcadb6b --- /dev/null +++ b/ld/testsuite/ld-aarch64/nto-stack-note-1.d @@ -0,0 +1,12 @@ +#name: nto-stack-note-1 +#source: start.s +#as: +#ld: -z stack-size=0x10000 +#readelf: -n + +Displaying notes found in: .note +[ ]+Owner[ ]+Data size[ ]+Description + QNX 0x0000000c QNX stack + Stack Size: 0x10000 + Stack allocated: 10000 + Executable: no diff --git a/ld/testsuite/ld-aarch64/nto-stack-note-2.d b/ld/testsuite/ld-aarch64/nto-stack-note-2.d new file mode 100644 index 00000000000..9e446ccea5c --- /dev/null +++ b/ld/testsuite/ld-aarch64/nto-stack-note-2.d @@ -0,0 +1,12 @@ +#name: nto-stack-note-2 +#source: start.s +#as: +#ld: -z stack-size=0x10000 --lazy-stack -z execstack +#readelf: -n + +Displaying notes found in: .note +[ ]+Owner[ ]+Data size[ ]+Description + QNX 0x0000000c QNX stack + Stack Size: 0x10000 + Stack allocated: 1000 + Executable: yes diff --git a/ld/testsuite/ld-aarch64/start.s b/ld/testsuite/ld-aarch64/start.s new file mode 100644 index 00000000000..58d42a60324 --- /dev/null +++ b/ld/testsuite/ld-aarch64/start.s @@ -0,0 +1,4 @@ + .global _start + .text +_start: + nop -- 2.25.1