Commit d7b10060 authored by Russ Cox's avatar Russ Cox

cmd/ld: clean for c2go

Change-Id: Iaab2be9a1919f2fa9dbc61a5b7fbf99bcd0712a9
Reviewed-on: https://go-review.googlesource.com/6332Reviewed-by: default avatarRob Pike <r@golang.org>
Reviewed-by: default avatarMinux Ma <minux@golang.org>
parent 0aac9bb8
...@@ -28,13 +28,21 @@ ...@@ -28,13 +28,21 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#define ARMAG "!<arch>\n" enum {
#define SARMAG 8 SARMAG = 8,
SARNAME = 16,
SAR_HDR = 16+44,
};
#define ARMAG "!<arch>\n"
#define ARFMAG "`\n" #define ARFMAG "`\n"
#define SARNAME 16 /*c2go
char ARMAG[] = "!<arch>\n";
char ARFMAG[] = "`\n";
*/
struct ar_hdr typedef struct ArHdr ArHdr;
struct ArHdr
{ {
char name[SARNAME]; char name[SARNAME];
char date[12]; char date[12];
...@@ -44,4 +52,3 @@ struct ar_hdr ...@@ -44,4 +52,3 @@ struct ar_hdr
char size[10]; char size[10];
char fmag[2]; char fmag[2];
}; };
#define SAR_HDR (SARNAME+44)
...@@ -52,9 +52,6 @@ struct Reloc ...@@ -52,9 +52,6 @@ struct Reloc
LSym* xsym; LSym* xsym;
}; };
// prevent incompatible type signatures between liblink and 8l on Plan 9
#pragma incomplete struct Section
struct LSym struct LSym
{ {
char* name; char* name;
...@@ -94,7 +91,7 @@ struct LSym ...@@ -94,7 +91,7 @@ struct LSym
char* file; char* file;
char* dynimplib; char* dynimplib;
char* dynimpvers; char* dynimpvers;
struct Section* sect; void* sect;
// STEXT // STEXT
Auto* autom; Auto* autom;
......
// Inferno utils/include/ar.h
// http://code.google.com/p/inferno-os/source/browse/utils/include/ar.h
//
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
// Portions Copyright © 1997-1999 Vita Nuova Limited
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
// Portions Copyright © 2004,2006 Bruce Ellis
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
enum {
SARMAG = 8,
SARNAME = 16,
SAR_HDR = 16+44,
};
#define ARMAG "!<arch>\n"
#define ARFMAG "`\n"
/*c2go
char ARMAG[] = "!<arch>\n";
char ARFMAG[] = "`\n";
*/
typedef struct ArHdr ArHdr;
struct ArHdr
{
char name[SARNAME];
char date[12];
char uid[6];
char gid[6];
char mode[8];
char size[10];
char fmag[2];
};
...@@ -305,9 +305,9 @@ machoreloc1(Reloc *r, vlong sectoff) ...@@ -305,9 +305,9 @@ machoreloc1(Reloc *r, vlong sectoff)
v = rs->dynid; v = rs->dynid;
v |= 1<<27; // external relocation v |= 1<<27; // external relocation
} else { } else {
v = rs->sect->extnum; v = ((Section*)rs->sect)->extnum;
if(v == 0) { if(v == 0) {
diag("reloc %d to symbol %s in non-macho section %s type=%d", r->type, rs->name, rs->sect->name, rs->type); diag("reloc %d to symbol %s in non-macho section %s type=%d", r->type, rs->name, ((Section*)rs->sect)->name, rs->type);
return -1; return -1;
} }
} }
...@@ -610,10 +610,10 @@ asmb(void) ...@@ -610,10 +610,10 @@ asmb(void)
sect = segtext.sect; sect = segtext.sect;
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
codeblk(sect->vaddr, sect->len); codeblk(sect->vaddr, sect->length);
for(sect = sect->next; sect != nil; sect = sect->next) { for(sect = sect->next; sect != nil; sect = sect->next) {
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
datblk(sect->vaddr, sect->len); datblk(sect->vaddr, sect->length);
} }
if(segrodata.filelen > 0) { if(segrodata.filelen > 0) {
...@@ -638,7 +638,7 @@ asmb(void) ...@@ -638,7 +638,7 @@ asmb(void)
Bprint(&bso, "%5.2f dwarf\n", cputime()); Bprint(&bso, "%5.2f dwarf\n", cputime());
if(!debug['w']) { // TODO(minux): enable DWARF Support if(!debug['w']) { // TODO(minux): enable DWARF Support
dwarfoff = rnd(HEADR+segtext.len, INITRND) + rnd(segdata.filelen, INITRND); dwarfoff = rnd(HEADR+segtext.length, INITRND) + rnd(segdata.filelen, INITRND);
cseek(dwarfoff); cseek(dwarfoff);
segdwarf.fileoff = cpos(); segdwarf.fileoff = cpos();
...@@ -659,18 +659,17 @@ asmb(void) ...@@ -659,18 +659,17 @@ asmb(void)
Bflush(&bso); Bflush(&bso);
switch(HEADTYPE) { switch(HEADTYPE) {
default: default:
if(iself) if(iself) {
goto ElfSym; symo = segdata.fileoff+segdata.filelen;
symo = rnd(symo, INITRND);
}
break;
case Hplan9: case Hplan9:
symo = segdata.fileoff+segdata.filelen; symo = segdata.fileoff+segdata.filelen;
break; break;
case Hdarwin: case Hdarwin:
symo = rnd(HEADR+segtext.filelen, INITRND)+rnd(segdata.filelen, INITRND)+machlink; symo = rnd(HEADR+segtext.filelen, INITRND)+rnd(segdata.filelen, INITRND)+machlink;
break; break;
ElfSym:
symo = segdata.fileoff+segdata.filelen;
symo = rnd(symo, INITRND);
break;
} }
cseek(symo); cseek(symo);
switch(HEADTYPE) { switch(HEADTYPE) {
...@@ -721,7 +720,7 @@ asmb(void) ...@@ -721,7 +720,7 @@ asmb(void)
thearch.lput(0x647); /* magic */ thearch.lput(0x647); /* magic */
thearch.lput(segtext.filelen); /* sizes */ thearch.lput(segtext.filelen); /* sizes */
thearch.lput(segdata.filelen); thearch.lput(segdata.filelen);
thearch.lput(segdata.len - segdata.filelen); thearch.lput(segdata.length - segdata.filelen);
thearch.lput(symsize); /* nsyms */ thearch.lput(symsize); /* nsyms */
thearch.lput(entryvalue()); /* va of entry */ thearch.lput(entryvalue()); /* va of entry */
thearch.lput(0L); thearch.lput(0L);
...@@ -742,9 +741,9 @@ asmb(void) ...@@ -742,9 +741,9 @@ asmb(void)
if(debug['c']){ if(debug['c']){
print("textsize=%ulld\n", segtext.filelen); print("textsize=%ulld\n", segtext.filelen);
print("datsize=%ulld\n", segdata.filelen); print("datsize=%ulld\n", segdata.filelen);
print("bsssize=%ulld\n", segdata.len - segdata.filelen); print("bsssize=%ulld\n", segdata.length - segdata.filelen);
print("symsize=%d\n", symsize); print("symsize=%d\n", symsize);
print("lcsize=%d\n", lcsize); print("lcsize=%d\n", lcsize);
print("total=%lld\n", segtext.filelen+segdata.len+symsize+lcsize); print("total=%lld\n", segtext.filelen+segdata.length+symsize+lcsize);
} }
} }
...@@ -37,7 +37,11 @@ ...@@ -37,7 +37,11 @@
#include "../ld/macho.h" #include "../ld/macho.h"
#include "../ld/pe.h" #include "../ld/pe.h"
#define PADDR(a) ((uint32)(a) & ~0x80000000) uint32
PADDR(uint32 x)
{
return x & ~0x80000000;
}
char zeroes[32]; char zeroes[32];
...@@ -333,9 +337,9 @@ machoreloc1(Reloc *r, vlong sectoff) ...@@ -333,9 +337,9 @@ machoreloc1(Reloc *r, vlong sectoff)
v = rs->dynid; v = rs->dynid;
v |= 1<<27; // external relocation v |= 1<<27; // external relocation
} else { } else {
v = rs->sect->extnum; v = ((Section*)rs->sect)->extnum;
if(v == 0) { if(v == 0) {
diag("reloc %d to symbol %s in non-macho section %s type=%d", r->type, rs->name, rs->sect->name, rs->type); diag("reloc %d to symbol %s in non-macho section %s type=%d", r->type, rs->name, ((Section*)rs->sect)->name, rs->type);
return -1; return -1;
} }
} }
...@@ -615,10 +619,10 @@ asmb(void) ...@@ -615,10 +619,10 @@ asmb(void)
sect = segtext.sect; sect = segtext.sect;
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
codeblk(sect->vaddr, sect->len); codeblk(sect->vaddr, sect->length);
for(sect = sect->next; sect != nil; sect = sect->next) { for(sect = sect->next; sect != nil; sect = sect->next) {
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
datblk(sect->vaddr, sect->len); datblk(sect->vaddr, sect->length);
} }
if(segrodata.filelen > 0) { if(segrodata.filelen > 0) {
...@@ -642,7 +646,7 @@ asmb(void) ...@@ -642,7 +646,7 @@ asmb(void)
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f dwarf\n", cputime()); Bprint(&bso, "%5.2f dwarf\n", cputime());
dwarfoff = rnd(HEADR+segtext.len, INITRND) + rnd(segdata.filelen, INITRND); dwarfoff = rnd(HEADR+segtext.length, INITRND) + rnd(segdata.filelen, INITRND);
cseek(dwarfoff); cseek(dwarfoff);
segdwarf.fileoff = cpos(); segdwarf.fileoff = cpos();
...@@ -763,7 +767,7 @@ asmb(void) ...@@ -763,7 +767,7 @@ asmb(void)
lputb(magic); /* magic */ lputb(magic); /* magic */
lputb(segtext.filelen); /* sizes */ lputb(segtext.filelen); /* sizes */
lputb(segdata.filelen); lputb(segdata.filelen);
lputb(segdata.len - segdata.filelen); lputb(segdata.length - segdata.filelen);
lputb(symsize); /* nsyms */ lputb(symsize); /* nsyms */
vl = entryvalue(); vl = entryvalue();
lputb(PADDR(vl)); /* va of entry */ lputb(PADDR(vl)); /* va of entry */
......
...@@ -296,9 +296,9 @@ machoreloc1(Reloc *r, vlong sectoff) ...@@ -296,9 +296,9 @@ machoreloc1(Reloc *r, vlong sectoff)
v = rs->dynid; v = rs->dynid;
v |= 1<<27; // external relocation v |= 1<<27; // external relocation
} else { } else {
v = rs->sect->extnum; v = ((Section*)rs->sect)->extnum;
if(v == 0) { if(v == 0) {
diag("reloc %d to symbol %s in non-macho section %s type=%d", r->type, rs->name, rs->sect->name, rs->type); diag("reloc %d to symbol %s in non-macho section %s type=%d", r->type, rs->name, ((Section*)rs->sect)->name, rs->type);
return -1; return -1;
} }
} }
...@@ -565,10 +565,10 @@ asmb(void) ...@@ -565,10 +565,10 @@ asmb(void)
sect = segtext.sect; sect = segtext.sect;
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
codeblk(sect->vaddr, sect->len); codeblk(sect->vaddr, sect->length);
for(sect = sect->next; sect != nil; sect = sect->next) { for(sect = sect->next; sect != nil; sect = sect->next) {
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
datblk(sect->vaddr, sect->len); datblk(sect->vaddr, sect->length);
} }
if(segrodata.filelen > 0) { if(segrodata.filelen > 0) {
...@@ -592,7 +592,7 @@ asmb(void) ...@@ -592,7 +592,7 @@ asmb(void)
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f dwarf\n", cputime()); Bprint(&bso, "%5.2f dwarf\n", cputime());
dwarfoff = rnd(HEADR+segtext.len, INITRND) + rnd(segdata.filelen, INITRND); dwarfoff = rnd(HEADR+segtext.length, INITRND) + rnd(segdata.filelen, INITRND);
cseek(dwarfoff); cseek(dwarfoff);
segdwarf.fileoff = cpos(); segdwarf.fileoff = cpos();
...@@ -613,18 +613,17 @@ asmb(void) ...@@ -613,18 +613,17 @@ asmb(void)
Bflush(&bso); Bflush(&bso);
switch(HEADTYPE) { switch(HEADTYPE) {
default: default:
if(iself) if(iself) {
goto Elfsym; symo = segdata.fileoff+segdata.filelen;
symo = rnd(symo, INITRND);
}
break;
case Hplan9: case Hplan9:
symo = segdata.fileoff+segdata.filelen; symo = segdata.fileoff+segdata.filelen;
break; break;
case Hdarwin: case Hdarwin:
symo = segdata.fileoff+rnd(segdata.filelen, INITRND)+machlink; symo = segdata.fileoff+rnd(segdata.filelen, INITRND)+machlink;
break; break;
Elfsym:
symo = segdata.fileoff+segdata.filelen;
symo = rnd(symo, INITRND);
break;
case Hwindows: case Hwindows:
symo = segdata.fileoff+segdata.filelen; symo = segdata.fileoff+segdata.filelen;
symo = rnd(symo, PEFILEALIGN); symo = rnd(symo, PEFILEALIGN);
...@@ -683,7 +682,7 @@ asmb(void) ...@@ -683,7 +682,7 @@ asmb(void)
lputb(magic); /* magic */ lputb(magic); /* magic */
lputb(segtext.filelen); /* sizes */ lputb(segtext.filelen); /* sizes */
lputb(segdata.filelen); lputb(segdata.filelen);
lputb(segdata.len - segdata.filelen); lputb(segdata.length - segdata.filelen);
lputb(symsize); /* nsyms */ lputb(symsize); /* nsyms */
lputb(entryvalue()); /* va of entry */ lputb(entryvalue()); /* va of entry */
lputb(spsize); /* sp offsets */ lputb(spsize); /* sp offsets */
......
...@@ -701,10 +701,10 @@ asmb(void) ...@@ -701,10 +701,10 @@ asmb(void)
sect = segtext.sect; sect = segtext.sect;
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
codeblk(sect->vaddr, sect->len); codeblk(sect->vaddr, sect->length);
for(sect = sect->next; sect != nil; sect = sect->next) { for(sect = sect->next; sect != nil; sect = sect->next) {
cseek(sect->vaddr - segtext.vaddr + segtext.fileoff); cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
datblk(sect->vaddr, sect->len); datblk(sect->vaddr, sect->length);
} }
if(segrodata.filelen > 0) { if(segrodata.filelen > 0) {
...@@ -734,14 +734,13 @@ asmb(void) ...@@ -734,14 +734,13 @@ asmb(void)
Bflush(&bso); Bflush(&bso);
switch(HEADTYPE) { switch(HEADTYPE) {
default: default:
if(iself) if(iself) {
goto ElfSym; symo = segdata.fileoff+segdata.filelen;
case Hplan9: symo = rnd(symo, INITRND);
symo = segdata.fileoff+segdata.filelen; }
break; break;
ElfSym: case Hplan9:
symo = segdata.fileoff+segdata.filelen; symo = segdata.fileoff+segdata.filelen;
symo = rnd(symo, INITRND);
break; break;
} }
cseek(symo); cseek(symo);
...@@ -789,7 +788,7 @@ asmb(void) ...@@ -789,7 +788,7 @@ asmb(void)
thearch.lput(0x647); /* magic */ thearch.lput(0x647); /* magic */
thearch.lput(segtext.filelen); /* sizes */ thearch.lput(segtext.filelen); /* sizes */
thearch.lput(segdata.filelen); thearch.lput(segdata.filelen);
thearch.lput(segdata.len - segdata.filelen); thearch.lput(segdata.length - segdata.filelen);
thearch.lput(symsize); /* nsyms */ thearch.lput(symsize); /* nsyms */
thearch.lput(entryvalue()); /* va of entry */ thearch.lput(entryvalue()); /* va of entry */
thearch.lput(0L); thearch.lput(0L);
...@@ -807,9 +806,9 @@ asmb(void) ...@@ -807,9 +806,9 @@ asmb(void)
if(debug['c']){ if(debug['c']){
print("textsize=%ulld\n", segtext.filelen); print("textsize=%ulld\n", segtext.filelen);
print("datsize=%ulld\n", segdata.filelen); print("datsize=%ulld\n", segdata.filelen);
print("bsssize=%ulld\n", segdata.len - segdata.filelen); print("bsssize=%ulld\n", segdata.length - segdata.filelen);
print("symsize=%d\n", symsize); print("symsize=%d\n", symsize);
print("lcsize=%d\n", lcsize); print("lcsize=%d\n", lcsize);
print("total=%lld\n", segtext.filelen+segdata.len+symsize+lcsize); print("total=%lld\n", segtext.filelen+segdata.length+symsize+lcsize);
} }
} }
This diff is collapsed.
...@@ -167,7 +167,7 @@ decodetype_funcdotdotdot(LSym *s) ...@@ -167,7 +167,7 @@ decodetype_funcdotdotdot(LSym *s)
return s->p[commonsize()]; return s->p[commonsize()];
} }
// Type.FuncType.in.len // Type.FuncType.in.length
int int
decodetype_funcincount(LSym *s) decodetype_funcincount(LSym *s)
{ {
...@@ -202,7 +202,7 @@ decodetype_funcouttype(LSym *s, int i) ...@@ -202,7 +202,7 @@ decodetype_funcouttype(LSym *s, int i)
return decode_reloc_sym(r->sym, r->add + i * thearch.ptrsize); return decode_reloc_sym(r->sym, r->add + i * thearch.ptrsize);
} }
// Type.StructType.fields.Slice::len // Type.StructType.fields.Slice::length
int int
decodetype_structfieldcount(LSym *s) decodetype_structfieldcount(LSym *s)
{ {
...@@ -243,7 +243,7 @@ decodetype_structfieldoffs(LSym *s, int i) ...@@ -243,7 +243,7 @@ decodetype_structfieldoffs(LSym *s, int i)
return decode_inuxi(s->p + commonsize() + thearch.ptrsize + 2*thearch.intsize + i*structfieldsize() + 4*thearch.ptrsize, thearch.intsize); return decode_inuxi(s->p + commonsize() + thearch.ptrsize + 2*thearch.intsize + i*structfieldsize() + 4*thearch.ptrsize, thearch.intsize);
} }
// InterfaceTYpe.methods.len // InterfaceTYpe.methods.length
vlong vlong
decodetype_ifacemethodcount(LSym *s) decodetype_ifacemethodcount(LSym *s)
{ {
......
This diff is collapsed.
...@@ -22,3 +22,4 @@ void dwarfaddshstrings(LSym *shstrtab); ...@@ -22,3 +22,4 @@ void dwarfaddshstrings(LSym *shstrtab);
void dwarfaddelfheaders(void); void dwarfaddelfheaders(void);
void dwarfaddmachoheaders(void); void dwarfaddmachoheaders(void);
void dwarfaddpeheaders(void); void dwarfaddpeheaders(void);
void dwarfaddelfsectionsyms(void);
This diff is collapsed.
This diff is collapsed.
...@@ -74,27 +74,27 @@ static int parsemethod(char**, char*, char**); ...@@ -74,27 +74,27 @@ static int parsemethod(char**, char*, char**);
static int parsepkgdata(char*, char*, char**, char*, char**, char**, char**); static int parsepkgdata(char*, char*, char**, char*, char**, char**, char**);
void void
ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence) ldpkg(Biobuf *f, char *pkg, int64 length, char *filename, int whence)
{ {
char *data, *p0, *p1, *name; char *data, *p0, *p1, *name;
if(debug['g']) if(debug['g'])
return; return;
if((int)len != len) { if((int)length != length) {
fprint(2, "%s: too much pkg data in %s\n", argv0, filename); fprint(2, "%s: too much pkg data in %s\n", argv0, filename);
if(debug['u']) if(debug['u'])
errorexit(); errorexit();
return; return;
} }
data = mal(len+1); data = mal(length+1);
if(Bread(f, data, len) != len) { if(Bread(f, data, length) != length) {
fprint(2, "%s: short pkg read %s\n", argv0, filename); fprint(2, "%s: short pkg read %s\n", argv0, filename);
if(debug['u']) if(debug['u'])
errorexit(); errorexit();
return; return;
} }
data[len] = '\0'; data[length] = '\x00';
// first \n$$ marks beginning of exports - skip rest of line // first \n$$ marks beginning of exports - skip rest of line
p0 = strstr(data, "\n$$"); p0 = strstr(data, "\n$$");
...@@ -106,7 +106,7 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence) ...@@ -106,7 +106,7 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence)
return; return;
} }
p0 += 3; p0 += 3;
while(*p0 != '\n' && *p0 != '\0') while(*p0 != '\n' && *p0 != '\x00')
p0++; p0++;
// second marks end of exports / beginning of local data // second marks end of exports / beginning of local data
...@@ -140,11 +140,11 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence) ...@@ -140,11 +140,11 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence)
} }
if(p0 < p1) { if(p0 < p1) {
if(*p0 == '\n') if(*p0 == '\n')
*p0++ = '\0'; *p0++ = '\x00';
else { else {
*p0++ = '\0'; *p0++ = '\x00';
while(p0 < p1 && *p0++ != '\n') while(p0 < p1 && *p0 != '\n')
; p0++;
} }
} }
if(strcmp(pkg, "main") == 0 && strcmp(name, "main") != 0) { if(strcmp(pkg, "main") == 0 && strcmp(name, "main") != 0) {
...@@ -183,14 +183,14 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence) ...@@ -183,14 +183,14 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence)
} }
static void static void
loadpkgdata(char *file, char *pkg, char *data, int len) loadpkgdata(char *file, char *pkg, char *data, int length)
{ {
char *p, *ep, *prefix, *name, *def; char *p, *ep, *prefix, *name, *def;
Import *x; Import *x;
file = estrdup(file); file = estrdup(file);
p = data; p = data;
ep = data + len; ep = data + length;
while(parsepkgdata(file, pkg, &p, ep, &prefix, &name, &def) > 0) { while(parsepkgdata(file, pkg, &p, ep, &prefix, &name, &def) > 0) {
x = ilookup(name); x = ilookup(name);
if(x->prefix == nil) { if(x->prefix == nil) {
...@@ -253,7 +253,7 @@ loop: ...@@ -253,7 +253,7 @@ loop:
nerrors++; nerrors++;
return -1; return -1;
} }
*p++ = '\0'; *p++ = '\x00';
imported(pkg, name); imported(pkg, name);
goto loop; goto loop;
} }
...@@ -262,7 +262,7 @@ loop: ...@@ -262,7 +262,7 @@ loop:
nerrors++; nerrors++;
return -1; return -1;
} }
p[-1] = '\0'; p[-1] = '\x00';
// name: a.b followed by space // name: a.b followed by space
name = p; name = p;
...@@ -281,7 +281,7 @@ loop: ...@@ -281,7 +281,7 @@ loop:
if(p >= ep) if(p >= ep)
return -1; return -1;
*p++ = '\0'; *p++ = '\x00';
// def: free form to new line // def: free form to new line
def = p; def = p;
...@@ -290,11 +290,11 @@ loop: ...@@ -290,11 +290,11 @@ loop:
if(p >= ep) if(p >= ep)
return -1; return -1;
edef = p; edef = p;
*p++ = '\0'; *p++ = '\x00';
// include methods on successive lines in def of named type // include methods on successive lines in def of named type
while(parsemethod(&p, ep, &meth) > 0) { while(parsemethod(&p, ep, &meth) > 0) {
*edef++ = '\n'; // overwrites '\0' *edef++ = '\n'; // overwrites '\x00'
if(edef+1 > meth) { if(edef+1 > meth) {
// We want to indent methods with a single \t. // We want to indent methods with a single \t.
// 6g puts at least one char of indent before all method defs, // 6g puts at least one char of indent before all method defs,
...@@ -355,7 +355,7 @@ useline: ...@@ -355,7 +355,7 @@ useline:
*pp = ep; *pp = ep;
return -1; return -1;
} }
*p++ = '\0'; *p++ = '\x00';
*pp = p; *pp = p;
return 1; return 1;
} }
...@@ -376,7 +376,7 @@ loadcgo(char *file, char *pkg, char *p, int n) ...@@ -376,7 +376,7 @@ loadcgo(char *file, char *pkg, char *p, int n)
if(next == nil) if(next == nil)
next = ""; next = "";
else else
*next++ = '\0'; *next++ = '\x00';
free(p0); free(p0);
p0 = estrdup(p); // save for error message p0 = estrdup(p); // save for error message
...@@ -411,7 +411,7 @@ loadcgo(char *file, char *pkg, char *p, int n) ...@@ -411,7 +411,7 @@ loadcgo(char *file, char *pkg, char *p, int n)
local = expandpkg(local, pkg); local = expandpkg(local, pkg);
q = strchr(remote, '#'); q = strchr(remote, '#');
if(q) if(q)
*q++ = '\0'; *q++ = '\x00';
s = linklookup(ctxt, local, 0); s = linklookup(ctxt, local, 0);
if(local != f[1]) if(local != f[1])
free(local); free(local);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -96,14 +96,12 @@ struct Segment ...@@ -96,14 +96,12 @@ struct Segment
{ {
uchar rwx; // permission as usual unix bits (5 = r-x etc) uchar rwx; // permission as usual unix bits (5 = r-x etc)
uvlong vaddr; // virtual address uvlong vaddr; // virtual address
uvlong len; // length in memory uvlong length; // length in memory
uvlong fileoff; // file offset uvlong fileoff; // file offset
uvlong filelen; // length on disk uvlong filelen; // length on disk
Section* sect; Section* sect;
}; };
#pragma incomplete struct Elf64_Shdr
struct Section struct Section
{ {
uchar rwx; uchar rwx;
...@@ -111,10 +109,10 @@ struct Section ...@@ -111,10 +109,10 @@ struct Section
int32 align; int32 align;
char *name; char *name;
uvlong vaddr; uvlong vaddr;
uvlong len; uvlong length;
Section *next; // in segment list Section *next; // in segment list
Segment *seg; Segment *seg;
struct Elf64_Shdr *elfsect; void *elfsect;
uvlong reloff; uvlong reloff;
uvlong rellen; uvlong rellen;
}; };
...@@ -191,14 +189,7 @@ enum { ...@@ -191,14 +189,7 @@ enum {
Pkgdef Pkgdef
}; };
typedef struct Header Header;
struct Header {
char *name;
int val;
};
EXTERN char* headstring; EXTERN char* headstring;
extern Header headers[];
#pragma varargck type "Y" LSym* #pragma varargck type "Y" LSym*
#pragma varargck type "Z" char* #pragma varargck type "Z" char*
...@@ -208,19 +199,8 @@ extern Header headers[]; ...@@ -208,19 +199,8 @@ extern Header headers[];
EXTERN Biobuf bso; EXTERN Biobuf bso;
EXTERN struct EXTERN Biobuf coutbuf;
{ void cput(uint8);
char cbuf[MAXIO]; /* output buffer */
} buf;
EXTERN int cbc;
EXTERN char* cbp;
EXTERN char* cbpmax;
#define cput(c)\
{ *cbp++ = c;\
if(--cbc <= 0)\
cflush(); }
void Lflag(char *arg); void Lflag(char *arg);
int Yconv(Fmt *fp); int Yconv(Fmt *fp);
...@@ -289,17 +269,19 @@ void hostobjs(void); ...@@ -289,17 +269,19 @@ void hostobjs(void);
int iconv(Fmt *fp); int iconv(Fmt *fp);
void importcycles(void); void importcycles(void);
void linkarchinit(void); void linkarchinit(void);
void ldelf(Biobuf *f, char *pkg, int64 len, char *pn); void ldelf(Biobuf *f, char *pkg, int64 length, char *pn);
void ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64 len, char *pn, char *file); void ldhostobj(void (*ld)(Biobuf*, char*, int64, char*), Biobuf *f, char *pkg, int64 length, char *pn, char *file);
void ldmacho(Biobuf *f, char *pkg, int64 len, char *pn); void ldmacho(Biobuf *f, char *pkg, int64 length, char *pn);
void ldobj(Biobuf *f, char *pkg, int64 len, char *pn, char *file, int whence); void ldobj(Biobuf *f, char *pkg, int64 length, char *pn, char *file, int whence);
void ldpe(Biobuf *f, char *pkg, int64 len, char *pn); void ldpe(Biobuf *f, char *pkg, int64 length, char *pn);
void ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence); void ldpkg(Biobuf *f, char *pkg, int64 length, char *filename, int whence);
uint16 le16(uchar *b); uint16 le16(uchar *b);
uint32 le32(uchar *b); uint32 le32(uchar *b);
uint64 le64(uchar *b); uint64 le64(uchar *b);
void libinit(void); void libinit(void);
LSym* listsort(LSym *l, int (*cmp)(LSym*, LSym*), int off); LSym* listsort(LSym *l, int (*cmp)(LSym*, LSym*), LSym** (*nextp)(LSym*));
LSym** listnextp(LSym*);
LSym** listsubp(LSym*);
void loadinternal(char *name); void loadinternal(char *name);
void loadlib(void); void loadlib(void);
void lputb(uint32 l); void lputb(uint32 l);
...@@ -307,7 +289,6 @@ void lputl(uint32 l); ...@@ -307,7 +289,6 @@ void lputl(uint32 l);
void* mal(uint32 n); void* mal(uint32 n);
void mark(LSym *s); void mark(LSym *s);
void mywhatsys(void); void mywhatsys(void);
struct ar_hdr;
void objfile(char *file, char *pkg); void objfile(char *file, char *pkg);
void patch(void); void patch(void);
int pathchar(void); int pathchar(void);
...@@ -345,4 +326,3 @@ void ldmain(int, char**); ...@@ -345,4 +326,3 @@ void ldmain(int, char**);
#pragma varargck argpos diag 1 #pragma varargck argpos diag 1
#define SYMDEF "__.GOSYMDEF"
This diff is collapsed.
...@@ -53,14 +53,15 @@ int machowrite(void); ...@@ -53,14 +53,15 @@ int machowrite(void);
void machoinit(void); void machoinit(void);
void machosymorder(void); void machosymorder(void);
void machoemitreloc(void); void machoemitreloc(void);
int machoreloc1(Reloc*, vlong);
/* /*
* Total amount of space to reserve at the start of the file * Total amount of space to reserve at the start of the file
* for Header, PHeaders, and SHeaders. * for Header, PHeaders, and SHeaders.
* May waste some. * May waste some.
*/ */
#define INITIAL_MACHO_HEADR 4*1024 enum {
INITIAL_MACHO_HEADR = 4*1024,
};
enum { enum {
MACHO_CPU_AMD64 = (1<<24)|7, MACHO_CPU_AMD64 = (1<<24)|7,
......
This diff is collapsed.
This diff is collapsed.
...@@ -153,9 +153,6 @@ ldmain(int argc, char **argv) ...@@ -153,9 +153,6 @@ ldmain(int argc, char **argv)
HEADTYPE, INITTEXT, INITDAT, INITRND); HEADTYPE, INITTEXT, INITDAT, INITRND);
Bflush(&bso); Bflush(&bso);
cbp = buf.cbuf;
cbc = sizeof(buf.cbuf);
addlibpath(ctxt, "command line", "command line", argv[0], "main"); addlibpath(ctxt, "command line", "command line", argv[0], "main");
loadlib(); loadlib();
......
This diff is collapsed.
...@@ -111,13 +111,11 @@ static char *rdstring(Biobuf*); ...@@ -111,13 +111,11 @@ static char *rdstring(Biobuf*);
static void rddata(Biobuf*, uchar**, int*); static void rddata(Biobuf*, uchar**, int*);
static LSym *rdsym(Link*, Biobuf*, char*); static LSym *rdsym(Link*, Biobuf*, char*);
extern char *outfile;
static char startmagic[] = "\x00\x00go13ld"; static char startmagic[] = "\x00\x00go13ld";
static char endmagic[] = "\xff\xffgo13ld"; static char endmagic[] = "\xff\xffgo13ld";
void void
ldobjfile(Link *ctxt, Biobuf *f, char *pkg, int64 len, char *pn) ldobjfile(Link *ctxt, Biobuf *f, char *pkg, int64 length, char *pn)
{ {
int c; int c;
uchar buf[8]; uchar buf[8];
...@@ -153,8 +151,8 @@ ldobjfile(Link *ctxt, Biobuf *f, char *pkg, int64 len, char *pn) ...@@ -153,8 +151,8 @@ ldobjfile(Link *ctxt, Biobuf *f, char *pkg, int64 len, char *pn)
if(memcmp(buf, endmagic, sizeof buf) != 0) if(memcmp(buf, endmagic, sizeof buf) != 0)
sysfatal("%s: invalid file end", pn); sysfatal("%s: invalid file end", pn);
if(Boffset(f) != start+len) if(Boffset(f) != start+length)
sysfatal("%s: unexpected end at %lld, want %lld", pn, (vlong)Boffset(f), (vlong)(start+len)); sysfatal("%s: unexpected end at %lld, want %lld", pn, (vlong)Boffset(f), (vlong)(start+length));
} }
static void static void
......
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