* PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections
@ 2006-03-02 23:21 H. J. Lu
2006-03-03 4:13 ` Alan Modra
0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2006-03-02 23:21 UTC (permalink / raw)
To: binutils
The ELF gABI doesn't support more than 64k sections in DSO and
executable when there are dynamic symbols. This patch checks that.
H.J.
---
2006-03-02 H.J. Lu <hongjiu.lu@intel.com>
PR ld/2411
* elflink.c (map_sections_to_segments): Check if the number
of output sections are allowed.
(assign_file_positions_for_segments): Updated.
--- bfd/elf.c.64k 2006-03-01 06:19:54.000000000 -0800
+++ bfd/elf.c 2006-03-02 15:17:19.000000000 -0800
@@ -3585,7 +3585,7 @@ _bfd_elf_make_dynamic_segment (bfd *abfd
/* Set up a mapping from BFD sections to program segments. */
static bfd_boolean
-map_sections_to_segments (bfd *abfd)
+map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
{
asection **sections = NULL;
asection *s;
@@ -3612,6 +3612,18 @@ map_sections_to_segments (bfd *abfd)
if (bfd_count_sections (abfd) == 0)
return TRUE;
+ if (elf_hash_table (info)->dynsymcount != 0
+ && bfd_count_sections (abfd) >= SHN_LORESERVE)
+ {
+ /* The gABI doesn't support dynamic symbols and more than 64K
+ output sections at the same time. */
+ (*_bfd_error_handler)
+ (_("%B: Too many sections: %d (< %d)"),
+ abfd, bfd_count_sections (abfd), SHN_LORESERVE);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ return FALSE;
+ }
+
/* Select the allocated sections, and sort them. */
sections = bfd_malloc2 (bfd_count_sections (abfd), sizeof (asection *));
@@ -4085,7 +4097,7 @@ assign_file_positions_for_segments (bfd
if (elf_tdata (abfd)->segment_map == NULL)
{
- if (! map_sections_to_segments (abfd))
+ if (! map_sections_to_segments (abfd, link_info))
return FALSE;
}
else
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections
2006-03-02 23:21 PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections H. J. Lu
@ 2006-03-03 4:13 ` Alan Modra
2006-03-03 17:15 ` H. J. Lu
0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2006-03-03 4:13 UTC (permalink / raw)
To: H. J. Lu; +Cc: binutils
On Thu, Mar 02, 2006 at 03:21:25PM -0800, H. J. Lu wrote:
> The ELF gABI doesn't support more than 64k sections in DSO and
> executable when there are dynamic symbols. This patch checks that.
I think you should put this check in bfd_elf_final_link rather than in
map_sections_to_segments, before the first call to
elf_link_output_extsym. That puts it close to the code that outputs
dynamic section syms.
> + (_("%B: Too many sections: %d (< %d)"),
> + abfd, bfd_count_sections (abfd), SHN_LORESERVE);
Typo.
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections
2006-03-03 4:13 ` Alan Modra
@ 2006-03-03 17:15 ` H. J. Lu
2006-03-03 19:04 ` H. J. Lu
0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2006-03-03 17:15 UTC (permalink / raw)
To: binutils
On Fri, Mar 03, 2006 at 02:43:51PM +1030, Alan Modra wrote:
> On Thu, Mar 02, 2006 at 03:21:25PM -0800, H. J. Lu wrote:
> > The ELF gABI doesn't support more than 64k sections in DSO and
> > executable when there are dynamic symbols. This patch checks that.
>
> I think you should put this check in bfd_elf_final_link rather than in
> map_sections_to_segments, before the first call to
> elf_link_output_extsym. That puts it close to the code that outputs
> dynamic section syms.
>
> > + (_("%B: Too many sections: %d (< %d)"),
> > + abfd, bfd_count_sections (abfd), SHN_LORESERVE);
>
> Typo.
>
Here is the updated patch.
H.J.
---
2006-03-02 H.J. Lu <hongjiu.lu@intel.com>
PR ld/2411
* elflink.c (bfd_elf_final_link): Check if the number of output
sections is allowed.
--- bfd/elflink.c.64k 2006-03-02 14:16:50.000000000 -0800
+++ bfd/elflink.c 2006-03-03 09:03:46.000000000 -0800
@@ -8263,6 +8263,18 @@ bfd_elf_final_link (bfd *abfd, struct bf
}
}
+ if (elf_hash_table (info)->dynsymcount != 0
+ && bfd_count_sections (abfd) >= SHN_LORESERVE)
+ {
+ /* The gABI doesn't support dynamic symbols and more than 64K
+ output sections at the same time. */
+ (*_bfd_error_handler)
+ (_("%B: Too many sections: %d (>= %d)"),
+ abfd, bfd_count_sections (abfd), SHN_LORESERVE);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ goto error_return;
+ }
+
/* Output any global symbols that got converted to local in a
version script or due to symbol visibility. We do this in a
separate step since ELF requires all local symbols to appear
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections
2006-03-03 17:15 ` H. J. Lu
@ 2006-03-03 19:04 ` H. J. Lu
2006-03-03 20:04 ` H. J. Lu
0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2006-03-03 19:04 UTC (permalink / raw)
To: binutils
On Fri, Mar 03, 2006 at 09:15:53AM -0800, H. J. Lu wrote:
> On Fri, Mar 03, 2006 at 02:43:51PM +1030, Alan Modra wrote:
> > On Thu, Mar 02, 2006 at 03:21:25PM -0800, H. J. Lu wrote:
> > > The ELF gABI doesn't support more than 64k sections in DSO and
> > > executable when there are dynamic symbols. This patch checks that.
> >
> > I think you should put this check in bfd_elf_final_link rather than in
> > map_sections_to_segments, before the first call to
> > elf_link_output_extsym. That puts it close to the code that outputs
> > dynamic section syms.
> >
> > > + (_("%B: Too many sections: %d (< %d)"),
> > > + abfd, bfd_count_sections (abfd), SHN_LORESERVE);
> >
> > Typo.
> >
>
> Here is the updated patch.
>
>
It is OK to have dynamic symbols with 64K sections, which is one of
the old testcases, as long as the dynamic symbols aren't in the
sections beyond 64K. This patch checks section index for each dynamic
symbol to make sure it is supported.
H.J.
----
2006-03-03 H.J. Lu <hongjiu.lu@intel.com>
PR ld/2411
* elflink.c (check_dynsym): New.
(elf_link_output_extsym): Use it.
(bfd_elf_final_link): Likewise.
--- bfd/elflink.c.64k 2006-03-02 14:16:50.000000000 -0800
+++ bfd/elflink.c 2006-03-03 10:58:55.000000000 -0800
@@ -6199,6 +6199,24 @@ elf_link_output_sym (struct elf_final_li
return TRUE;
}
+/* Return TRUE if the dynamic symbol SYM in ABFD is supported. */
+
+static bfd_boolean
+check_dynsym (bfd *abfd, Elf_Internal_Sym *sym)
+{
+ if (sym->st_shndx > SHN_HIRESERVE)
+ {
+ /* The gABI doesn't support dynamic symbols in output sections
+ beyond 64k. */
+ (*_bfd_error_handler)
+ (_("%B: Too many sections: %d (>= %d)"),
+ abfd, bfd_count_sections (abfd), SHN_LORESERVE);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ return FALSE;
+ }
+ return TRUE;
+}
+
/* For DSOs loaded in via a DT_NEEDED entry, emulate ld.so in
allowing an unsatisfied unversioned symbol in the DSO to match a
versioned symbol that would normally require an explicit version.
@@ -6631,6 +6649,11 @@ elf_link_output_extsym (struct elf_link_
sym.st_name = h->dynstr_index;
esym = finfo->dynsym_sec->contents + h->dynindx * bed->s->sizeof_sym;
+ if (! check_dynsym (finfo->output_bfd, &sym))
+ {
+ eoinfo->failed = TRUE;
+ return FALSE;
+ }
bed->s->swap_symbol_out (finfo->output_bfd, &sym, esym, 0);
bucketcount = elf_hash_table (finfo->info)->bucketcount;
@@ -8313,6 +8336,8 @@ bfd_elf_final_link (bfd *abfd, struct bf
continue;
indx = elf_section_data (s)->this_idx;
BFD_ASSERT (indx > 0);
+ if (! check_dynsym (abfd, &sym))
+ return FALSE;
sym.st_shndx = indx;
sym.st_value = s->vma;
dest = dynsym + dynindx * bed->s->sizeof_sym;
@@ -8348,6 +8373,8 @@ bfd_elf_final_link (bfd *abfd, struct bf
sym.st_shndx =
elf_section_data (s->output_section)->this_idx;
+ if (! check_dynsym (abfd, &sym))
+ return FALSE;
sym.st_value = (s->output_section->vma
+ s->output_offset
+ e->isym.st_value);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections
2006-03-03 19:04 ` H. J. Lu
@ 2006-03-03 20:04 ` H. J. Lu
2006-03-10 2:28 ` H. J. Lu
0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2006-03-03 20:04 UTC (permalink / raw)
To: binutils
On Fri, Mar 03, 2006 at 11:04:03AM -0800, H. J. Lu wrote:
> On Fri, Mar 03, 2006 at 09:15:53AM -0800, H. J. Lu wrote:
> > On Fri, Mar 03, 2006 at 02:43:51PM +1030, Alan Modra wrote:
> > > On Thu, Mar 02, 2006 at 03:21:25PM -0800, H. J. Lu wrote:
> > > > The ELF gABI doesn't support more than 64k sections in DSO and
> > > > executable when there are dynamic symbols. This patch checks that.
> > >
> > > I think you should put this check in bfd_elf_final_link rather than in
> > > map_sections_to_segments, before the first call to
> > > elf_link_output_extsym. That puts it close to the code that outputs
> > > dynamic section syms.
> > >
> > > > + (_("%B: Too many sections: %d (< %d)"),
> > > > + abfd, bfd_count_sections (abfd), SHN_LORESERVE);
> > >
> > > Typo.
> > >
> >
> > Here is the updated patch.
> >
> >
>
> It is OK to have dynamic symbols with 64K sections, which is one of
> the old testcases, as long as the dynamic symbols aren't in the
> sections beyond 64K. This patch checks section index for each dynamic
> symbol to make sure it is supported.
>
I had a typo in my last patch. Here is the right one.
H.J.
---
2006-03-03 H.J. Lu <hongjiu.lu@intel.com>
PR ld/2411
* elflink.c (check_dynsym): New.
(elf_link_output_extsym): Use it.
(bfd_elf_final_link): Likewise.
--- bfd/elflink.c.64k 2006-03-02 14:16:50.000000000 -0800
+++ bfd/elflink.c 2006-03-03 11:55:14.000000000 -0800
@@ -6199,6 +6199,24 @@ elf_link_output_sym (struct elf_final_li
return TRUE;
}
+/* Return TRUE if the dynamic symbol SYM in ABFD is supported. */
+
+static bfd_boolean
+check_dynsym (bfd *abfd, Elf_Internal_Sym *sym)
+{
+ if (sym->st_shndx > SHN_HIRESERVE)
+ {
+ /* The gABI doesn't support dynamic symbols in output sections
+ beyond 64k. */
+ (*_bfd_error_handler)
+ (_("%B: Too many sections: %d (>= %d)"),
+ abfd, bfd_count_sections (abfd), SHN_LORESERVE);
+ bfd_set_error (bfd_error_nonrepresentable_section);
+ return FALSE;
+ }
+ return TRUE;
+}
+
/* For DSOs loaded in via a DT_NEEDED entry, emulate ld.so in
allowing an unsatisfied unversioned symbol in the DSO to match a
versioned symbol that would normally require an explicit version.
@@ -6631,6 +6649,11 @@ elf_link_output_extsym (struct elf_link_
sym.st_name = h->dynstr_index;
esym = finfo->dynsym_sec->contents + h->dynindx * bed->s->sizeof_sym;
+ if (! check_dynsym (finfo->output_bfd, &sym))
+ {
+ eoinfo->failed = TRUE;
+ return FALSE;
+ }
bed->s->swap_symbol_out (finfo->output_bfd, &sym, esym, 0);
bucketcount = elf_hash_table (finfo->info)->bucketcount;
@@ -8314,6 +8337,8 @@ bfd_elf_final_link (bfd *abfd, struct bf
indx = elf_section_data (s)->this_idx;
BFD_ASSERT (indx > 0);
sym.st_shndx = indx;
+ if (! check_dynsym (abfd, &sym))
+ return FALSE;
sym.st_value = s->vma;
dest = dynsym + dynindx * bed->s->sizeof_sym;
if (last_local < dynindx)
@@ -8348,6 +8373,8 @@ bfd_elf_final_link (bfd *abfd, struct bf
sym.st_shndx =
elf_section_data (s->output_section)->this_idx;
+ if (! check_dynsym (abfd, &sym))
+ return FALSE;
sym.st_value = (s->output_section->vma
+ s->output_offset
+ e->isym.st_value);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections
2006-03-03 20:04 ` H. J. Lu
@ 2006-03-10 2:28 ` H. J. Lu
2006-04-05 11:39 ` Nick Clifton
0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2006-03-10 2:28 UTC (permalink / raw)
To: binutils
On Fri, Mar 03, 2006 at 12:04:41PM -0800, H. J. Lu wrote:
> On Fri, Mar 03, 2006 at 11:04:03AM -0800, H. J. Lu wrote:
> > On Fri, Mar 03, 2006 at 09:15:53AM -0800, H. J. Lu wrote:
> > > On Fri, Mar 03, 2006 at 02:43:51PM +1030, Alan Modra wrote:
> > > > On Thu, Mar 02, 2006 at 03:21:25PM -0800, H. J. Lu wrote:
> > > > > The ELF gABI doesn't support more than 64k sections in DSO and
> > > > > executable when there are dynamic symbols. This patch checks that.
> > > >
> > > > I think you should put this check in bfd_elf_final_link rather than in
> > > > map_sections_to_segments, before the first call to
> > > > elf_link_output_extsym. That puts it close to the code that outputs
> > > > dynamic section syms.
> > > >
> > > > > + (_("%B: Too many sections: %d (< %d)"),
> > > > > + abfd, bfd_count_sections (abfd), SHN_LORESERVE);
> > > >
> > > > Typo.
> > > >
> > >
> > > Here is the updated patch.
> > >
> > >
> >
> > It is OK to have dynamic symbols with 64K sections, which is one of
> > the old testcases, as long as the dynamic symbols aren't in the
> > sections beyond 64K. This patch checks section index for each dynamic
> > symbol to make sure it is supported.
> >
>
> I had a typo in my last patch. Here is the right one.
>
Can someone please take a look at
http://sourceware.org/ml/binutils/2006-03/msg00055.html
Thanks.
H.J.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections
2006-03-10 2:28 ` H. J. Lu
@ 2006-04-05 11:39 ` Nick Clifton
0 siblings, 0 replies; 7+ messages in thread
From: Nick Clifton @ 2006-04-05 11:39 UTC (permalink / raw)
To: H. J. Lu; +Cc: binutils
Hi H. J.
> Can someone please take a look at
>
> http://sourceware.org/ml/binutils/2006-03/msg00055.html
Sorry for the long delay.
> 2006-03-03 H.J. Lu <hongjiu.lu@intel.com>
>
> PR ld/2411
> * elflink.c (check_dynsym): New.
> (elf_link_output_extsym): Use it.
> (bfd_elf_final_link): Likewise.
Approved - please apply.
Cheers
Nick
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-04-05 11:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-02 23:21 PATCH: ld/2411: ELF linker fails to create executable with more than 64k sections H. J. Lu
2006-03-03 4:13 ` Alan Modra
2006-03-03 17:15 ` H. J. Lu
2006-03-03 19:04 ` H. J. Lu
2006-03-03 20:04 ` H. J. Lu
2006-03-10 2:28 ` H. J. Lu
2006-04-05 11:39 ` Nick Clifton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).