This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Special ELF section flags vs. linker-specified bfd flags
- From: Richard Sandiford <richard at codesourcery dot com>
- To: binutils at sourceware dot org
- Date: Wed, 18 Oct 2006 11:15:32 +0100
- Subject: Special ELF section flags vs. linker-specified bfd flags
There seems to be a bad interaction between:
bfd/
2006-04-26 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/2593
* elf.c (_bfd_elf_new_section_hook): Don't set section ELF type
and flags if its BFD flags have been set.
(_bfd_elf_init_private_section_data): Don't copy the output ELF
section type from input if it has been set to something
different.
and:
ld/
2006-08-01 H.J. Lu <hongjiu.lu@intel.com>
* ldlang.c (init_os): Add flags. Replace bfd_make_section with
bfd_make_section_with_flags.
(exp_init_os): Updated.
(lang_add_section): Call init_os with flags.
(map_input_to_output_sections): Likewise.
The _bfd_elf_new_section_hook hunk was:
bed = get_elf_backend_data (abfd);
sec->use_rela_p = bed->default_use_rela_p;
- /* When we read a file, we don't need section type and flags unless
- it is a linker created section. They will be overridden in
- _bfd_elf_make_section_from_shdr anyway. */
- if (abfd->direction != read_direction
+ /* When we read a file or section BFD flags have been set, we don't
+ need section type and flags unless it is a linker created section.
+ They will be overridden in _bfd_elf_make_section_from_shdr
+ anyway. */
+ if ((!sec->flags && abfd->direction != read_direction)
|| (sec->flags & SEC_LINKER_CREATED) != 0)
{
ssect = (*bed->get_sec_type_attr) (abfd, sec);
but the later linker change makes init_os propagate the input section's
bfd flags to the new output section. We therefore skip the get_sec_type_attr
stuff for normal sections, even though the user hasn't overridden the flags.
This in turn means we miss target-specific SHF_* flags that have no
corresponding bfd section flag.
This caused reloc-1-rel.d and reloc-1-n32.d to fail on MIPS. This loop:
else if (info->relocatable)
{
bfd_vma lo = MINUS_ONE;
/* Find the GP-relative section with the lowest offset. */
for (o = abfd->sections; o != NULL; o = o->next)
if (o->vma < lo
&& (elf_section_data (o)->this_hdr.sh_flags & SHF_MIPS_GPREL))
lo = o->vma;
/* And calculate GP relative to that. */
elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (info);
}
wouldn't see any SHF_MIPS_GPREL sections, and would use -1 as the
GP value.
I think the fix below is in the spirit of HJ's other changes.
Patch tested on mips{,64}{,el}-{elf,linux-gnu} and mips-sgi-irix6.5.
OK to install?
Richard
bfd/
* elf.c (_bfd_elf_init_private_section_data): Copy the ELF section
flags as well as the section type.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.359
diff -u -p -r1.359 elf.c
--- bfd/elf.c 15 Oct 2006 14:22:13 -0000 1.359
+++ bfd/elf.c 18 Oct 2006 10:10:31 -0000
@@ -5954,7 +5954,10 @@ _bfd_elf_init_private_section_data (bfd
section flags. */
if (osec->flags == isec->flags
|| (osec->flags == 0 && elf_section_type (osec) == SHT_NULL))
- elf_section_type (osec) = elf_section_type (isec);
+ {
+ elf_section_type (osec) = elf_section_type (isec);
+ elf_section_flags (osec) = elf_section_flags (isec);
+ }
/* Set things up for objcopy and relocatable link. The output
SHT_GROUP section will have its elf_next_in_group pointing back