This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: Specifying LMA's after unallocated sections?
Ian Lance Taylor wrote:
>
> Date: Thu, 06 Apr 2000 23:31:43 +0100
> From: Jonathan Larmour <jlarmour@redhat.co.uk>
>
> I was thinking of some way to avoid outputting the section regardless.
> Suppose for example you want to put .bar after .rel.* relocation
> information. I know (because I accidentally stumbled across it) that
> outputting an empty .rel section makes BFD very unhappy. And to be honest,
> I think BFD is right: you shouldn't be emitting "unused" empty output
> sections in general.
>
> The only way that comes to mind would be to use memory regions with
> the new AT> construct. Then you could avoid using LOADADDR and
> SIZEOF. I can't think of any other way to implicitly define the load
> address, which is basically what you want to do.
Ah, now that is new and useful. I think I can abuse that in exactly the way
I want. Thanks!
> By the way, an empty .rel section should work fine. If it fails, I
> think that is a bug.
In that case, perhaps the attached trivial patch is required?
Without it, if you put a ". = ." in e.g. a .rela.text section of a
mips-tx39-elf target linker script defining no actual relocation info, then
you get a BFD assertion failure in bfd_section_from_elf_index(), called
from bfd_section_from_shdr(). This is triggered because of an index of 0
being passed to bfd_section_from_elf_index(). But there's nothing wrong
with an index of 0 AFAIK, so the assert is wrong.
However, even with that fixed, objdump reports "File format not
recognized". I don't know for sure whether the correct behaviour should be
just to ignore empty .rel/.rela sections completely if they are empty, but
it seems reasonable so that's what I suggest.
Jifl
2000-04-07 Jonathan Larmour <jlarmour@redhat.co.uk>
* elf.c (bfd_section_from_shdr): Ignore empty SHT_REL/SHT_RELA
sections
(bfd_section_from_elf_index): Don't assert on an index of 0
--
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow." || These opinions are all my own fault
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.27
diff -u -5 -p -r1.27 elf.c
--- elf.c 2000/03/27 08:39:12 1.27
+++ elf.c 2000/04/06 23:52:36
@@ -1277,10 +1277,14 @@ bfd_section_from_shdr (abfd, shindex)
/* *These* do a lot of work -- but build no sections! */
{
asection *target_sect;
Elf_Internal_Shdr *hdr2;
+ /* Check for empty section - if so, throw it away */
+ if (hdr->sh_size == 0)
+ return true;
+
/* Check for a bogus link to avoid crashing. */
if (hdr->sh_link >= ehdr->e_shnum)
{
((*_bfd_error_handler)
(_("%s: invalid link %lu for reloc section %s (index %u)"),
@@ -1400,11 +1404,11 @@ bfd_section_from_shdr (abfd, shindex)
asection *
bfd_section_from_elf_index (abfd, index)
bfd *abfd;
unsigned int index;
{
- BFD_ASSERT (index > 0 && index < SHN_LORESERVE);
+ BFD_ASSERT (index < SHN_LORESERVE);
if (index >= elf_elfheader (abfd)->e_shnum)
return NULL;
return elf_elfsections (abfd)[index]->bfd_section;
}