gas patch for non-octet processors

2012-06-29 Thread jnielsen
The attached patches correct an issue that exists in gas. The problem is 
general but only manifests itself when OCTETS_PER_BYTE > 1. I have found 
the problem in binutils 2.22 in connection with TI C4x (i.e. ./configure 
--target=c4x-coff).

Function frag_offset_fixed_p in frags.[ch] returns an offset through its 
last parameter. The parameter type is bfd_vma which is unsigned. The only 
calls to the function are in expr.c; the offset is returned to local 
variables frag_off which are also of type bfd_vma. The variables frag_off 
are divided by OCTETS_PER_BYTE; the problem is that these divisions are 
unsigned as a result of the use of bfd_vma. Dividing these offsets must be 
done signed. No actual division takes place when OCTETS_PER_BYTE = 1 so 
this problem only manifests itself when OCTETS_PER_BYTE > 1.

These uses of bfd_vma are the only ones in the three sources expr.c, 
frags.c, frags.h. I believe all these uses of bfd_vma should be changed to 
offsetT. This will be more consistent with the definitions of the struct 
members used in frag_offset_fixed_p and the fact that the returned value 
is supposed to be an offset; it also makes the divisions produce the 
correct values when OCTETS_PER_BYTE > 1.

Please consider these patches for future binutils releases. The revisions 
of the original expr.c, frags.c, and frags.h are respectively 1.90, 
1.30.2.1, and 1.24.4.1.

Thanks,
Johan Olmutz Nielsen

--- expr.1.90.c 2011-03-17 11:59:29.0 +0100
+++ expr.c  2012-06-22 12:33:40.531010600 +0200
@@ -1746,7 +1746,7 @@
   while (op_left != O_illegal && op_rank[(int) op_left] > rank)
 {
   segT rightseg;
-  bfd_vma frag_off;
+  offsetT frag_off;
 
   input_line_pointer += op_chars;  /* -> after operator.  */
 
@@ -2030,7 +2030,7 @@
   valueT left, right;
   segT seg_left, seg_right;
   fragS *frag_left, *frag_right;
-  bfd_vma frag_off;
+  offsetT frag_off;
 
   switch (op)
 {

--- frags.1.30.2.1.c2011-11-21 10:29:28.0 +0100
+++ frags.c 2012-06-22 12:23:46.886766700 +0200
@@ -394,10 +394,10 @@
not already accounted for in the frag FR_ADDRESS.  */
 
 bfd_boolean
-frag_offset_fixed_p (const fragS *frag1, const fragS *frag2, bfd_vma 
*offset)
+frag_offset_fixed_p (const fragS *frag1, const fragS *frag2, offsetT 
*offset)
 {
   const fragS *frag;
-  bfd_vma off;
+  offsetT off;
 
   /* Start with offset initialised to difference between the two frags.
  Prior to assigning frag addresses this will be zero.  */

--- frags.1.24.4.1.h2011-11-21 10:29:28.0 +0100
+++ frags.h 2012-06-22 12:23:02.655089200 +0200
@@ -151,6 +151,6 @@
offsetT offset,
char *opcode);
 
-bfd_boolean frag_offset_fixed_p (const fragS *, const fragS *, bfd_vma 
*);
+bfd_boolean frag_offset_fixed_p (const fragS *, const fragS *, offsetT 
*);
 
 #endif /* FRAGS_H */

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


ld patch to prevent uninitialized data in TI COFF output

2008-12-06 Thread jnielsen
The attached patches correct an issue that exists in ld when the object 
code format is TI COFF.

The problem is that struct external_scnhdr in ti.h define two members, 
s_reserved and s_page, which are not always set before the section header 
is written to the output. The output file in TI COFF works nicely except 
that subsequent ld invocations may produce files which are not identical. 
I have for instance seen the length of the output file name affect the 
resulting values of s_reserved and s_page.

Please consider these patches for future binutils releases.

I found the problem in an older version of binutils but have verified that 
these members remain unset in the CVS head revisions. The patches are 
relative to the CVS head revisions as of today, coffcode.h rev. 1.144 and 
ti.h rev. 1.18.

Thanks,
Johan Olmutz Nielsen


--- coffcode.h.1.1442008-12-06 12:45:12.393963200 +0100
+++ coffcode.h  2008-12-06 12:57:45.576987200 +0100
@@ -3528,6 +3528,8 @@
   section.s_size =  current->size;
 #ifdef coff_get_section_load_page
   section.s_page = coff_get_section_load_page (current);
+#else
+  section.s_page = 0;
 #endif

 #ifdef COFF_WITH_PE


--- ti.h.1.18   2008-12-06 12:51:52.609444800 +0100
+++ ti.h2008-12-06 12:56:26.503284800 +0100
@@ -321,6 +321,16 @@
 }  \
while (0)

+/* The entire scnhdr may not be assigned.
+   Ensure that everything is initialized.
+ */
+#define COFF_ADJUST_SCNHDR_OUT_PRE(ABFD, INT, EXT) \
+  do   \
+{  \
+  memset((EXT), 0, sizeof(SCNHDR));  \
+}  \
+   while (0)
+
 /* The line number and reloc overflow checking in coff_swap_scnhdr_out in
coffswap.h doesn't use PUT_X for s_nlnno and s_nreloc.
Due to different sized v0/v1/v2 section headers, we have to re-write 
these



This message is intended only for the use of the individual or entity to which 
it is addressed. If the reader of this message is not the intended recipient, 
or the employee or agent responsible for delivering the message to the intended 
recipient, you are hereby notified that any dissemination, distribution or 
copying of this message is strictly prohibited. If you have received this 
communication in error, please notify us immediately by replying to the sender 
of this E-Mail by return E-Mail or by telephone. 


___
bug-binutils mailing list
bug-binutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-binutils