From 88f84b3e415ad226f9724dc486be0f1b363b9f05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9my=20Oudompheng?= Date: Fri, 14 Mar 2014 21:33:55 +0100 Subject: [PATCH] liblink, runtime: make nacl/386 binaries valid. They were rejected by NaCl due to AES instructions and accesses to %gs:0x8, caused by wrong tlsoffset value. LGTM=iant R=rsc, dave, iant CC=golang-codereviews https://golang.org/cl/76050044 --- src/liblink/sym.c | 13 +++++++++++-- src/pkg/runtime/alg.goc | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/liblink/sym.c b/src/liblink/sym.c index 0c7aae00a1..3990f7200e 100644 --- a/src/liblink/sym.c +++ b/src/liblink/sym.c @@ -139,9 +139,18 @@ linknew(LinkArch *arch) */ ctxt->tlsoffset = -2*ctxt->arch->ptrsize; break; - + case Hnacl: - ctxt->tlsoffset = 0; + 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: diff --git a/src/pkg/runtime/alg.goc b/src/pkg/runtime/alg.goc index 81eb1664a9..9fb54cac3f 100644 --- a/src/pkg/runtime/alg.goc +++ b/src/pkg/runtime/alg.goc @@ -21,7 +21,7 @@ runtime·memhash(uintptr *h, uintptr s, void *a) { byte *b; uintptr hash; - if(use_aeshash) { + if(!NaCl && use_aeshash) { runtime·aeshash(h, s, a); return; } @@ -470,6 +470,9 @@ byte runtime·aeskeysched[HashRandomBytes]; void runtime·hashinit(void) { + if(NaCl) + return; + // Install aes hash algorithm if we have the instructions we need if((runtime·cpuid_ecx & (1 << 25)) != 0 && // aes (aesenc) (runtime·cpuid_ecx & (1 << 9)) != 0 && // sse3 (pshufb) -- 2.50.0