Commit f16c280f authored by Russ Cox's avatar Russ Cox

gopack: allow ELF/Mach-O objects in .a files without clearing allobj

R=iant
CC=golang-dev
https://golang.org/cl/3503041
parent 8132f1d0
...@@ -593,12 +593,26 @@ scanobj(Biobuf *b, Arfile *ap, long size) ...@@ -593,12 +593,26 @@ scanobj(Biobuf *b, Arfile *ap, long size)
vlong offset; vlong offset;
Dir *d; Dir *d;
static int lastobj = -1; static int lastobj = -1;
uchar buf[4];
if (!allobj) /* non-object file encountered */ if (!allobj) /* non-object file encountered */
return; return;
offset = Boffset(b); offset = Boffset(b);
obj = objtype(b, 0); obj = objtype(b, 0);
if (obj < 0) { /* not an object file */ if (obj < 0) { /* not an object file */
/* maybe a foreign object file */
Bseek(b, offset, 0);
memset(buf, 0, sizeof buf);
Bread(b, buf, 4);
/* maybe a foreign object file? that's okay */
if((buf[0] == 0x7F && buf[1] == 'E' && buf[2] == 'L' && buf[3] == 'F') || // ELF
(buf[0] == 0xFE && buf[1] == 0xED && buf[2] == 0xFA && (buf[3]&~1) == 0xCE) || // Mach-O big-endian
(buf[3] == 0xFE && buf[2] == 0xED && buf[1] == 0xFA && (buf[0]&~1) == 0xCE)) { // Mach-O little-endian
Bseek(b, offset, 0);
return;
}
if (!gflag || strcmp(file, pkgdef) != 0) { /* don't clear allobj if it's pkg defs */ if (!gflag || strcmp(file, pkgdef) != 0) { /* don't clear allobj if it's pkg defs */
fprint(2, "gopack: non-object file %s\n", file); fprint(2, "gopack: non-object file %s\n", file);
errors++; errors++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment