Ejemplo n.º 1
0
void
mywhatsys(void)
{
	goroot = getgoroot();
	goos = getgoos();
	goarch = thestring;	// ignore $GOARCH - we know who we are
}
Ejemplo n.º 2
0
Link*
linknew(LinkArch *arch)
{
	Link *ctxt;
	char *p;
	char buf[1024];

	nuxiinit();
	
	ctxt = emallocz(sizeof *ctxt);
	ctxt->arch = arch;
	ctxt->version = HistVersion;
	ctxt->goroot = getgoroot();
	ctxt->goroot_final = getenv("GOROOT_FINAL");
	if(ctxt->goroot_final != nil && ctxt->goroot_final[0] == '\0')
		ctxt->goroot_final = nil;

	p = getgoarch();
	if(strcmp(p, arch->name) != 0)
		sysfatal("invalid goarch %s (want %s)", p, arch->name);
	
	if(getwd(buf, sizeof buf) == 0)
		strcpy(buf, "/???");
	if(yy_isalpha(buf[0]) && buf[1] == ':') {
		// On Windows.
		ctxt->windows = 1;

		// Canonicalize path by converting \ to / (Windows accepts both).
		for(p=buf; *p; p++)
			if(*p == '\\')
				*p = '/';
	}
	ctxt->pathname = strdup(buf);
	
	ctxt->headtype = headtype(getgoos());
	if(ctxt->headtype < 0)
		sysfatal("unknown goos %s", getgoos());
	
	// Record thread-local storage offset.
	// TODO(rsc): Move tlsoffset back into the linker.
	switch(ctxt->headtype) {
	default:
		sysfatal("unknown thread-local storage offset for %s", headstr(ctxt->headtype));
	case Hplan9:
		ctxt->tlsoffset = -2*ctxt->arch->ptrsize;
		break;
	case Hwindows:
		break;
	case Hlinux:
	case Hfreebsd:
	case Hnetbsd:
	case Hopenbsd:
	case Hdragonfly:
	case Hsolaris:
		/*
		 * ELF uses TLS offset negative from FS.
		 * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS).
		 * Known to low-level assembly in package runtime and runtime/cgo.
		 */
		ctxt->tlsoffset = -2*ctxt->arch->ptrsize;
		break;

	case Hnacl:
		switch(ctxt->arch->thechar) {
		default:
			sysfatal("unknown thread-local storage offset for nacl/%s", ctxt->arch->name);
		case '6':
			ctxt->tlsoffset = 0;
			break;
		case '8':
			ctxt->tlsoffset = -8;
			break;
		}
		break;

	case Hdarwin:
		/*
		 * OS X system constants - offset from 0(GS) to our TLS.
		 * Explained in ../../pkg/runtime/cgo/gcc_darwin_*.c.
		 */
		switch(ctxt->arch->thechar) {
		default:
			sysfatal("unknown thread-local storage offset for darwin/%s", ctxt->arch->name);
		case '6':
			ctxt->tlsoffset = 0x8a0;
			break;
		case '8':
			ctxt->tlsoffset = 0x468;
			break;
		}
		break;
	}
	
	// On arm, record goarm.
	if(ctxt->arch->thechar == '5') {
		p = getgoarm();
		if(p != nil)
			ctxt->goarm = atoi(p);
		else
			ctxt->goarm = 6;
	}

	return ctxt;
}