From 45407bd5599299b90e4d060d10993fb456d1d84a Mon Sep 17 00:00:00 2001 From: Lucio De Re Date: Mon, 22 Aug 2011 23:24:38 -0400 Subject: [PATCH] ld: handle Plan 9 ar format The Go version has 64 character long section names; originally, in Plan 9, the limit was 16. To provide compatibility, this change allows the input length to be either the target length or the earlier option. The section name is extended with spaces where required. This has been tested to work without regressions in the Go environment, testing the older alternative has not been possible yet. R=rsc CC=golang-dev https://golang.org/cl/4650071 --- src/cmd/ld/lib.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index 5d1e6d61b4..37379e1863 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -295,19 +295,33 @@ nextar(Biobuf *bp, int off, struct ar_hdr *a) { int r; int32 arsize; + char *buf; if (off&01) off++; Bseek(bp, off, 0); - r = Bread(bp, a, SAR_HDR); - if(r != SAR_HDR) - return 0; - if(strncmp(a->fmag, ARFMAG, sizeof(a->fmag))) + buf = Brdline(bp, '\n'); + r = Blinelen(bp); + if(buf == nil) { + if(r == 0) + return 0; + return -1; + } + if(r == SAR_HDR) { + memmove(a, buf, SAR_HDR); + } else if (r == SAR_HDR-SARNAME+16) { // old Plan 9 + memset(a->name, ' ', sizeof a->name); + memmove(a, buf, 16); + memmove((char*)a+SARNAME, buf+16, SAR_HDR-SARNAME); + } else { // unexpected + return -1; + } + if(strncmp(a->fmag, ARFMAG, sizeof a->fmag)) return -1; arsize = strtol(a->size, 0, 0); if (arsize&1) arsize++; - return arsize + SAR_HDR; + return arsize + r; } void @@ -1332,7 +1346,7 @@ Yconv(Fmt *fp) fmtprint(fp, ""); } else { fmtstrinit(&fmt); - fmtprint(&fmt, "%s @0x%08x [%d]", s->name, s->value, s->size); + fmtprint(&fmt, "%s @0x%08llx [%lld]", s->name, (vlong)s->value, (vlong)s->size); for (i = 0; i < s->size; i++) { if (!(i%8)) fmtprint(&fmt, "\n\t0x%04x ", i); fmtprint(&fmt, "%02x ", s->p[i]); -- 2.50.0