This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PR11168, COFF maximum number of sections
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 18 Jan 2010 17:49:31 +1030
- Subject: PR11168, COFF maximum number of sections
COFF uses 16-bit fields for section numbers, and as the Microsoft PE
documentation plus a TI COFF document I found on the web says, the
field in the symbol struct should be treated as a 1-based signed index
into the section table. We ought to report an error on exceeding the
maximum number of sections. This patch does that.
PR 11168
* coffcode.h (coff_compute_section_file_positions): Move Rs6000COFF_C
block past vars in COFF_IMAGE_WITH_PE block. Report error on more
than 32k sections.
Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.162
diff -u -p -r1.162 coffcode.h
--- bfd/coffcode.h 23 Nov 2009 14:41:29 -0000 1.162
+++ bfd/coffcode.h 18 Jan 2010 02:11:32 -0000
@@ -3093,10 +3093,31 @@ coff_compute_section_file_positions (bfd
asection *previous = NULL;
file_ptr sofar = bfd_coff_filhsz (abfd);
bfd_boolean align_adjust;
+ int target_index;
#ifdef ALIGN_SECTIONS_IN_FILE
file_ptr old_sofar;
#endif
+#ifdef COFF_IMAGE_WITH_PE
+ int page_size;
+
+ if (coff_data (abfd)->link_info)
+ {
+ page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
+
+ /* If no file alignment has been set, default to one.
+ This repairs 'ld -r' for arm-wince-pe target. */
+ if (page_size == 0)
+ page_size = 1;
+ }
+ else
+ page_size = PE_DEF_FILE_ALIGNMENT;
+#else
+#ifdef COFF_PAGE_SIZE
+ int page_size = COFF_PAGE_SIZE;
+#endif
+#endif
+
#ifdef RS6000COFF_C
/* On XCOFF, if we have symbols, set up the .debug section. */
if (bfd_get_symcount (abfd) > 0)
@@ -3136,26 +3157,6 @@ coff_compute_section_file_positions (bfd
}
#endif
-#ifdef COFF_IMAGE_WITH_PE
- int page_size;
-
- if (coff_data (abfd)->link_info)
- {
- page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
-
- /* If no file alignment has been set, default to one.
- This repairs 'ld -r' for arm-wince-pe target. */
- if (page_size == 0)
- page_size = 1;
- }
- else
- page_size = PE_DEF_FILE_ALIGNMENT;
-#else
-#ifdef COFF_PAGE_SIZE
- int page_size = COFF_PAGE_SIZE;
-#endif
-#endif
-
if (bfd_get_start_address (abfd))
/* A start address may have been added to the original file. In this
case it will need an optional header to record it. */
@@ -3191,7 +3192,6 @@ coff_compute_section_file_positions (bfd
unsigned int count;
asection **section_list;
unsigned int i;
- int target_index;
bfd_size_type amt;
#ifdef COFF_PAGE_SIZE
@@ -3254,14 +3254,20 @@ coff_compute_section_file_positions (bfd
#else /* ! COFF_IMAGE_WITH_PE */
{
/* Set the target_index field. */
- int target_index;
-
target_index = 1;
for (current = abfd->sections; current != NULL; current = current->next)
current->target_index = target_index++;
}
#endif /* ! COFF_IMAGE_WITH_PE */
+ if (target_index >= 32768)
+ {
+ bfd_set_error (bfd_error_file_too_big);
+ (*_bfd_error_handler)
+ (_("%B: too many sections (%d)"), abfd, target_index);
+ return FALSE;
+ }
+
align_adjust = FALSE;
for (current = abfd->sections;
current != NULL;
--
Alan Modra
Australia Development Lab, IBM