mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-07-18 11:49:10 +08:00
PR25662, invalid sh_offset for first section in segment with phdrs
PR 25662 * elf.c (assign_file_positions_for_load_sections): Adjust offset for SHT_NOBITS section if first in segment.
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2020-03-25 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
|
PR 25662
|
||||||
|
* elf.c (assign_file_positions_for_load_sections): Adjust offset
|
||||||
|
for SHT_NOBITS section if first in segment.
|
||||||
|
|
||||||
2020-03-24 H.J. Lu <hongjiu.lu@intel.com>
|
2020-03-24 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
PR binutils/25708
|
PR binutils/25708
|
||||||
|
24
bfd/elf.c
24
bfd/elf.c
@ -5833,10 +5833,11 @@ assign_file_positions_for_load_sections (bfd *abfd,
|
|||||||
}
|
}
|
||||||
p->p_memsz += adjust;
|
p->p_memsz += adjust;
|
||||||
|
|
||||||
if (this_hdr->sh_type != SHT_NOBITS)
|
if (p->p_type == PT_LOAD)
|
||||||
{
|
{
|
||||||
if (p->p_type == PT_LOAD)
|
if (this_hdr->sh_type != SHT_NOBITS)
|
||||||
{
|
{
|
||||||
|
off_adjust = 0;
|
||||||
if (p->p_filesz + adjust < p->p_memsz)
|
if (p->p_filesz + adjust < p->p_memsz)
|
||||||
{
|
{
|
||||||
/* We have a PROGBITS section following NOBITS ones.
|
/* We have a PROGBITS section following NOBITS ones.
|
||||||
@ -5846,10 +5847,25 @@ assign_file_positions_for_load_sections (bfd *abfd,
|
|||||||
if (!write_zeros (abfd, off, adjust))
|
if (!write_zeros (abfd, off, adjust))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
off += adjust;
|
|
||||||
}
|
}
|
||||||
p->p_filesz += adjust;
|
/* We only adjust sh_offset in SHT_NOBITS sections
|
||||||
|
as would seem proper for their address when the
|
||||||
|
section is first in the segment. sh_offset
|
||||||
|
doesn't really have any significance for
|
||||||
|
SHT_NOBITS anyway, apart from a notional position
|
||||||
|
relative to other sections. Historically we
|
||||||
|
didn't bother with adjusting sh_offset and some
|
||||||
|
programs depend on it not being adjusted. See
|
||||||
|
pr12921 and pr25662. */
|
||||||
|
if (this_hdr->sh_type != SHT_NOBITS || i == 0)
|
||||||
|
{
|
||||||
|
off += adjust;
|
||||||
|
if (this_hdr->sh_type == SHT_NOBITS)
|
||||||
|
off_adjust += adjust;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (this_hdr->sh_type != SHT_NOBITS)
|
||||||
|
p->p_filesz += adjust;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->p_type == PT_NOTE && bfd_get_format (abfd) == bfd_core)
|
if (p->p_type == PT_NOTE && bfd_get_format (abfd) == bfd_core)
|
||||||
|
Reference in New Issue
Block a user