tizen 2.3 release
[external/binutils.git] / packaging / fixbug13534_1.patch
1 commit 75bf1d978bc03a07ad59a3f983c806bb5899c28c
2 Author: Francois Gouget <fgouget@codeweavers.com>
3 Date:   Tue Dec 20 18:37:16 2011 +0100
4
5     bfd: Fix writing the size of 2+GB elements in the archive.
6
7 diff --git a/bfd/archive.c b/bfd/archive.c
8 index 3e333c7..5c5b3d4 100644
9 --- a/bfd/archive.c
10 +++ b/bfd/archive.c
11 @@ -179,6 +179,22 @@ _bfd_ar_spacepad (char *p, size_t n, const char *fmt, long val)
12      memcpy (p, buf, n);
13  }
14  \f
15 +void
16 +_bfd_ar_sizepad (char *p, size_t n, bfd_size_type size)
17 +{
18 +  static char buf[21];
19 +  size_t len;
20 +  snprintf (buf, sizeof (buf), "%-10" BFD_VMA_FMT "u", size);
21 +  len = strlen (buf);
22 +  if (len < n)
23 +    {
24 +      memcpy (p, buf, len);
25 +      memset (p + len, ' ', n - len);
26 +    }
27 +  else
28 +    memcpy (p, buf, n);
29 +}
30 +\f
31  bfd_boolean
32  _bfd_generic_mkarchive (bfd *abfd)
33  {
34 @@ -1770,7 +1786,7 @@ _bfd_bsd44_write_ar_hdr (bfd *archive, bfd *abfd)
35  
36        BFD_ASSERT (padded_len == arch_eltdata (abfd)->extra_size);
37  
38 -      _bfd_ar_spacepad (hdr->ar_size, sizeof (hdr->ar_size), "%-10ld",
39 +      _bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
40                          arch_eltdata (abfd)->parsed_size + padded_len);
41  
42        if (bfd_bwrite (hdr, sizeof (*hdr), archive) != sizeof (*hdr))
43 @@ -1891,7 +1907,7 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member)
44                        status.st_gid);
45    _bfd_ar_spacepad (hdr->ar_mode, sizeof (hdr->ar_mode), "%-8lo",
46                      status.st_mode);
47 -  _bfd_ar_spacepad (hdr->ar_size, sizeof (hdr->ar_size), "%-10ld",
48 +  _bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
49                      status.st_size);
50    memcpy (hdr->ar_fmag, ARFMAG, 2);
51    ared->parsed_size = status.st_size;
52 @@ -2132,7 +2148,7 @@ _bfd_write_archive_contents (bfd *arch)
53        memset (&hdr, ' ', sizeof (struct ar_hdr));
54        memcpy (hdr.ar_name, ename, strlen (ename));
55        /* Round size up to even number in archive header.  */
56 -      _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld",
57 +      _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
58                          (elength + 1) & ~(bfd_size_type) 1);
59        memcpy (hdr.ar_fmag, ARFMAG, 2);
60        if ((bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
61 @@ -2409,7 +2425,7 @@ bsd_write_armap (bfd *arch,
62                      bfd_ardata (arch)->armap_timestamp);
63    _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", uid);
64    _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", gid);
65 -  _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", mapsize);
66 +  _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize);
67    memcpy (hdr.ar_fmag, ARFMAG, 2);
68    if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
69        != sizeof (struct ar_hdr))
70 @@ -2564,8 +2580,7 @@ coff_write_armap (bfd *arch,
71  
72    memset (&hdr, ' ', sizeof (struct ar_hdr));
73    hdr.ar_name[0] = '/';
74 -  _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld",
75 -                    mapsize);
76 +  _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize);
77    _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
78                      ((arch->flags & BFD_DETERMINISTIC_OUTPUT) == 0
79                       ? time (NULL) : 0));
80 diff --git a/bfd/archive64.c b/bfd/archive64.c
81 index bbc4c3f..a906508 100644
82 --- a/bfd/archive64.c
83 +++ b/bfd/archive64.c
84 @@ -169,7 +169,7 @@ bfd_elf64_archive_write_armap (bfd *arch,
85  
86    memset (&hdr, ' ', sizeof (struct ar_hdr));
87    memcpy (hdr.ar_name, "/SYM64/", strlen ("/SYM64/"));
88 -  _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld",
89 +  _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
90                      mapsize);
91    _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
92                      time (NULL));
93 diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
94 index 7db09e4..57197ac 100644
95 --- a/bfd/libbfd-in.h
96 +++ b/bfd/libbfd-in.h
97 @@ -203,6 +203,8 @@ extern void *_bfd_generic_read_ar_hdr
98    (bfd *);
99  extern void _bfd_ar_spacepad
100    (char *, size_t, const char *, long);
101 +extern void _bfd_ar_sizepad
102 +  (char *, size_t, bfd_size_type);
103  
104  extern void *_bfd_generic_read_ar_hdr_mag
105    (bfd *, const char *);
106 diff --git a/bfd/libbfd.h b/bfd/libbfd.h
107 index 0beddb6..121e865 100644
108 --- a/bfd/libbfd.h
109 +++ b/bfd/libbfd.h
110 @@ -208,6 +208,8 @@ extern void *_bfd_generic_read_ar_hdr
111    (bfd *);
112  extern void _bfd_ar_spacepad
113    (char *, size_t, const char *, long);
114 +extern void _bfd_ar_sizepad
115 +  (char *, size_t, bfd_size_type);
116  
117  extern void *_bfd_generic_read_ar_hdr_mag
118    (bfd *, const char *);