This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: PATCH: Pass section name to elf_backend_section_flags
On Mon, Apr 26, 2004 at 08:29:01AM -0700, H. J. Lu wrote:
> How about this patch?
I did say to make the hdr arg to elf_backend_section_flags const.
There's a good reason to do so.
> --- bfd/elf.c.section 2004-04-26 08:02:32.000000000 -0700
> +++ bfd/elf.c 2004-04-26 08:02:56.000000000 -0700
> @@ -652,6 +652,9 @@ _bfd_elf_make_section_from_shdr (bfd *ab
> if (newsect == NULL)
> return FALSE;
>
> + hdr->bfd_section = newsect;
> + elf_section_data (newsect)->this_hdr = *hdr;
We copy the hdr here, so we'd better make sure that nothing changes hdr
fields later. Marking the pointer const in elf_backend_section_flags
should alert anyone wanting to change hdr fields in
elf_backend_section_flags that doing so is not a good idea.
I've committed the following patch, which also fixes some recent
carelessness. Your sh patch is OK, with the obvious addition of
'const'.
* elf64-alpha.c (elf64_alpha_read_ecoff_info): Don't assign
structure field removed in 2004-04-24 patch.
* elf64-sparc.c (sparc64_elf_plt_sym_val): Warning fix.
* elf-bfd.h (struct elf_backend_data <elf_backend_section_flags>):
Constify hdr arg.
* elf32-arm.h (elf32_arm_section_flags): Likewise.
* elf64-alpha.c (elf64_alpha_section_flags): Likewise.
* elfxx-ia64.c (elfNN_ia64_section_flags): Likewise.
* elf.c (_bfd_elf_make_section_from_shdr): Set the bfd_section
field before calling elf_backend_section_flags.
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.137
diff -u -p -r1.137 elf-bfd.h
--- bfd/elf-bfd.h 22 Apr 2004 14:45:30 -0000 1.137
+++ bfd/elf-bfd.h 27 Apr 2004 03:07:38 -0000
@@ -597,7 +597,7 @@ struct elf_backend_data
/* A function to convert machine dependent section header flags to
BFD internal section header flags. */
bfd_boolean (*elf_backend_section_flags)
- (flagword *, Elf_Internal_Shdr *);
+ (flagword *, const Elf_Internal_Shdr *);
/* A function to handle unusual program segment types when creating BFD
sections from ELF program segments. */
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.221
diff -u -p -r1.221 elf.c
--- bfd/elf.c 22 Apr 2004 14:45:31 -0000 1.221
+++ bfd/elf.c 27 Apr 2004 03:07:40 -0000
@@ -652,6 +652,9 @@ _bfd_elf_make_section_from_shdr (bfd *ab
if (newsect == NULL)
return FALSE;
+ hdr->bfd_section = newsect;
+ elf_section_data (newsect)->this_hdr = *hdr;
+
/* Always use the real type/flags. */
elf_section_type (newsect) = hdr->sh_type;
elf_section_flags (newsect) = hdr->sh_flags;
@@ -797,9 +800,6 @@ _bfd_elf_make_section_from_shdr (bfd *ab
}
}
}
-
- hdr->bfd_section = newsect;
- elf_section_data (newsect)->this_hdr = *hdr;
return TRUE;
}
Index: bfd/elf32-arm.h
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.h,v
retrieving revision 1.130
diff -u -p -r1.130 elf32-arm.h
--- bfd/elf32-arm.h 23 Apr 2004 19:12:55 -0000 1.130
+++ bfd/elf32-arm.h 27 Apr 2004 03:07:41 -0000
@@ -4121,7 +4121,7 @@ elf32_arm_reloc_type_class (rela)
}
}
-static bfd_boolean elf32_arm_section_flags PARAMS ((flagword *, Elf_Internal_Shdr *));
+static bfd_boolean elf32_arm_section_flags PARAMS ((flagword *, const Elf_Internal_Shdr *));
static void elf32_arm_final_write_processing PARAMS ((bfd *, bfd_boolean));
/* Set the right machine number for an Arm ELF file. */
@@ -4129,7 +4129,7 @@ static void elf32_arm_final_write
static bfd_boolean
elf32_arm_section_flags (flags, hdr)
flagword *flags;
- Elf_Internal_Shdr *hdr;
+ const Elf_Internal_Shdr *hdr;
{
if (hdr->sh_type == SHT_NOTE)
*flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
Index: bfd/elf64-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-alpha.c,v
retrieving revision 1.117
diff -u -p -r1.117 elf64-alpha.c
--- bfd/elf64-alpha.c 27 Mar 2004 10:58:07 -0000 1.117
+++ bfd/elf64-alpha.c 27 Apr 2004 03:07:45 -0000
@@ -75,7 +75,7 @@ static bfd_boolean elf64_alpha_object_p
static bfd_boolean elf64_alpha_section_from_shdr
PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
static bfd_boolean elf64_alpha_section_flags
- PARAMS ((flagword *, Elf_Internal_Shdr *));
+ PARAMS ((flagword *, const Elf_Internal_Shdr *));
static bfd_boolean elf64_alpha_fake_sections
PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
static bfd_boolean elf64_alpha_create_got_section
@@ -2315,7 +2315,7 @@ elf64_alpha_section_from_shdr (abfd, hdr
static bfd_boolean
elf64_alpha_section_flags (flags, hdr)
flagword *flags;
- Elf_Internal_Shdr *hdr;
+ const Elf_Internal_Shdr *hdr;
{
if (hdr->sh_flags & SHF_ALPHA_GPREL)
*flags |= SEC_SMALL_DATA;
@@ -2572,7 +2572,6 @@ elf64_alpha_read_ecoff_info (abfd, secti
#undef READ
debug->fdr = NULL;
- debug->adjust = NULL;
return TRUE;
Index: bfd/elf64-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-sparc.c,v
retrieving revision 1.90
diff -u -p -r1.90 elf64-sparc.c
--- bfd/elf64-sparc.c 22 Apr 2004 14:45:31 -0000 1.90
+++ bfd/elf64-sparc.c 27 Apr 2004 03:07:47 -0000
@@ -3112,7 +3112,7 @@ sparc64_elf_object_p (abfd)
static bfd_vma
sparc64_elf_plt_sym_val (bfd_vma i, const asection *plt,
- const arelent *rel)
+ const arelent *rel ATTRIBUTE_UNUSED)
{
bfd_vma j;
Index: bfd/elfxx-ia64.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-ia64.c,v
retrieving revision 1.125
diff -u -p -r1.125 elfxx-ia64.c
--- bfd/elfxx-ia64.c 6 Apr 2004 00:59:22 -0000 1.125
+++ bfd/elfxx-ia64.c 27 Apr 2004 03:07:49 -0000
@@ -186,7 +186,7 @@ static bfd_boolean is_unwind_section_nam
static bfd_boolean elfNN_ia64_section_from_shdr
PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
static bfd_boolean elfNN_ia64_section_flags
- PARAMS ((flagword *, Elf_Internal_Shdr *));
+ PARAMS ((flagword *, const Elf_Internal_Shdr *));
static bfd_boolean elfNN_ia64_fake_sections
PARAMS ((bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec));
static void elfNN_ia64_final_write_processing
@@ -1271,7 +1271,7 @@ elfNN_ia64_section_from_shdr (abfd, hdr,
static bfd_boolean
elfNN_ia64_section_flags (flags, hdr)
flagword *flags;
- Elf_Internal_Shdr *hdr;
+ const Elf_Internal_Shdr *hdr;
{
if (hdr->sh_flags & SHF_IA_64_SHORT)
*flags |= SEC_SMALL_DATA;
--
Alan Modra
IBM OzLabs - Linux Technology Centre