1 commit 75bf1d978bc03a07ad59a3f983c806bb5899c28c
2 Author: Francois Gouget <fgouget@codeweavers.com>
3 Date: Tue Dec 20 18:37:16 2011 +0100
5 bfd: Fix writing the size of 2+GB elements in the archive.
7 diff --git a/bfd/archive.c b/bfd/archive.c
8 index 3e333c7..5c5b3d4 100644
11 @@ -179,6 +179,22 @@ _bfd_ar_spacepad (char *p, size_t n, const char *fmt, long val)
16 +_bfd_ar_sizepad (char *p, size_t n, bfd_size_type size)
18 + static char buf[21];
20 + snprintf (buf, sizeof (buf), "%-10" BFD_VMA_FMT "u", size);
24 + memcpy (p, buf, len);
25 + memset (p + len, ' ', n - len);
32 _bfd_generic_mkarchive (bfd *abfd)
34 @@ -1770,7 +1786,7 @@ _bfd_bsd44_write_ar_hdr (bfd *archive, bfd *abfd)
36 BFD_ASSERT (padded_len == arch_eltdata (abfd)->extra_size);
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);
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)
45 _bfd_ar_spacepad (hdr->ar_mode, sizeof (hdr->ar_mode), "%-8lo",
47 - _bfd_ar_spacepad (hdr->ar_size, sizeof (hdr->ar_size), "%-10ld",
48 + _bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_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,
72 memset (&hdr, ' ', sizeof (struct ar_hdr));
74 - _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld",
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
80 diff --git a/bfd/archive64.c b/bfd/archive64.c
81 index bbc4c3f..a906508 100644
84 @@ -169,7 +169,7 @@ bfd_elf64_archive_write_armap (bfd *arch,
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),
91 _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
93 diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
94 index 7db09e4..57197ac 100644
97 @@ -203,6 +203,8 @@ extern void *_bfd_generic_read_ar_hdr
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);
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
110 @@ -208,6 +208,8 @@ extern void *_bfd_generic_read_ar_hdr
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);
117 extern void *_bfd_generic_read_ar_hdr_mag
118 (bfd *, const char *);