This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] _bfd_mips_elf_final_link: notify user about wrong .reginfo size
- From: "Maciej W. Rozycki" <macro at mips dot com>
- To: Vlad Ivanov <vlad@ivanov.email>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Tue, 9 Jan 2018 18:33:34 +0000
- Subject: Re: [PATCH] _bfd_mips_elf_final_link: notify user about wrong .reginfo size
- Authentication-results: sourceware.org; auth=none
- References: <20171223164610.11596-1-vlad@ivanov.email> <alpine.DEB.2.00.1801070020500.20647@tp.orcam.me.uk> <260501515480372@web18o.yandex.ru>
Hi Vlad,
> Target used was mipsel-sde-elf. It's triggered when the user-provided linker
> script lacks .reginfo section. In order to fix it, the following line was
> added to the linker script:
>
> .reginfo 0 : { KEEP(*(.reginfo)) }
Thank you for the explanation. While I wasn't able to reproduce the
assertion failure by just having no `.reginfo' section in a linker script
(or having it explicitly removed with a /DISCARD/ clause) I was able to do
so with input that has no `.reginfo' section and this linker script:
SECTIONS
{
.reginfo : { foo = .; }
/DISCARD/ : { *(*) }
}
and also with this linker script:
SECTIONS
{
.reginfo : { *(.data) }
/DISCARD/ : { *(*) }
}
and an oversize input `.data' section. I will convert these examples to
proper test suite cases.
Also with the latter linker script and an undersized `.data' section a
link failure happens with a cryptic:
ld: final link failed: Bad value
error message produced. This is because `bfd_get_section_contents' fails
in `_bfd_mips_elf_final_link' at elfxx-mips.c:14355, however we don't
bother producing a more specific error message, one that would at least
mention the name of the offending section. I think this will have to be
adressed too, with a separate change.
> Since the assertion itself wasn't very self-descriptive, I decided to
> submit a patch for it. I'm not sure if this change needs a test.
No assertion failure is allowed for any input, valid or not. For invalid
input a proper error message has to be printed instead. Assertions are
only allowed as internal consistency checks, essentially situations that
are expected to never happen. So your change is highly desirable as it
improves the quality of error reporting.
> As far as I understand, the issue here is not the input section being
> wrong size (although this may happen too) but rather a total lack
> of such input section, which leads to a creation of zero-sized output
> section.
I can trigger another assertion, in `_bfd_mips_elf_section_processing' at
elfxx-mips.c:7105, which is where input sections are processed, either by
assembling input as simple as:
.section .reginfo, "a"
.word 0xdeadbeef
or by renaming a section to `.reginfo' with `objcopy'. This will have to
be addressed with a separate change (and respective test suite cases).
Maciej