# This shell script emits a C file. -*- C -*-
# Copyright (C) 2023-2025 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.
source_em "${srcdir}/emultempl/${ARCH}elf.em"
/* As ${ARCH}elf.em is imported and ${ARCH}_elf_create_output_section_statements
is called before this function, stub_file should already be defined. */
if (!stub_file)
{
fatal (_("%P: cannot create .note section in stub BFD.\n"));
return NULL;
}
/* Lookup for a section holding a QNX note or create a new section. */
static asection*
nto_lookup_QNX_note_section(int type)
{
asection *stack_note_sec = NULL;
bfd *abfd;
bool duplicated_notes_detected = false;
for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
{
Elf_External_Note *e_note;
asection *sec;
/* QNX notes are held under a note section simply named ".note". */
sec = bfd_get_section_by_name (abfd, ".note");
if (!sec)
continue;
/* Verify that this is a QNX note of the expected type. */
sec->contents = xmalloc(sec->size);
if (!bfd_get_section_contents (sec->owner, sec, sec->contents, (file_ptr) 0,
sec->size))
fatal (_("%P: %pB: can't read contents of section .note: %E\n"),
sec->owner);
if (nto_lazy_stack && !link_info.stacksize)
{
fatal (_("%P: error: --lazy-stack must follow -zstack-size=<size>\n"));
return;
}
/* Don't create a note if none of the stack parameter have to be modified. */
if (link_info.stacksize <= 0 && (link_info.execstack == link_info.noexecstack))
return;
note_sec = nto_lookup_QNX_note_section(QNT_STACK);
if (! note_sec)
return;
PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
fprintf (file, _("\
--stack <size> 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)
fatal (_("%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
#