diff --git a/.gitignore b/.gitignore index fdf335c..766d48f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,11 +8,13 @@ *.swp *.mo */build -/bin -/pkg -/android/pkg -/android/bin -/android/gen -/android/obj -/android/libs -/android/local.properties +bin +pkg +*/android/pkg +*/android/bin +*/android/gen +*/android/obj +*/android/libs +*/android/local.properties +/go +/ndk-toolchain diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..57f6b0e --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +Copyright (c) 2013, Elias Naur +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 351585f..785d84c 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,28 @@ goandroid ========= -Patches to the Go tools and runtime to enable Android apps to interface directly with a shared library written in Go. Goandroid also includes a simple demo written in Go, showing off OpenGL ES 2 and touch input. +Patches to the Go tools and runtime to enable Android apps to interface directly with a shared library written in Go. Goandroid also includes two demos, `hellogl2` and `nativeactivity`, both written in Go. Goandroid currently runs on ARMv7 or later CPUs. -Running [Go](http://golang.org) code from Android apps is currently not possible, because the Go tools can only output executables while Android requires any foreign code in shared library (.so) format. This repository contains patches for the Go tools and runtime to enable shared library output, including workarounds to Android specific limitations. It also includes a simple example app written in Go to demonstrate OpenGL ES 2 graphics and touch input. +Running [Go](http://golang.org) code from Android apps is currently not possible, because the Go tools can only output executables while Android requires any foreign code in shared library (.so) format. This repository contains patches for the Go tools and runtime to enable shared library output, including workarounds to Android specific limitations. -This guide assumes you're running linux and have an android device connected through USB. +*Disclaimer*: Please note that the patches are unofficial, and while I hope the Go developers will eventually incorporate at least the patches not specific to Android, there's no guarantee they will. Also note that goandroid only includes the bare minimum to let Go run in Android apps. If you need a more comprehensive framework, check out [Mandala](https://github.com/remogatto/mandala). ### Set up ### -1. Make sure [mercurial](http://mercurial.selenic.com/) is installed -2. Download and install the [NDK](http://developer.android.com/tools/sdk/ndk/index.html). These instructions assumes the NDK is installed in `$NDK`. -3. Create a standalone NDK toolchain (as described in $NDK/docs/STANDALONE-TOOLCHAIN.html): +This guide is tested on linux/amd64 and assumes you have an android device connected through USB and that you meet the requirements for [building Go from source](http://golang.org/doc/install/source). + +1. Download and install the [NDK](http://developer.android.com/tools/sdk/ndk/index.html) at least version r8e. These instructions assumes the NDK is installed in `$NDK`. +2. Create a standalone NDK toolchain (as described in $NDK/docs/STANDALONE-TOOLCHAIN.html): `$NDK/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=ndk-toolchain` You might need to add `--system=linux-x86_64` or `--system=darwin-x86_64` depending on your system. - Set `$NDK_TOOLCHAIN` to point at the `ndk-toolchain` directory + Set `$NDK_ROOT` to point at the `ndk-toolchain` directory 3. Clone the golang repository: - `hg clone https://code.google.com/p/go` + `hg clone -u release https://code.google.com/p/go` 4. Copy the `patches` directory to the `go/.hg` directory: @@ -31,7 +32,8 @@ This guide assumes you're running linux and have an android device connected thr ``` [extensions] - mq = + mq = + codereview = ! [ui] username = me @@ -42,14 +44,18 @@ This guide assumes you're running linux and have an android device connected thr ``` cd go/src hg qpush -a - CGO_ENABLED=0 GOARCH=arm ./make.bash - CC="$NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc" GOARCH=arm GOARM=7 CGO_ENABLED=1 ../bin/go install -tags android -a -v std + CGO_ENABLED=0 GOOS=linux GOARCH=arm ./make.bash \ + CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc" GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 ../bin/go install -tags android -a -v std cd ../.. ``` -### Building and installing the example app ### +### Building and installing the example apps ### + +If everything is set up correctly, you should be able to `cd hello-gl2` and run `build.sh` to build and copy `libgoandroid.so` to android/libs. Then, running `ant -f android/build.xml clean debug install` will build and install the final apk to the connected device. Running the app should display a simple color animated triangle that you can move around the screen with your finger. + +A more complicated but also more useful example is `nativeactivity`. It mimicks the C/C++ `native_app_glue` library and uses the NativeActivity API to completely avoid Java code and gain control of the input and render loop as well as context creation through EGL. It can be compiled and installed in the same way as `hellogl2` with `./build.sh` and `ant -f android/build.xml clean debug install`. The nativeactivity sample requires Android 2.3, which is the version where NativeActivity were introduced. -If everything is set up correctly, you should be able to run `build.sh` in the goandroid root to build and copy `libandroid.so` to android/libs. Then, running `ant -f android/build.xml clean debug install` will build and install the final apk to the connected device. Running the app should display a simple color animated triangle that you can move around the screen with your finger. +An interesting artifact of Go apps is that the compile-deploy cycle can be shorter than the ant scripts. If an existing debug apk is already present after an `ant -f android/build.xml clean debug install` you can use `./upload.sh` to replace the Go library and upload the apk to the device. On my system, `touch src/nativeactivity/main.go android/AndroidManifest.xml && time ./build.sh && time ant -f android/build.xml debug install` takes 17 seconds, while `touch src/nativeactivity/main.go && time ./upload.sh` takes 10 seconds. This difference will only be more exaggerated if the apk contains resources. ### Go patches ### diff --git a/build.sh b/build.sh deleted file mode 100755 index 35c0a73..0000000 --- a/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -e - -mkdir -p android/libs/armeabi-v7a -mkdir -p android/obj/local/armeabi-v7a -CC="$NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc" -GO="`pwd`/go/bin/go" -CC=$CC GOPATH="`pwd`:$GOPATH" GOARCH=arm GOARM=7 CGO_ENABLED=1 $GO install $GOFLAGS -v -ldflags="-android -shared -extld $CC -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'" -tags android goandroid -cp bin/linux_arm/goandroid android/libs/armeabi-v7a/libgoandroid.so -cp bin/linux_arm/goandroid android/obj/local/armeabi-v7a/libgoandroid.so diff --git a/android/AndroidManifest.xml b/hello-gl2/android/AndroidManifest.xml similarity index 95% rename from android/AndroidManifest.xml rename to hello-gl2/android/AndroidManifest.xml index adbf034..f45f3b1 100644 --- a/android/AndroidManifest.xml +++ b/hello-gl2/android/AndroidManifest.xml @@ -1,6 +1,6 @@ diff --git a/android/ant.properties b/hello-gl2/android/ant.properties similarity index 100% rename from android/ant.properties rename to hello-gl2/android/ant.properties diff --git a/android/build.xml b/hello-gl2/android/build.xml similarity index 98% rename from android/build.xml rename to hello-gl2/android/build.xml index 1064ae5..a8d0144 100644 --- a/android/build.xml +++ b/hello-gl2/android/build.xml @@ -1,5 +1,5 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/native-activity/android/proguard-project.txt b/native-activity/android/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/native-activity/android/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/native-activity/android/project.properties b/native-activity/android/project.properties new file mode 100644 index 0000000..a3ee5ab --- /dev/null +++ b/native-activity/android/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-17 diff --git a/native-activity/android/res/values/strings.xml b/native-activity/android/res/values/strings.xml new file mode 100644 index 0000000..aca86b7 --- /dev/null +++ b/native-activity/android/res/values/strings.xml @@ -0,0 +1,4 @@ + + + Go Native Activity! + diff --git a/native-activity/android/src/dummy b/native-activity/android/src/dummy new file mode 100644 index 0000000..e69de29 diff --git a/native-activity/build.sh b/native-activity/build.sh new file mode 100755 index 0000000..5339e47 --- /dev/null +++ b/native-activity/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +mkdir -p android/libs/armeabi-v7a +mkdir -p android/obj/local/armeabi-v7a +CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc" +CC=$CC GOPATH="`pwd`:$GOPATH" GOROOT="" GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 ../go/bin/go install $GOFLAGS -v -ldflags="-android -shared -extld $CC -extldflags '-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16'" -tags android nativeactivity +cp bin/linux_arm/nativeactivity android/libs/armeabi-v7a/libnativeactivity.so +cp bin/linux_arm/nativeactivity android/obj/local/armeabi-v7a/libnativeactivity.so diff --git a/native-activity/refresh.sh b/native-activity/refresh.sh new file mode 100755 index 0000000..b4a1f43 --- /dev/null +++ b/native-activity/refresh.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +APKNAME=nativeactivity + +cd android +ln -sT libs lib +zip -u bin/$APKNAME-debug.apk lib/armeabi-v7a/lib$APKNAME.so +rm lib +cd .. +./signapk.sh "android/bin/$APKNAME-debug.apk" +mv signed_$APKNAME-debug.apk "android/bin/$APKNAME-debug.apk" diff --git a/native-activity/signapk.sh b/native-activity/signapk.sh new file mode 100755 index 0000000..b29f7e1 --- /dev/null +++ b/native-activity/signapk.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# +# Original signapk.sh script from https://code.google.com/p/apk-resigner/ +# +# Sample usage is as follows; +# ./signapk myapp.apk debug.keystore android androiddebugkey +# +# param1, APK file: Calculator_debug.apk +# param2, keystore location: ~/.android/debug.keystore +# param3, key storepass: android +# param4, key alias: androiddebugkey + +USER_HOME=$(eval echo ~${SUDO_USER}) + +# use my debug key default +APK=$1 +KEYSTORE="${2:-$USER_HOME/.android/debug.keystore}" +STOREPASS="${3:-android}" +ALIAS="${4:-androiddebugkey}" + +APK_BASENAME=$(basename $APK) +SIGNED_APK="signed_"$APK_BASENAME + +# delete META-INF folder +zip -d $APK META-INF/\* + +# sign APK +jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore $KEYSTORE -storepass $STOREPASS $APK $ALIAS + +#verify +#jarsigner -verify $APK + +#zipalign +zipalign 4 $APK $SIGNED_APK diff --git a/native-activity/src/nativeactivity/game.go b/native-activity/src/nativeactivity/game.go new file mode 100644 index 0000000..c29fe6c --- /dev/null +++ b/native-activity/src/nativeactivity/game.go @@ -0,0 +1,219 @@ +package main + +/* +#include +#include +#include + +#cgo android LDFLAGS: -lGLESv2 +*/ +import "C" + +import ( + "fmt" + "log" + "math" + "unsafe" +) + +var time float64 + +type game struct { + prog C.GLuint + width, height int + offsetUni, colorUni int + + offsetX, offsetY float32 + + touching bool + touchX, touchY float32 +} + +const vertShaderSrcDef = ` + uniform vec2 offset; + attribute vec4 vPosition; + + void main() { + gl_Position = vec4(vPosition.xy+offset, vPosition.zw); + } +` + +const fragShaderSrcDef = ` + precision mediump float; + + uniform vec3 color; + + void main() { + gl_FragColor = vec4(color.xyz, 1.0); + } +` + +func GetShaderInfoLog(shader C.GLuint) string { + var logLen C.GLint + C.glGetShaderiv(shader, C.GL_INFO_LOG_LENGTH, &logLen) + var c C.GLchar + logLenBytes := int(logLen) * int(unsafe.Sizeof(c)) + log := C.malloc(C.size_t(logLenBytes)) + if log == nil { + panic("Failed to allocate shader log buffer") + } + defer C.free(log) + C.glGetShaderInfoLog(C.GLuint(shader), C.GLsizei(logLen), (*C.GLsizei)(unsafe.Pointer(nil)), (*C.GLchar)(log)) + return string(C.GoBytes(log, C.int(logLenBytes))) +} + +func GetProgramInfoLog(program C.GLuint) string { + var logLen C.GLint + C.glGetProgramiv(program, C.GL_INFO_LOG_LENGTH, &logLen) + var c C.GLchar + logLenBytes := int(logLen) * int(unsafe.Sizeof(c)) + log := C.malloc(C.size_t(logLenBytes)) + if log == nil { + panic("Failed to allocate shader log buffer") + } + defer C.free(log) + C.glGetProgramInfoLog(C.GLuint(program), C.GLsizei(logLen), (*C.GLsizei)(unsafe.Pointer(nil)), (*C.GLchar)(log)) + return string(C.GoBytes(log, C.int(logLenBytes))) +} + +func loadShader(shaderType C.GLenum, source string) C.GLuint { + handle := C.glCreateShader(shaderType) + if handle == 0 { + panic(fmt.Errorf("Failed to create shader of type %v", shaderType)) + } + sourceC := C.CString(source) + defer C.free(unsafe.Pointer(sourceC)) + C.glShaderSource(handle, 1, (**C.GLchar)(unsafe.Pointer(&sourceC)), (*C.GLint)(unsafe.Pointer(nil))) + C.glCompileShader(handle) + var compiled C.GLint + C.glGetShaderiv(handle, C.GL_COMPILE_STATUS, &compiled) + if compiled != C.GL_TRUE { + log := GetShaderInfoLog(handle) + panic(fmt.Errorf("Failed to compile shader: %v, shader: %v", log, source)) + } + return handle +} + +func GenBuffer() C.GLuint { + var buf C.GLuint + C.glGenBuffers(1, &buf) + return C.GLuint(buf) +} + +func checkGLError() { + if glErr := C.glGetError(); glErr != C.GL_NO_ERROR { + panic(fmt.Errorf("C.gl error: %v", glErr)) + } +} + +func createProgram(vertShaderSrc string, fragShaderSrc string) C.GLuint { + vertShader := loadShader(C.GL_VERTEX_SHADER, vertShaderSrc) + fragShader := loadShader(C.GL_FRAGMENT_SHADER, fragShaderSrc) + prog := C.glCreateProgram() + if prog == 0 { + panic("Failed to create shader program") + } + C.glAttachShader(prog, vertShader) + checkGLError() + C.glAttachShader(prog, fragShader) + checkGLError() + C.glLinkProgram(prog) + var linkStatus C.GLint + C.glGetProgramiv(prog, C.GL_LINK_STATUS, &linkStatus) + if linkStatus != C.GL_TRUE { + log := GetProgramInfoLog(prog) + panic(fmt.Errorf("Failed to link program: %v", log)) + } + return prog +} + +func attribLocation(prog C.GLuint, name string) int { + nameC := C.CString(name) + defer C.free(unsafe.Pointer(nameC)) + attrib := int(C.glGetAttribLocation(C.GLuint(prog), (*C.GLchar)(unsafe.Pointer(nameC)))) + checkGLError() + if attrib == -1 { + panic(fmt.Errorf("Failed to find attrib position for %v", name)) + } + return attrib +} + +func uniformLocation(prog C.GLuint, name string) int { + nameC := C.CString(name) + defer C.free(unsafe.Pointer(nameC)) + attrib := int(C.glGetUniformLocation(C.GLuint(prog), (*C.GLchar)(unsafe.Pointer(nameC)))) + checkGLError() + if attrib == -1 { + panic(fmt.Errorf("Failed to find attrib position for %v", name)) + } + return attrib +} + +func GetString(name C.GLenum) string { + val := C.glGetString(C.GLenum(name)) + return C.GoString((*C.char)(unsafe.Pointer(val))) +} + +func (game *game) resize(width, height int) { + game.width = width + game.height = height + C.glViewport(0, 0, C.GLsizei(width), C.GLsizei(height)) +} + +func (game *game) initGL() { + log.Printf("GL_VERSION: %v GL_RENDERER: %v GL_VENDOR %v\n", + GetString(C.GL_VERSION), GetString(C.GL_RENDERER), GetString(C.GL_VENDOR)) + log.Printf("GL_EXTENSIONS: %v\n", GetString(C.GL_EXTENSIONS)) + C.glClearColor(0.0, 0.0, 0.0, 1.0) + C.glEnable(C.GL_CULL_FACE) + C.glEnable(C.GL_DEPTH_TEST) + + game.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef) + posAttrib := attribLocation(game.prog, "vPosition") + game.offsetUni = uniformLocation(game.prog, "offset") + game.colorUni = uniformLocation(game.prog, "color") + C.glUseProgram(game.prog) + C.glEnableVertexAttribArray(C.GLuint(posAttrib)) + + vertVBO := GenBuffer() + checkGLError() + C.glBindBuffer(C.GL_ARRAY_BUFFER, vertVBO) + verts := []float32{.0, 0.5, -0.5, -0.5, 0.5, -0.5} + C.glBufferData(C.GL_ARRAY_BUFFER, C.GLsizeiptr(len(verts)*int(unsafe.Sizeof(verts[0]))), unsafe.Pointer(&verts[0]), C.GL_STATIC_DRAW) + C.glVertexAttribPointer(C.GLuint(posAttrib), 2, C.GL_FLOAT, C.GL_FALSE, 0, unsafe.Pointer(uintptr(0))) +} + +func (game *game) drawFrame() { + time += .05 + color := (C.GLclampf(math.Sin(time)) + 1) * .5 + + offX := game.offsetX + offY := game.offsetY + C.glUniform2f(C.GLint(game.offsetUni), C.GLfloat(offX), C.GLfloat(offY)) + C.glUniform3f(C.GLint(game.colorUni), 1.0, C.GLfloat(color), 0) + C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT) + + C.glUseProgram(game.prog) + C.glDrawArrays(C.GL_TRIANGLES, 0, 3) +} + +func (game *game) onTouch(event *C.AInputEvent) bool { + action := C.AMotionEvent_getAction(event) & C.AMOTION_EVENT_ACTION_MASK + x := float32(C.AMotionEvent_getX(event, 0)) + y := float32(C.AMotionEvent_getY(event, 0)) + switch action { + case C.AMOTION_EVENT_ACTION_UP: + game.touching = false + case C.AMOTION_EVENT_ACTION_DOWN: + game.touching = true + game.touchX, game.touchY = x, y + case C.AMOTION_EVENT_ACTION_MOVE: + if !game.touching { + break + } + game.offsetX += 2 * (x - game.touchX) / float32(game.width) + game.offsetY += 2 * -(y - game.touchY) / float32(game.height) + game.touchX, game.touchY = x, y + } + return true +} diff --git a/native-activity/src/nativeactivity/log_android.go b/native-activity/src/nativeactivity/log_android.go new file mode 100644 index 0000000..3fc9d72 --- /dev/null +++ b/native-activity/src/nativeactivity/log_android.go @@ -0,0 +1,37 @@ +// +build android +package main + +// #include +// #cgo LDFLAGS: -llog +import "C" + +import ( + "bytes" + "log" + "unsafe" +) + +var ctag *C.char = C.CString("Go runtime") + +func init() { + log.SetOutput(&androidWriter{}) +} + +type androidWriter struct { + buf []byte +} + +func (aw *androidWriter) Write(p []byte) (n int, err error) { + n = len(p) + err = nil + for nlidx := bytes.IndexByte(p, '\n'); nlidx != -1; nlidx = bytes.IndexByte(p, '\n'){ + aw.buf = append(aw.buf, p[:nlidx]...) + p = p[nlidx+1:] + aw.buf = append(aw.buf, 0) + cstr := (*C.char)(unsafe.Pointer(&aw.buf[0])) + C.__android_log_write(C.ANDROID_LOG_INFO, ctag, cstr) + aw.buf = aw.buf[:0] + } + aw.buf = append(aw.buf, p...) + return +} diff --git a/native-activity/src/nativeactivity/main.c b/native-activity/src/nativeactivity/main.c new file mode 100644 index 0000000..f8cc9a5 --- /dev/null +++ b/native-activity/src/nativeactivity/main.c @@ -0,0 +1,43 @@ +// +build android + +#include + +int throwException(ANativeActivity *act, const char*err) { + JNIEnv *env; + (*(act->vm))->GetEnv(act->vm, (void **)&env, JNI_VERSION_1_6); + if (env == NULL) + return 0; + jclass excClass = (*env)->FindClass(env, "java/lang/Error"); + if (excClass == NULL) + return 0; + if ((*env)->ThrowNew(env, excClass, err) < 0) + return 0; + return 1; +} + +extern void onNativeWindowCreated(ANativeActivity *activity, ANativeWindow* window); +extern void onNativeWindowDestroyed(ANativeActivity *activity, ANativeWindow* window); +extern void onNativeWindowResized(ANativeActivity *activity, ANativeWindow* window); +extern void onInputQueueCreated(ANativeActivity *activity, AInputQueue* queue); +extern void onInputQueueDestroyed(ANativeActivity *activity, AInputQueue* queue); +extern void onCreate(ANativeActivity *activity, void* savedState, size_t savedStateSize); +extern void onDestroy(ANativeActivity *activity); +extern void onResume(ANativeActivity *activity); +extern void onPause(ANativeActivity *activity); +extern void onConfigurationChanged(ANativeActivity *activity); +extern void onWindowFocusChanged(ANativeActivity *activity, int focused); + +void ANativeActivity_onCreate(ANativeActivity *activity, void* savedState, size_t savedStateSize) { + activity->callbacks->onNativeWindowCreated = onNativeWindowCreated; + activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed; + activity->callbacks->onInputQueueCreated = onInputQueueCreated; + activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed; + activity->callbacks->onDestroy = onDestroy; + activity->callbacks->onResume = onResume; + activity->callbacks->onPause = onPause; + activity->callbacks->onConfigurationChanged = onConfigurationChanged; + activity->callbacks->onNativeWindowResized = onNativeWindowResized; + activity->callbacks->onWindowFocusChanged = onWindowFocusChanged; + + onCreate(activity, savedState, savedStateSize); +} diff --git a/native-activity/src/nativeactivity/main.go b/native-activity/src/nativeactivity/main.go new file mode 100644 index 0000000..7b2eadd --- /dev/null +++ b/native-activity/src/nativeactivity/main.go @@ -0,0 +1,456 @@ +// +build android + +package main + +// #include +// #include +// #include +// #include +// #include +// #include "main.h" +// +// #cgo LDFLAGS: -landroid -lEGL +import "C" + +import ( + "fmt" + "log" + "runtime" + "runtime/debug" + "unsafe" +) + +type mainLoop struct { + looper *C.ALooper + + quit chan struct{} + resume chan struct{} + pause chan struct{} + focus chan bool + render chan *renderState + input chan *C.AInputQueue + ack chan struct{} + + inputQ *C.AInputQueue + renderState *renderState + running, focused bool + width, height int + + game *game +} + +type activityState struct { + renderState *renderState + mLoop *mainLoop +} + +var states map[*C.ANativeActivity]*activityState = make(map[*C.ANativeActivity]*activityState) + +const ( + LOOPER_ID_INPUT = iota +) + +func (s *activityState) Destroy() { + s.mLoop.Quit() + s.renderState.Destroy() +} + +type renderState struct { + disp C.EGLDisplay + conf C.EGLConfig + ctx C.EGLContext + surf C.EGLSurface +} + +func (s *renderState) Destroy() { + if s == nil { + return + } + if s.disp != nil { + if s.ctx != nil { + C.eglDestroyContext(s.disp, s.ctx) + } + C.eglTerminate(s.disp) + } +} + +func newMainLoop() (m *mainLoop) { + m = &mainLoop{ + quit: make(chan struct{}, 1), + resume: make(chan struct{}, 1), + pause: make(chan struct{}, 1), + focus: make(chan bool, 1), + render: make(chan *renderState, 1), + input: make(chan *C.AInputQueue, 1), + ack: make(chan struct{}, 1), + game: &game{}, + } + init := make(chan struct{}) + go m.loop(init) + <-init + return m +} + +func (m *mainLoop) Resume() { + m.resume <- struct{}{} + m.wakeAndAck() +} + +func (m *mainLoop) Focused(focused bool) { + m.focus <- focused + m.wakeAndAck() +} + +func (m *mainLoop) Pause() { + m.pause <- struct{}{} + m.wakeAndAck() +} + +func (m *mainLoop) Quit() { + m.quit <- struct{}{} + m.wakeAndAck() +} + +func (m *mainLoop) UpdateRenderState(rs *renderState) { + m.render <- rs + m.wakeAndAck() +} + +func (m *mainLoop) isRunning() bool { + return m.focused && m.running && m.renderState != nil +} + +func (m *mainLoop) loop(init chan<- struct{}) { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + looper := C.ALooper_prepare(C.ALOOPER_PREPARE_ALLOW_NON_CALLBACKS) + if looper == nil { + panic("ALooper_prepare returned nil") + } + m.looper = looper + init <- struct{}{} + for { + select { + case <-m.quit: + if m.renderState != nil && m.renderState.ctx != nil { + if C.eglMakeCurrent(m.renderState.disp, C.EGLSurface(unsafe.Pointer(nil)), C.EGLSurface(unsafe.Pointer(nil)), C.EGLContext(unsafe.Pointer(nil))) != C.EGL_TRUE { + panic("Error: eglMakeCurrent() failed\n") + } + } + m.ack <- struct{}{} + break + case <-m.resume: + m.running = true + m.ack <- struct{}{} + case <-m.pause: + m.running = false + m.width, m.height = 0, 0 + m.ack <- struct{}{} + case m.focused = <-m.focus: + m.width, m.height = 0, 0 + m.ack <- struct{}{} + case m.renderState = <-m.render: + m.ack <- struct{}{} + case inputQ := <-m.input: + if inputQ != nil { + C.AInputQueue_attachLooper(inputQ, m.looper, LOOPER_ID_INPUT, nil, nil) + } else { + C.AInputQueue_detachLooper(m.inputQ) + } + m.inputQ = inputQ + m.ack <- struct{}{} + default: + m.frame() + } + } +} + +func (m *mainLoop) frame() { + var timeout C.int = 0 + if !m.isRunning() { + timeout = -1 + } + ident := C.ALooper_pollAll(timeout, nil, nil, nil) + switch ident { + case LOOPER_ID_INPUT: + if m.inputQ != nil { + m.processInput(m.inputQ) + } + case C.ALOOPER_POLL_ERROR: + log.Fatalf("ALooper_pollAll returned ALOOPER_POLL_ERROR\n") + } + if m.isRunning() { + m.checkSize() + createCtx := m.renderState.ctx == nil + if createCtx { + log.Printf("Creating context\n") + ctx_attribs := [...]C.EGLint{ + C.EGL_CONTEXT_CLIENT_VERSION, 2, + C.EGL_NONE, + } + + m.renderState.ctx = C.eglCreateContext(m.renderState.disp, m.renderState.conf, C.EGLContext(unsafe.Pointer(nil)), (*C.EGLint)(unsafe.Pointer(&ctx_attribs[0]))) + if m.renderState.ctx == nil { + panic("Error: eglCreateContext failed\n") + } + } + + if C.eglMakeCurrent(m.renderState.disp, m.renderState.surf, m.renderState.surf, m.renderState.ctx) != C.EGL_TRUE { + panic("Error: eglMakeCurrent() failed\n") + } + if createCtx { + m.game.initGL() + } + m.game.drawFrame() + C.eglSwapBuffers(m.renderState.disp, m.renderState.surf) + } +} + +func (m *mainLoop) checkSize() { + var w, h C.EGLint + C.eglQuerySurface(m.renderState.disp, m.renderState.surf, C.EGL_WIDTH, &w) + C.eglQuerySurface(m.renderState.disp, m.renderState.surf, C.EGL_HEIGHT, &h) + width, height := int(w), int(h) + if width != m.width || height != m.height { + m.width = width + m.height = height + m.game.resize(m.width, m.height) + } +} + +func (m *mainLoop) inputQueue(inputQ *C.AInputQueue) { + m.input <- inputQ + m.wakeAndAck() +} + +func (m *mainLoop) wakeAndAck() { + C.ALooper_wake(m.looper) + <-m.ack +} + +func handleCallbackError(act *C.ANativeActivity, err interface{}) { + if err == nil { + return + } + errStr := fmt.Sprintf("callback panic: %s stack: %s", err, debug.Stack()) + errStrC := C.CString(errStr) + defer C.free(unsafe.Pointer(errStrC)) + if C.throwException(act, errStrC) == 0 { + log.Fatalf("%v\n", errStr) + } +} + +//export onWindowFocusChanged +func onWindowFocusChanged(act *C.ANativeActivity, focusedC C.int) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onWindowFocusChanged %v...\n", focusedC) + focused := false + if focusedC != 0 { + focused = true + } + states[act].mLoop.Focused(focused) + log.Printf("onWindowFocusChanged done\n") +} + +//export onConfigurationChanged +func onConfigurationChanged(act *C.ANativeActivity) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onConfigurationChanged\n") +} + +//export onNativeWindowResized +func onNativeWindowResized(act *C.ANativeActivity) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onNativeWindowResized\n") +} + +//export onInputQueueDestroyed +func onInputQueueDestroyed(act *C.ANativeActivity, queue unsafe.Pointer) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onInputQueueDestroy...\n") + states[act].mLoop.inputQueue(nil) + log.Printf("onInputQueueDestroy done\n") +} + +func (m *mainLoop) dispatchEvent(event *C.AInputEvent) bool { + switch C.AInputEvent_getType(event) { + case C.AINPUT_EVENT_TYPE_MOTION: + return m.game.onTouch(event) + } + return false +} + +func (m *mainLoop) processInput(inputQueue *C.AInputQueue) { + var event *C.AInputEvent + for { + if ret := C.AInputQueue_getEvent(inputQueue, &event); ret < 0 { + break + } + if C.AInputQueue_preDispatchEvent(inputQueue, event) != 0 { + continue + } + handled := m.dispatchEvent(event) + var handledC C.int + if handled { + handledC = 1 + } + C.AInputQueue_finishEvent(inputQueue, event, handledC) + } +} + +//export onInputQueueCreated +func onInputQueueCreated(act *C.ANativeActivity, queue unsafe.Pointer) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onInputQueueCreated...\n") + inputQ := (*C.AInputQueue)(queue) + state := states[act] + state.mLoop.inputQueue(inputQ) + log.Printf("onInputQueueCreated done\n") +} + +//export onPause +func onPause(act *C.ANativeActivity) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("Pausing...\n") + states[act].mLoop.Pause() + log.Printf("Paused...\n") +} + +//export onResume +func onResume(act *C.ANativeActivity) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("Resuming...\n") + states[act].mLoop.Resume() + log.Printf("Resumed...\n") +} + +//export onCreate +func onCreate(act *C.ANativeActivity, savedState unsafe.Pointer, savedStateSize C.size_t) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onCreate...\n") + state := &activityState{ + mLoop: newMainLoop(), + } + states[act] = state + log.Printf("onCreate done\n") +} + +//export onDestroy +func onDestroy(act *C.ANativeActivity) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onDestroy...\n") + state := states[act] + delete(states, act) + state.Destroy() + log.Printf("onDestroy done\n") +} + +//export onNativeWindowDestroyed +func onNativeWindowDestroyed(act *C.ANativeActivity, win unsafe.Pointer) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onWindowDestroy...\n") + state := states[act] + state.mLoop.UpdateRenderState(nil) + C.eglDestroySurface(state.renderState.disp, state.renderState.surf) + state.renderState.surf = nil + log.Printf("onWindowDestroy done\n") +} + +func getEGLDisp(disp C.EGLNativeDisplayType) C.EGLDisplay { + if C.eglBindAPI(C.EGL_OPENGL_ES_API) == C.EGL_FALSE { + panic("Error: eglBindAPI() failed") + } + + egl_dpy := C.eglGetDisplay((C.EGLNativeDisplayType)(disp)) + if egl_dpy == nil { + panic("Error: eglGetDisplay() failed\n") + } + + var egl_major, egl_minor C.EGLint + if C.eglInitialize(egl_dpy, &egl_major, &egl_minor) != C.EGL_TRUE { + panic("Error: eglInitialize() failed\n") + } + return egl_dpy +} + +func EGLCreateWindowSurface(eglDisp C.EGLDisplay, config C.EGLConfig, win C.EGLNativeWindowType) C.EGLSurface { + eglSurf := C.eglCreateWindowSurface(eglDisp, config, win, (*C.EGLint)(unsafe.Pointer(nil))) + if eglSurf == nil { + panic("Error: eglCreateWindowSurface failed\n") + } + return eglSurf +} + +func getEGLNativeVisualId(eglDisp C.EGLDisplay, config C.EGLConfig) C.EGLint { + var vid C.EGLint + if C.eglGetConfigAttrib(eglDisp, config, C.EGL_NATIVE_VISUAL_ID, &vid) != C.EGL_TRUE { + panic("Error: eglGetConfigAttrib() failed\n") + } + return vid +} + +func chooseEGLConfig(eglDisp C.EGLDisplay) C.EGLConfig { + eglAttribs := [...]C.EGLint{ + C.EGL_RED_SIZE, 4, + C.EGL_GREEN_SIZE, 4, + C.EGL_BLUE_SIZE, 4, + //C.EGL_DEPTH_SIZE, 1, + C.EGL_RENDERABLE_TYPE, C.EGL_OPENGL_ES2_BIT, + C.EGL_SURFACE_TYPE, C.EGL_WINDOW_BIT, + C.EGL_NONE, + } + + var config C.EGLConfig + var num_configs C.EGLint + if C.eglChooseConfig(eglDisp, (*C.EGLint)(unsafe.Pointer(&eglAttribs[0])), &config, 1, &num_configs) != C.EGL_TRUE { + panic("Error: couldn't get an EGL visual config\n") + } + + return config +} + +//export onNativeWindowCreated +func onNativeWindowCreated(act *C.ANativeActivity, win unsafe.Pointer) { + defer func() { + handleCallbackError(act, recover()) + }() + log.Printf("onNativeWindowCreated...\n") + state := states[act] + if state.renderState == nil { + state.renderState = &renderState{ + disp: getEGLDisp(C.EGLNativeDisplayType(nil)), + } + state.renderState.conf = chooseEGLConfig(state.renderState.disp) + } + vid := getEGLNativeVisualId(state.renderState.disp, state.renderState.conf) + C.ANativeWindow_setBuffersGeometry((*[0]byte)(win), 0, 0, C.int32_t(vid)) + state.renderState.surf = EGLCreateWindowSurface(state.renderState.disp, state.renderState.conf, C.EGLNativeWindowType(win)) + + state.mLoop.UpdateRenderState(state.renderState) + log.Printf("onNativeWindowCreated done\n") +} + +func main() { + runtime.GOMAXPROCS(runtime.NumCPU()) +} diff --git a/native-activity/src/nativeactivity/main.h b/native-activity/src/nativeactivity/main.h new file mode 100644 index 0000000..118a910 --- /dev/null +++ b/native-activity/src/nativeactivity/main.h @@ -0,0 +1,3 @@ +// +build android + +extern int throwException(ANativeActivity *act, const char *err); diff --git a/native-activity/upload.sh b/native-activity/upload.sh new file mode 100755 index 0000000..cbacdcf --- /dev/null +++ b/native-activity/upload.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +./build.sh +./refresh.sh +adb install -r android/bin/nativeactivity-debug.apk diff --git a/patches/5l-ext-linking b/patches/5l-ext-linking deleted file mode 100644 index 7a1517b..0000000 --- a/patches/5l-ext-linking +++ /dev/null @@ -1,481 +0,0 @@ -# HG changeset patch -# Parent a7acae25db41c9fc7b9eeaadd7bf3acb515cd2cb - -diff -r a7acae25db41 src/cmd/5l/5.out.h ---- a/src/cmd/5l/5.out.h Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/5l/5.out.h Wed Jun 26 11:08:41 2013 +0200 -@@ -277,7 +277,7 @@ - #define D_PLT1 (D_NONE+44) // R_ARM_PLT32, 2nd inst: add ip, ip, #0xNN000 - #define D_PLT2 (D_NONE+45) // R_ARM_PLT32, 3rd inst: ldr pc, [ip, #0xNNN]! - #define D_CALL (D_NONE+46) // R_ARM_PLT32/R_ARM_CALL/R_ARM_JUMP24, bl xxxxx or b yyyyy --#define D_TLS (D_NONE+47) -+#define D_TLS (D_NONE+47) // R_ARM_TLS_LE32 - - /* - * this is the ranlib header -diff -r a7acae25db41 src/cmd/5l/asm.c ---- a/src/cmd/5l/asm.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/5l/asm.c Wed Jun 26 11:08:41 2013 +0200 -@@ -264,6 +264,23 @@ - else - return -1; - break; -+ -+ case D_CALL: -+ if(r->siz == 4) { -+ if((r->add & 0xff000000) == 0xeb000000) // BL -+ LPUT(R_ARM_CALL | elfsym<<8); -+ else -+ LPUT(R_ARM_JUMP24 | elfsym<<8); -+ } else -+ return -1; -+ break; -+ -+ case D_TLS: -+ if(r->siz == 4) -+ LPUT(R_ARM_TLS_LE32 | elfsym<<8); -+ else -+ return -1; -+ break; - } - - return 0; -@@ -308,6 +325,34 @@ - int - archreloc(Reloc *r, Sym *s, vlong *val) - { -+ Sym *rs; -+ -+ if(linkmode == LinkExternal) { -+ switch(r->type) { -+ case D_CALL: -+ r->done = 0; -+ -+ // set up addend for eventual relocation via outer symbol. -+ rs = r->sym; -+ r->xadd = r->add; -+ if(r->xadd & 0x800000) -+ r->xadd |= ~0xffffff; -+ r->xadd *= 4; -+ while(rs->outer != nil) { -+ r->xadd += symaddr(rs) - symaddr(rs->outer); -+ rs = rs->outer; -+ } -+ -+ if(rs->type != SHOSTOBJ && rs->sect == nil) -+ diag("missing section for %s", rs->name); -+ r->xsym = rs; -+ -+ *val = braddoff((0xff000000U & (uint32)r->add), -+ (0xffffff & (uint32)(r->xadd / 4))); -+ return 0; -+ } -+ return -1; -+ } - switch(r->type) { - case D_CONST: - *val = r->add; -@@ -759,7 +804,7 @@ - } - - void --asmout(Prog *p, Optab *o, int32 *out) -+asmout(Prog *p, Optab *o, int32 *out, Sym *gmsym) - { - int32 o1, o2, o3, o4, o5, o6, v; - int r, rf, rt, rt2; -@@ -842,11 +887,19 @@ - break; - - case 5: /* bra s */ -+ o1 = opbra(p->as, p->scond); - v = -8; -- // TODO: Use addrel. -+ if(p->to.sym != S && p->to.sym->type != 0) { -+ rel = addrel(cursym); -+ rel->off = pc - cursym->value; -+ rel->siz = 4; -+ rel->sym = p->to.sym; -+ rel->add = o1 | ((v >> 2) & 0xffffff); -+ rel->type = D_CALL; -+ break; -+ } - if(p->cond != P) - v = (p->cond->pc - pc) - 8; -- o1 = opbra(p->as, p->scond); - o1 |= (v >> 2) & 0xffffff; - break; - -@@ -904,7 +957,11 @@ - rel->siz = 4; - rel->sym = p->to.sym; - rel->add = p->to.offset; -- if(flag_shared) { -+ if(rel->sym == gmsym) { -+ rel->type = D_TLS; -+ rel->xadd = rel->add; -+ rel->xsym = rel->sym; -+ } else if(flag_shared) { - rel->type = D_PCREL; - rel->add += pc - p->pcrel->pc - 8; - } else -@@ -1235,9 +1292,22 @@ - - case 63: /* bcase */ - if(p->cond != P) { -- o1 = p->cond->pc; -- if(flag_shared) -- o1 = o1 - p->pcrel->pc - 16; -+ rel = addrel(cursym); -+ rel->off = pc - cursym->value; -+ rel->siz = 4; -+ if(p->to.sym != S && p->to.sym->type != 0) { -+ rel->sym = p->to.sym; -+ rel->add = p->to.offset; -+ } else { -+ rel->sym = cursym; -+ rel->add = p->cond->pc - cursym->value; -+ } -+ if(o->flag & LPCREL) { -+ rel->type = D_PCREL; -+ rel->add += pc - p->pcrel->pc - 16 + rel->siz; -+ } else -+ rel->type = D_ADDR; -+ o1 = 0; - } - break; - -diff -r a7acae25db41 src/cmd/5l/l.h ---- a/src/cmd/5l/l.h Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/5l/l.h Wed Jun 26 11:08:41 2013 +0200 -@@ -366,7 +366,7 @@ - void addhist(int32, int); - Prog* appendp(Prog*); - void asmb(void); --void asmout(Prog*, Optab*, int32*); -+void asmout(Prog*, Optab*, int32*, Sym*); - int32 atolwhex(char*); - Prog* brloop(Prog*); - void buildop(void); -diff -r a7acae25db41 src/cmd/5l/noop.c ---- a/src/cmd/5l/noop.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/5l/noop.c Wed Jun 26 11:08:41 2013 +0200 -@@ -65,7 +65,7 @@ - Prog *p, *q, *q1, *q2; - int o; - Prog *pmorestack; -- Sym *symmorestack, *tlsfallback; -+ Sym *symmorestack, *tlsfallback, *gmsym; - - /* - * find leaf subroutines -@@ -88,6 +88,9 @@ - pmorestack->reg |= NOSPLIT; - - tlsfallback = lookup("runtime.read_tls_fallback", 0); -+ gmsym = S; -+ if(linkmode == LinkExternal) -+ gmsym = lookup("runtime.tlsgm", 0); - q = P; - for(cursym = textp; cursym != nil; cursym = cursym->next) { - for(p = cursym->text; p != P; p = p->link) { -@@ -170,6 +173,35 @@ - p->to.offset = 0; - cursym->text->mark &= ~LEAF; - } -+ if(linkmode == LinkExternal) { -+ // runtime.tlsgm is relocated with R_ARM_TLS_LE32 -+ // and $runtime.tlsgm will contain the TLS offset. -+ // -+ // MOV $runtime.tlsgm+tlsoffset(SB), REGTMP -+ // ADD REGTMP, -+ q = p; -+ p = appendp(p); -+ p->as = AMOVW; -+ p->scond = 14; -+ p->reg = NREG; -+ p->from.type = D_CONST; -+ p->from.sym = gmsym; -+ p->from.name = D_EXTERN; -+ p->from.offset = tlsoffset; -+ p->to.type = D_REG; -+ p->to.reg = REGTMP; -+ p->to.offset = 0; -+ -+ p = appendp(p); -+ p->as = AADD; -+ p->scond = 14; -+ p->reg = NREG; -+ p->from.type = D_REG; -+ p->from.reg = REGTMP; -+ p->to.type = D_REG; -+ p->to.reg = (q->to.offset & 0xf000) >> 12; -+ p->to.offset = 0; -+ } - } - } - q = p; -diff -r a7acae25db41 src/cmd/5l/obj.c ---- a/src/cmd/5l/obj.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/5l/obj.c Wed Jun 26 11:08:41 2013 +0200 -@@ -82,7 +82,7 @@ - INITRND = -1; - INITENTRY = 0; - LIBINITENTRY = 0; -- linkmode = LinkInternal; // TODO: LinkAuto once everything works. -+ linkmode = LinkAuto; - nuxiinit(); - - p = getgoarm(); -@@ -131,29 +131,35 @@ - flagcount("v", "print link trace", &debug['v']); - flagcount("w", "disable DWARF generation", &debug['w']); - flagcount("shared", "generate shared object", &flag_shared); -- // TODO: link mode flag - - flagparse(&argc, &argv, usage); - - if(argc != 1) - usage(); - -+ mywhatsys(); -+ -+ if(HEADTYPE == -1) -+ HEADTYPE = headtype(goos); -+ - // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when - // Go was built; see ../../make.bash. - if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0) - linkmode = LinkInternal; - -- if(linkmode == LinkExternal) { -- diag("only -linkmode=internal is supported"); -- errorexit(); -- } else if(linkmode == LinkAuto) { -- linkmode = LinkInternal; -+ switch(HEADTYPE) { -+ default: -+ if(linkmode == LinkAuto) -+ linkmode = LinkInternal; -+ if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0) -+ sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE)); -+ break; -+ case Hlinux: -+ break; - } - - libinit(); - -- if(HEADTYPE == -1) -- HEADTYPE = headtype(goos); - switch(HEADTYPE) { - default: - diag("unknown -H option"); -diff -r a7acae25db41 src/cmd/5l/optab.c ---- a/src/cmd/5l/optab.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/5l/optab.c Wed Jun 26 11:08:41 2013 +0200 -@@ -182,7 +182,7 @@ - { AMOVBU, C_REG, C_NONE, C_SHIFT, 61, 4, 0 }, - - { ACASE, C_REG, C_NONE, C_NONE, 62, 4, 0, LPCREL, 8 }, -- { ABCASE, C_NONE, C_NONE, C_SBRA, 63, 4, 0 }, -+ { ABCASE, C_NONE, C_NONE, C_SBRA, 63, 4, 0, LPCREL, 0 }, - - { AMOVH, C_REG, C_NONE, C_HAUTO, 70, 4, REGSP, 0 }, - { AMOVH, C_REG, C_NONE, C_HOREG, 70, 4, 0, 0 }, -diff -r a7acae25db41 src/cmd/5l/span.c ---- a/src/cmd/5l/span.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/5l/span.c Wed Jun 26 11:08:41 2013 +0200 -@@ -90,7 +90,7 @@ - int32 c, otxt, out[6]; - Section *sect; - uchar *bp; -- Sym *sub; -+ Sym *sub, *gmsym; - - if(debug['v']) - Bprint(&bso, "%5.2f span\n", cputime()); -@@ -237,6 +237,9 @@ - * code references to be relocated too, and then - * perhaps we'd be able to parallelize the span loop above. - */ -+ gmsym = S; -+ if(linkmode == LinkExternal) -+ gmsym = lookup("runtime.tlsgm", 0); - for(cursym = textp; cursym != nil; cursym = cursym->next) { - p = cursym->text; - if(p == P || p->link == P) -@@ -249,7 +252,7 @@ - pc = p->pc; - curp = p; - o = oplook(p); -- asmout(p, o, out); -+ asmout(p, o, out, gmsym); - for(i=0; isize/4; i++) { - v = out[i]; - *bp++ = v; -diff -r a7acae25db41 src/cmd/8l/asm.c ---- a/src/cmd/8l/asm.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/8l/asm.c Wed Jun 26 11:08:41 2013 +0200 -@@ -366,6 +366,8 @@ - archreloc(Reloc *r, Sym *s, vlong *val) - { - USED(s); -+ if(linkmode == LinkExternal) -+ return -1; - switch(r->type) { - case D_CONST: - *val = r->add; -diff -r a7acae25db41 src/cmd/ld/data.c ---- a/src/cmd/ld/data.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/ld/data.c Wed Jun 26 11:08:41 2013 +0200 -@@ -178,7 +178,7 @@ - switch(r->type) { - default: - o = 0; -- if(linkmode == LinkExternal || archreloc(r, s, &o) < 0) -+ if(archreloc(r, s, &o) < 0) - diag("unknown reloc %d", r->type); - break; - case D_TLS: -diff -r a7acae25db41 src/cmd/ld/elf.h ---- a/src/cmd/ld/elf.h Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/ld/elf.h Wed Jun 26 11:08:41 2013 +0200 -@@ -569,6 +569,7 @@ - #define R_ARM_GOT_PREL 96 - #define R_ARM_GNU_VTENTRY 100 - #define R_ARM_GNU_VTINHERIT 101 -+#define R_ARM_TLS_LE32 108 - #define R_ARM_RSBREL32 250 - #define R_ARM_THM_RPC22 251 - #define R_ARM_RREL32 252 -@@ -576,7 +577,7 @@ - #define R_ARM_RPC24 254 - #define R_ARM_RBASE 255 - --#define R_ARM_COUNT 37 /* Count of defined relocation types. */ -+#define R_ARM_COUNT 38 /* Count of defined relocation types. */ - - - #define R_386_NONE 0 /* No relocation. */ -diff -r a7acae25db41 src/cmd/ld/lib.c ---- a/src/cmd/ld/lib.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/cmd/ld/lib.c Wed Jun 26 11:08:41 2013 +0200 -@@ -671,6 +671,9 @@ - case '6': - argv[argc++] = "-m64"; - break; -+ case '5': -+ argv[argc++] = "-marm"; -+ break; - } - if(!debug['s'] && !debug_s) { - argv[argc++] = "-gdwarf-2"; -diff -r a7acae25db41 src/pkg/runtime/asm_arm.s ---- a/src/pkg/runtime/asm_arm.s Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/pkg/runtime/asm_arm.s Wed Jun 26 11:08:41 2013 +0200 -@@ -11,7 +11,7 @@ - // copy arguments forward on an even stack - // use R13 instead of SP to avoid linker rewriting the offsets - MOVW 0(R13), R0 // argc -- MOVW $4(R13), R1 // argv -+ MOVW 4(R13), R1 // argv - SUB $64, R13 // plenty of scratch - AND $~7, R13 - MOVW R0, 60(R13) // save argc, argv away -diff -r a7acae25db41 src/pkg/runtime/os_linux_arm.c ---- a/src/pkg/runtime/os_linux_arm.c Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/pkg/runtime/os_linux_arm.c Wed Jun 26 11:08:41 2013 +0200 -@@ -34,16 +34,13 @@ - - #pragma textflag 7 - void --runtime·setup_auxv(int32 argc, void *argv_list) -+runtime·setup_auxv(int32 argc, byte **argv) - { -- byte **argv; - byte **envp; - byte *rnd; - uint32 *auxv; - uint32 t; - -- argv = &argv_list; -- - // skip envp to get to ELF auxiliary vector. - for(envp = &argv[argc+1]; *envp != nil; envp++) - ; -diff -r a7acae25db41 src/pkg/runtime/rt0_freebsd_arm.s ---- a/src/pkg/runtime/rt0_freebsd_arm.s Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/pkg/runtime/rt0_freebsd_arm.s Wed Jun 26 11:08:41 2013 +0200 -@@ -5,4 +5,7 @@ - // FreeBSD and Linux use the same linkage to main - - TEXT _rt0_arm_freebsd(SB),7,$-4 -+ MOVW (R13), R0 // argc -+ MOVW $4(R13), R1 // argv -+ MOVM.DB.W [R0-R1], (R13) - B _rt0_go(SB) -diff -r a7acae25db41 src/pkg/runtime/rt0_linux_arm.s ---- a/src/pkg/runtime/rt0_linux_arm.s Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/pkg/runtime/rt0_linux_arm.s Wed Jun 26 11:08:41 2013 +0200 -@@ -3,6 +3,12 @@ - // license that can be found in the LICENSE file. - - TEXT _rt0_arm_linux(SB),7,$-4 -+ MOVW (R13), R0 // argc -+ MOVW $4(R13), R1 // argv -+ MOVW $_rt0_arm_linux1(SB), R4 -+ B (R4) -+ -+TEXT _rt0_arm_linux1(SB),7,$-4 - // We first need to detect the kernel ABI, and warn the user - // if the system only supports OABI - // The strategy here is to call some EABI syscall to see if -@@ -12,6 +18,8 @@ - // we don't know the kernel ABI... Oh, not really, we can do - // syscall in Thumb mode. - -+ // Save argc and argv -+ MOVM.DB.W [R0-R1], (R13) - // set up sa_handler - MOVW $bad_abi<>(SB), R0 // sa_handler - MOVW $0, R1 // sa_flags -@@ -41,6 +49,7 @@ - SUB $4, R13 // fake a stack frame for runtime·setup_auxv - BL runtime·setup_auxv(SB) - ADD $4, R13 -+ - B _rt0_go(SB) - - TEXT bad_abi<>(SB),7,$-4 -@@ -70,3 +79,7 @@ - // TODO(minux): only supports little-endian CPUs - WORD $0x4770df01 // swi $1; bx lr - -+TEXT main(SB),7,$-8 -+ MOVW $_rt0_arm_linux1(SB), R4 -+ B (R4) -+ -diff -r a7acae25db41 src/pkg/runtime/rt0_netbsd_arm.s ---- a/src/pkg/runtime/rt0_netbsd_arm.s Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/pkg/runtime/rt0_netbsd_arm.s Wed Jun 26 11:08:41 2013 +0200 -@@ -5,4 +5,7 @@ - // FreeBSD/NetBSD and Linux use the same linkage to main - - TEXT _rt0_arm_netbsd(SB),7,$-4 -+ MOVW (R13), R0 // argc -+ MOVW $4(R13), R1 // argv -+ MOVM.DB.W [R0-R1], (R13) - B _rt0_go(SB) -diff -r a7acae25db41 src/run.bash ---- a/src/run.bash Mon Jun 24 15:26:25 2013 +0200 -+++ b/src/run.bash Wed Jun 26 11:08:41 2013 +0200 -@@ -100,7 +100,7 @@ - *) go test -ldflags '-linkmode=external' ;; - esac - ;; --freebsd-386 | freebsd-amd64 | linux-386 | linux-amd64 | netbsd-386 | netbsd-amd64) -+freebsd-386 | freebsd-amd64 | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64) - go test -ldflags '-linkmode=external' - go test -ldflags '-linkmode=auto' ../testtls - go test -ldflags '-linkmode=external' ../testtls diff --git a/patches/android-build-hacks b/patches/android-build-hacks index ba477ec..e2e5c53 100644 --- a/patches/android-build-hacks +++ b/patches/android-build-hacks @@ -1,10 +1,10 @@ # HG changeset patch -# Parent 43c633da755a75f7a72956267224d39c33320969 +# Parent 885d86446b1fee0b26a11b928f2e407b4acb1645 -diff -r 43c633da755a src/cmd/go/build.go ---- a/src/cmd/go/build.go Sat Jun 29 10:52:03 2013 +0200 -+++ b/src/cmd/go/build.go Sat Jun 29 17:26:07 2013 +0200 -@@ -1807,7 +1807,19 @@ +diff -r 885d86446b1f src/cmd/go/build.go +--- a/src/cmd/go/build.go Wed Sep 11 22:42:53 2013 +0200 ++++ b/src/cmd/go/build.go Wed Sep 11 22:50:28 2013 +0200 +@@ -1866,7 +1866,19 @@ case "windows": a = append(a, "-mthreads") default: @@ -25,9 +25,20 @@ diff -r 43c633da755a src/cmd/go/build.go } } -diff -r 43c633da755a src/pkg/os/file_android.go +@@ -1913,10 +1925,6 @@ + ) + + func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string, gxxfiles []string) (outGo, outObj []string, err error) { +- if goos != toolGOOS { +- return nil, nil, errors.New("cannot use cgo when compiling for a different operating system") +- } +- + cgoCPPFLAGS := stringList(envList("CGO_CPPFLAGS"), p.CgoCPPFLAGS) + cgoCFLAGS := stringList(envList("CGO_CFLAGS"), p.CgoCFLAGS) + cgoCXXFLAGS := stringList(envList("CGO_CXXFLAGS"), p.CgoCXXFLAGS) +diff -r 885d86446b1f src/pkg/os/file_android.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/src/pkg/os/file_android.go Sat Jun 29 17:26:07 2013 +0200 ++++ b/src/pkg/os/file_android.go Wed Sep 11 22:50:28 2013 +0200 @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style @@ -45,9 +56,9 @@ diff -r 43c633da755a src/pkg/os/file_android.go + } + return dir +} -diff -r 43c633da755a src/pkg/os/file_non_android.go +diff -r 885d86446b1f src/pkg/os/file_non_android.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/src/pkg/os/file_non_android.go Sat Jun 29 17:26:07 2013 +0200 ++++ b/src/pkg/os/file_non_android.go Wed Sep 11 22:50:28 2013 +0200 @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style @@ -65,10 +76,10 @@ diff -r 43c633da755a src/pkg/os/file_non_android.go + } + return dir +} -diff -r 43c633da755a src/pkg/os/file_unix.go ---- a/src/pkg/os/file_unix.go Sat Jun 29 10:52:03 2013 +0200 -+++ b/src/pkg/os/file_unix.go Sat Jun 29 17:26:07 2013 +0200 -@@ -273,12 +273,3 @@ +diff -r 885d86446b1f src/pkg/os/file_unix.go +--- a/src/pkg/os/file_unix.go Wed Sep 11 22:42:53 2013 +0200 ++++ b/src/pkg/os/file_unix.go Wed Sep 11 22:50:28 2013 +0200 +@@ -281,12 +281,3 @@ return name } @@ -81,40 +92,41 @@ diff -r 43c633da755a src/pkg/os/file_unix.go - } - return dir -} -diff -r 43c633da755a src/pkg/os/user/lookup_stubs.go ---- a/src/pkg/os/user/lookup_stubs.go Sat Jun 29 10:52:03 2013 +0200 -+++ b/src/pkg/os/user/lookup_stubs.go Sat Jun 29 17:26:07 2013 +0200 +diff -r 885d86446b1f src/pkg/os/user/lookup_stubs.go +--- a/src/pkg/os/user/lookup_stubs.go Wed Sep 11 22:42:53 2013 +0200 ++++ b/src/pkg/os/user/lookup_stubs.go Wed Sep 11 22:50:28 2013 +0200 @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. --// +build !cgo,!windows -+// +build !cgo,!windows android +-// +build !cgo,!windows,!plan9 ++// +build !cgo,!windows,!plan9 android package user -diff -r 43c633da755a src/pkg/os/user/lookup_unix.go ---- a/src/pkg/os/user/lookup_unix.go Sat Jun 29 10:52:03 2013 +0200 -+++ b/src/pkg/os/user/lookup_unix.go Sat Jun 29 17:26:07 2013 +0200 +diff -r 885d86446b1f src/pkg/os/user/lookup_unix.go +--- a/src/pkg/os/user/lookup_unix.go Wed Sep 11 22:42:53 2013 +0200 ++++ b/src/pkg/os/user/lookup_unix.go Wed Sep 11 22:50:28 2013 +0200 @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. --// +build darwin freebsd linux netbsd openbsd -+// +build darwin freebsd !android,linux netbsd openbsd +-// +build darwin dragonfly freebsd linux netbsd openbsd ++// +build darwin dragonfly freebsd !android,linux netbsd openbsd // +build cgo package user -diff -r 43c633da755a src/pkg/runtime/cgo/cgo.go ---- a/src/pkg/runtime/cgo/cgo.go Sat Jun 29 10:52:03 2013 +0200 -+++ b/src/pkg/runtime/cgo/cgo.go Sat Jun 29 17:26:07 2013 +0200 -@@ -9,18 +9,6 @@ +diff -r 885d86446b1f src/pkg/runtime/cgo/cgo.go +--- a/src/pkg/runtime/cgo/cgo.go Wed Sep 11 22:42:53 2013 +0200 ++++ b/src/pkg/runtime/cgo/cgo.go Wed Sep 11 22:50:28 2013 +0200 +@@ -9,19 +9,6 @@ */ package cgo -/* - -#cgo darwin LDFLAGS: -lpthread +-#cgo dragonfly LDFLAGS: -lpthread -#cgo freebsd LDFLAGS: -lpthread -#cgo linux LDFLAGS: -lpthread -#cgo netbsd LDFLAGS: -lpthread @@ -127,9 +139,9 @@ diff -r 43c633da755a src/pkg/runtime/cgo/cgo.go import "C" // Supports _cgo_panic by converting a string constant to an empty -diff -r 43c633da755a src/pkg/runtime/cgo/cgo_flags.go +diff -r 885d86446b1f src/pkg/runtime/cgo/cgo_flags.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/src/pkg/runtime/cgo/cgo_flags.go Sat Jun 29 17:26:07 2013 +0200 ++++ b/src/pkg/runtime/cgo/cgo_flags.go Wed Sep 11 22:50:28 2013 +0200 @@ -0,0 +1,16 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style @@ -147,10 +159,10 @@ diff -r 43c633da755a src/pkg/runtime/cgo/cgo_flags.go +#cgo windows LDFLAGS: -lm -mthreads +*/ +import "C" -diff -r 43c633da755a src/pkg/runtime/malloc.goc ---- a/src/pkg/runtime/malloc.goc Sat Jun 29 10:52:03 2013 +0200 -+++ b/src/pkg/runtime/malloc.goc Sat Jun 29 17:26:07 2013 +0200 -@@ -293,7 +293,7 @@ +diff -r 885d86446b1f src/pkg/runtime/malloc.goc +--- a/src/pkg/runtime/malloc.goc Wed Sep 11 22:42:53 2013 +0200 ++++ b/src/pkg/runtime/malloc.goc Wed Sep 11 22:50:28 2013 +0200 +@@ -316,7 +316,7 @@ uintptr runtime·sizeof_C_MStats = sizeof(MStats); diff --git a/patches/android-tls b/patches/android-tls index f4cbbdb..a16fcfd 100644 --- a/patches/android-tls +++ b/patches/android-tls @@ -1,10 +1,10 @@ # HG changeset patch -# Parent 9dc377d326c1a17cedcdfdedf06e449dfa5c8673 +# Parent 4ca1bf670de5268db946674716e87bdb65a5de4f -diff -r 9dc377d326c1 src/cmd/5l/asm.c ---- a/src/cmd/5l/asm.c Sat Jun 29 10:52:02 2013 +0200 -+++ b/src/cmd/5l/asm.c Sat Jun 29 17:27:01 2013 +0200 -@@ -954,7 +954,7 @@ +diff -r 4ca1bf670de5 src/cmd/5l/asm.c +--- a/src/cmd/5l/asm.c Tue Aug 13 17:12:09 2013 +0200 ++++ b/src/cmd/5l/asm.c Tue Aug 13 17:38:47 2013 +0200 +@@ -961,7 +961,7 @@ rel->siz = 4; rel->sym = p->to.sym; rel->add = p->to.offset; @@ -13,10 +13,10 @@ diff -r 9dc377d326c1 src/cmd/5l/asm.c rel->type = D_TLS; if(flag_shared) rel->add += pc - p->pcrel->pc - 8 - rel->siz; -diff -r 9dc377d326c1 src/cmd/5l/l.h ---- a/src/cmd/5l/l.h Sat Jun 29 10:52:02 2013 +0200 -+++ b/src/cmd/5l/l.h Sat Jun 29 17:27:01 2013 +0200 -@@ -326,6 +326,7 @@ +diff -r 4ca1bf670de5 src/cmd/5l/l.h +--- a/src/cmd/5l/l.h Tue Aug 13 17:12:09 2013 +0200 ++++ b/src/cmd/5l/l.h Tue Aug 13 17:38:47 2013 +0200 +@@ -324,6 +324,7 @@ EXTERN int goarm; EXTERN Sym* adrgotype; // type symbol on last Adr read EXTERN Sym* fromgotype; // type symbol on last p->from read @@ -24,9 +24,9 @@ diff -r 9dc377d326c1 src/cmd/5l/l.h extern char* anames[]; extern Optab optab[]; -diff -r 9dc377d326c1 src/cmd/5l/obj.c ---- a/src/cmd/5l/obj.c Sat Jun 29 10:52:02 2013 +0200 -+++ b/src/cmd/5l/obj.c Sat Jun 29 17:27:01 2013 +0200 +diff -r 4ca1bf670de5 src/cmd/5l/obj.c +--- a/src/cmd/5l/obj.c Tue Aug 13 17:12:09 2013 +0200 ++++ b/src/cmd/5l/obj.c Tue Aug 13 17:38:47 2013 +0200 @@ -93,6 +93,7 @@ debug['F'] = 1; @@ -48,9 +48,9 @@ diff -r 9dc377d326c1 src/cmd/5l/obj.c // mark some functions that are only referenced after linker code editing if(debug['F']) -diff -r 9dc377d326c1 src/cmd/ld/symtab.c ---- a/src/cmd/ld/symtab.c Sat Jun 29 10:52:02 2013 +0200 -+++ b/src/cmd/ld/symtab.c Sat Jun 29 17:27:01 2013 +0200 +diff -r 4ca1bf670de5 src/cmd/ld/symtab.c +--- a/src/cmd/ld/symtab.c Tue Aug 13 17:12:09 2013 +0200 ++++ b/src/cmd/ld/symtab.c Tue Aug 13 17:38:47 2013 +0200 @@ -182,13 +182,15 @@ if(linkmode == LinkExternal && HEADTYPE != Hopenbsd) { @@ -73,9 +73,9 @@ diff -r 9dc377d326c1 src/cmd/ld/symtab.c } elfbind = STB_GLOBAL; -diff -r 9dc377d326c1 src/pkg/runtime/cgo/cgo_android_arm.c +diff -r 4ca1bf670de5 src/pkg/runtime/cgo/cgo_android_arm.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/src/pkg/runtime/cgo/cgo_android_arm.c Sat Jun 29 17:27:01 2013 +0200 ++++ b/src/pkg/runtime/cgo/cgo_android_arm.c Tue Aug 13 17:38:47 2013 +0200 @@ -0,0 +1,12 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style @@ -89,9 +89,9 @@ diff -r 9dc377d326c1 src/pkg/runtime/cgo/cgo_android_arm.c +extern void x_cgo_tls_setup(void (*)(void*)); +void (*_cgo_tls_setup)(void (*)(void*)) = x_cgo_tls_setup; + -diff -r 9dc377d326c1 src/pkg/runtime/cgo/gcc_android_arm.c +diff -r 4ca1bf670de5 src/pkg/runtime/cgo/gcc_android_arm.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/src/pkg/runtime/cgo/gcc_android_arm.c Sat Jun 29 17:27:01 2013 +0200 ++++ b/src/pkg/runtime/cgo/gcc_android_arm.c Tue Aug 13 17:38:47 2013 +0200 @@ -0,0 +1,88 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style @@ -181,13 +181,13 @@ diff -r 9dc377d326c1 src/pkg/runtime/cgo/gcc_android_arm.c + for(i=0; itext; - pmorestack->reg |= NOSPLIT; - -+ tlsfallback = lookup("runtime.read_tls_fallback", 0); - q = P; - for(cursym = textp; cursym != nil; cursym = cursym->next) { - for(p = cursym->text; p != P; p = p->link) { -@@ -150,6 +152,25 @@ - } - } - break; -+ case AWORD: -+ // Rewrite TLS register fetch: MRC 15, 0, , C13, C0, 3 -+ if((p->to.offset & 0xffff0fff) == 0xee1d0f70) { -+ if(HEADTYPE == Hopenbsd) { -+ p->as = ARET; -+ } else if(goarm < 7) { -+ if(tlsfallback->type != STEXT) { -+ diag("runtime·read_tls_fallback not defined"); -+ errorexit(); -+ } -+ // BL runtime.read_tls_fallback(SB) -+ p->as = ABL; -+ p->to.type = D_BRANCH; -+ p->to.sym = tlsfallback; -+ p->cond = tlsfallback->text; -+ p->to.offset = 0; -+ cursym->text->mark &= ~LEAF; -+ } -+ } - } - q = p; - } -diff -r af0c031528c3 src/cmd/5l/obj.c ---- a/src/cmd/5l/obj.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/cmd/5l/obj.c Mon Jun 24 15:26:24 2013 +0200 -@@ -208,7 +208,7 @@ - case Hnetbsd: - debug['d'] = 0; // with dynamic linking - tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m -- // this number is known to ../../pkg/runtime/cgo/gcc_linux_arm.c -+ // this number is known to ../../pkg/runtime/rt0_*_arm.s - elfinit(); - HEADR = ELFRESERVE; - if(INITTEXT == -1) -@@ -253,6 +253,7 @@ - // mark some functions that are only referenced after linker code editing - if(debug['F']) - mark(rlookup("_sfloat", 0)); -+ mark(lookup("runtime.read_tls_fallback", 0)); - deadcode(); - if(textp == nil) { - diag("no code"); -diff -r af0c031528c3 src/cmd/6l/span.c ---- a/src/cmd/6l/span.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/cmd/6l/span.c Mon Jun 24 15:26:24 2013 +0200 -@@ -888,18 +888,11 @@ - - r = addrel(cursym); - r->off = curp->pc + andptr - and; -- r->add = 0; -- r->xadd = 0; -+ r->add = a->offset-tlsoffset; -+ r->xadd = r->add; - r->siz = 4; - r->type = D_TLS; -- if(a->offset == tlsoffset+0) -- s = lookup("runtime.g", 0); -- else -- s = lookup("runtime.m", 0); -- s->type = STLSBSS; -- s->reachable = 1; -- s->size = PtrSize; -- s->hide = 1; -+ s = lookup("runtime.tlsgm", 0); - r->sym = s; - r->xsym = s; - v = 0; -diff -r af0c031528c3 src/cmd/8l/span.c ---- a/src/cmd/8l/span.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/cmd/8l/span.c Mon Jun 24 15:26:24 2013 +0200 -@@ -695,18 +695,11 @@ - - r = addrel(cursym); - r->off = curp->pc + andptr - and; -- r->add = 0; -- r->xadd = 0; -+ r->add = a->offset-tlsoffset; -+ r->xadd = r->add; - r->siz = 4; - r->type = D_TLS; -- if(a->offset == tlsoffset+0) -- s = lookup("runtime.g", 0); -- else -- s = lookup("runtime.m", 0); -- s->type = STLSBSS; -- s->reachable = 1; -- s->hide = 1; -- s->size = PtrSize; -+ s = lookup("runtime.tlsgm", 0); - r->sym = s; - r->xsym = s; - v = 0; -diff -r af0c031528c3 src/cmd/ld/data.c ---- a/src/cmd/ld/data.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/cmd/ld/data.c Mon Jun 24 15:26:24 2013 +0200 -@@ -184,6 +184,8 @@ - case D_TLS: - r->done = 0; - o = 0; -+ if(thechar != '6') -+ o = r->add; - break; - case D_ADDR: - if(linkmode == LinkExternal && r->sym->type != SCONST) { -diff -r af0c031528c3 src/cmd/ld/lib.c ---- a/src/cmd/ld/lib.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/cmd/ld/lib.c Mon Jun 24 15:26:24 2013 +0200 -@@ -292,7 +292,7 @@ - loadlib(void) - { - int i, w, x; -- Sym *s; -+ Sym *s, *gmsym; - - loadinternal("runtime"); - if(thechar == '5') -@@ -341,6 +341,12 @@ - } else - s->type = 0; - } -+ } else if(linkmode == LinkExternal) { -+ gmsym = lookup("runtime.tlsgm", 0); -+ gmsym->type = STLSBSS; -+ gmsym->size = 2*PtrSize; -+ gmsym->hide = 1; -+ gmsym->reachable = 1; - } - - // Now that we know the link mode, trim the dynexp list. -diff -r af0c031528c3 src/cmd/ld/symtab.c ---- a/src/cmd/ld/symtab.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/cmd/ld/symtab.c Mon Jun 24 15:26:24 2013 +0200 -@@ -181,22 +181,13 @@ - genasmsym(putelfsym); - - if(linkmode == LinkExternal && HEADTYPE != Hopenbsd) { -- s = lookup("runtime.m", 0); -+ s = lookup("runtime.tlsgm", 0); - if(s->sect == nil) { - cursym = nil; - diag("missing section for %s", s->name); - errorexit(); - } -- putelfsyment(putelfstr(s->name), 0, PtrSize, (STB_LOCAL<<4)|STT_TLS, s->sect->elfsect->shnum, 0); -- s->elfsym = numelfsym++; -- -- s = lookup("runtime.g", 0); -- if(s->sect == nil) { -- cursym = nil; -- diag("missing section for %s", s->name); -- errorexit(); -- } -- putelfsyment(putelfstr(s->name), PtrSize, PtrSize, (STB_LOCAL<<4)|STT_TLS, s->sect->elfsect->shnum, 0); -+ putelfsyment(putelfstr(s->name), 0, 2*PtrSize, (STB_LOCAL<<4)|STT_TLS, s->sect->elfsect->shnum, 0); - s->elfsym = numelfsym++; - } - -diff -r af0c031528c3 src/pkg/runtime/asm_arm.s ---- a/src/pkg/runtime/asm_arm.s Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/asm_arm.s Mon Jun 24 15:26:24 2013 +0200 -@@ -33,10 +33,15 @@ - BL runtime·emptyfunc(SB) // fault if stack check is wrong - - // if there is an _cgo_init, call it. -- MOVW _cgo_init(SB), R2 -- CMP $0, R2 -- MOVW.NE g, R0 // first argument of _cgo_init is g -- BL.NE (R2) // will clobber R0-R3 -+ MOVW _cgo_init(SB), R4 -+ CMP $0, R4 -+ B.EQ nocgo -+ BL runtime·save_gm(SB); -+ MOVW g, R0 // first argument of _cgo_init is g -+ MOVW $setmg_gcc<>(SB), R1 // second argument is address of save_gm -+ BL (R4) // will clobber R0-R3 -+ -+nocgo: - // update stackguard after _cgo_init - MOVW g_stackguard0(g), R0 - MOVW R0, g_stackguard(g) -@@ -114,9 +119,9 @@ - MOVW 0(FP), R1 // gobuf - MOVW gobuf_g(R1), g - MOVW 0(g), R2 // make sure g != nil -- MOVW _cgo_save_gm(SB), R2 -+ MOVB runtime·iscgo(SB), R2 - CMP $0, R2 // if in Cgo, we have to save g and m -- BL.NE (R2) // this call will clobber R0 -+ BL.NE runtime·save_gm(SB) // this call will clobber R0 - MOVW gobuf_sp(R1), SP // restore SP - MOVW gobuf_lr(R1), LR - MOVW gobuf_ret(R1), R0 -@@ -309,9 +314,9 @@ - // See cgocall.c for more details. - TEXT runtime·cgocallback_gofunc(SB),7,$12 - // Load m and g from thread-local storage. -- MOVW _cgo_load_gm(SB), R0 -+ MOVB runtime·iscgo(SB), R0 - CMP $0, R0 -- BL.NE (R0) -+ BL.NE runtime·load_gm(SB) - - // If m is nil, Go did not create the current thread. - // Call needm to obtain one for temporary use. -@@ -403,9 +408,9 @@ - MOVW gg+4(FP), g - - // Save m and g to thread-local storage. -- MOVW _cgo_save_gm(SB), R0 -+ MOVB runtime·iscgo(SB), R0 - CMP $0, R0 -- BL.NE (R0) -+ BL.NE runtime·save_gm(SB) - - RET - -@@ -498,3 +503,31 @@ - - MOVW $0, R0 - RET -+ -+// We have to resort to TLS variable to save g(R10) and -+// m(R9). One reason is that external code might trigger -+// SIGSEGV, and our runtime.sigtramp don't even know we -+// are in external code, and will continue to use R10/R9, -+// this might as well result in another SIGSEGV. -+// Note: all three functions will clobber R0, and the last -+// two can be called from 5c ABI code. -+ -+// g (R10) at 8(TP), m (R9) at 12(TP) -+TEXT runtime·save_gm(SB),7,$0 -+ MRC 15, 0, R0, C13, C0, 3 // Fetch TLS register -+ MOVW g, 8(R0) -+ MOVW m, 12(R0) -+ RET -+ -+TEXT runtime·load_gm(SB),7,$0 -+ MRC 15, 0, R0, C13, C0, 3 // Fetch TLS register -+ MOVW 8(R0), g -+ MOVW 12(R0), m -+ RET -+ -+// void setmg_gcc(M*, G*); set m and g called from gcc. -+TEXT setmg_gcc<>(SB),7,$0 -+ MOVW R0, m -+ MOVW R1, g -+ B runtime·save_gm(SB) -+ -diff -r af0c031528c3 src/pkg/runtime/cgo/asm_arm.s ---- a/src/pkg/runtime/cgo/asm_arm.s Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/cgo/asm_arm.s Mon Jun 24 15:26:24 2013 +0200 -@@ -12,12 +12,11 @@ - * push 2 args for fn (R1 and R2). - * Also note that at procedure entry in 5c/5g world, 4(R13) will be the - * first arg, so we must push another dummy reg (R0) for 0(R13). -- * Additionally, cgo_tls_set_gm will clobber R0, so we need to save R0 -+ * Additionally, runtime·load_gm will clobber R0, so we need to save R0 - * nevertheless. - */ - MOVM.WP [R0, R1, R2, R4, R5, R6, R7, R8, m, g, R11, R12, R14], (R13) -- MOVW _cgo_load_gm(SB), R0 -- BL (R0) -+ BL runtime·load_gm(SB) - MOVW PC, R14 - MOVW 0(R13), PC - MOVM.IAW (R13), [R0, R1, R2, R4, R5, R6, R7, R8, m, g, R11, R12, PC] -diff -r af0c031528c3 src/pkg/runtime/cgo/cgo_arm.c ---- a/src/pkg/runtime/cgo/cgo_arm.c Mon Jun 24 17:17:45 2013 +1000 -+++ /dev/null Thu Jan 01 00:00:00 1970 +0000 -@@ -1,12 +0,0 @@ --// Copyright 2013 The Go Authors. All rights reserved. --// Use of this source code is governed by a BSD-style --// license that can be found in the LICENSE file. -- --#pragma cgo_import_static x_cgo_load_gm --extern void x_cgo_load_gm(void); --void (*_cgo_load_gm)(void) = x_cgo_load_gm; -- --#pragma cgo_import_static x_cgo_save_gm --extern void x_cgo_save_gm(void); --void (*_cgo_save_gm)(void) = x_cgo_save_gm; -- -diff -r af0c031528c3 src/pkg/runtime/cgo/gcc_arm.S ---- a/src/pkg/runtime/cgo/gcc_arm.S Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/cgo/gcc_arm.S Mon Jun 24 15:26:24 2013 +0200 -@@ -21,12 +21,8 @@ - .globl EXT(crosscall_arm2) - EXT(crosscall_arm2): - push {r4, r5, r6, r7, r8, r9, r10, r11, ip, lr} -- mov r10, r1 // g -- mov r9, r2 // m -- mov r3, r0 // save r0, cgo_tls_set_gm will clobber it -- bl EXT(x_cgo_save_gm) // save current g and m into TLS variable - mov lr, pc -- mov pc, r3 -+ mov pc, r0 - pop {r4, r5, r6, r7, r8, r9, r10, r11, ip, pc} - - .globl EXT(__stack_chk_fail_local) -diff -r af0c031528c3 src/pkg/runtime/cgo/gcc_freebsd_arm.c ---- a/src/pkg/runtime/cgo/gcc_freebsd_arm.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/cgo/gcc_freebsd_arm.c Mon Jun 24 15:26:24 2013 +0200 -@@ -8,72 +8,26 @@ - #include - #include "libcgo.h" - --static void *threadentry(void*); -- --// We have to resort to TLS variable to save g(R10) and --// m(R9). One reason is that external code might trigger --// SIGSEGV, and our runtime.sigtramp don't even know we --// are in external code, and will continue to use R10/R9, --// this might as well result in another SIGSEGV. --// Note: all three functions will clobber R0, and the last --// two can be called from 5c ABI code. --void __aeabi_read_tp(void) __attribute__((naked)); --void x_cgo_save_gm(void) __attribute__((naked)); --void x_cgo_load_gm(void) __attribute__((naked)); -- --void --__aeabi_read_tp(void) --{ -- __asm__ __volatile__ ( - #ifdef ARM_TP_ADDRESS -- // ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000 -- // GCC inline asm doesn't provide a way to provide a constant -- // to "ldr r0, =??" pseudo instruction, so we hardcode the value -- // and check it with cpp. -+// ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000 -+// and is known to runtime.read_tls_fallback. Verify it with -+// cpp. - #if ARM_TP_ADDRESS != 0xffff1000 - #error Wrong ARM_TP_ADDRESS! - #endif -- "ldr r0, =0xffff1000\n\t" -- "ldr r0, [r0]\n\t" --#else -- "mrc p15, 0, r0, c13, c0, 3\n\t" - #endif -- "mov pc, lr\n\t" -- ); --} - --// g (R10) at 8(TP), m (R9) at 12(TP) --void --x_cgo_load_gm(void) --{ -- __asm__ __volatile__ ( -- "push {lr}\n\t" -- "bl __aeabi_read_tp\n\t" -- "ldr r10, [r0, #8]\n\t" -- "ldr r9, [r0, #12]\n\t" -- "pop {pc}\n\t" -- ); --} -+static void *threadentry(void*); -+ -+static void (*setmg_gcc)(void*, void*); - - void --x_cgo_save_gm(void) --{ -- __asm__ __volatile__ ( -- "push {lr}\n\t" -- "bl __aeabi_read_tp\n\t" -- "str r10, [r0, #8]\n\t" -- "str r9, [r0, #12]\n\t" -- "pop {pc}\n\t" -- ); --} -- --void --x_cgo_init(G *g) -+x_cgo_init(G *g, void (*setmg)(void*, void*)) - { - pthread_attr_t attr; - size_t size; -- x_cgo_save_gm(); // save g and m for the initial thread - -+ setmg_gcc = setmg; - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - g->stackguard = (uintptr)&attr - size + 4096; -@@ -121,6 +75,8 @@ - */ - ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; - -- crosscall_arm2(ts.fn, (void *)ts.g, (void *)ts.m); -+ setmg_gcc((void*)ts.m, (void*)ts.g); -+ -+ crosscall_arm2(ts.fn); - return nil; - } -diff -r af0c031528c3 src/pkg/runtime/cgo/gcc_linux_arm.c ---- a/src/pkg/runtime/cgo/gcc_linux_arm.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/cgo/gcc_linux_arm.c Mon Jun 24 15:26:24 2013 +0200 -@@ -8,60 +8,15 @@ - - static void *threadentry(void*); - --// We have to resort to TLS variable to save g(R10) and --// m(R9). One reason is that external code might trigger --// SIGSEGV, and our runtime.sigtramp don't even know we --// are in external code, and will continue to use R10/R9, --// this might as well result in another SIGSEGV. --// Note: all three functions will clobber R0, and the last --// two can be called from 5c ABI code. --void __aeabi_read_tp(void) __attribute__((naked)); --void x_cgo_save_gm(void) __attribute__((naked)); --void x_cgo_load_gm(void) __attribute__((naked)); -+static void (*setmg_gcc)(void*, void*); - - void --__aeabi_read_tp(void) --{ -- // b __kuser_get_tls @ 0xffff0fe0 -- __asm__ __volatile__ ( -- "mvn r0, #0xf000\n\t" -- "sub pc, r0, #31\n\t" -- "nop\n\tnop\n\t" -- ); --} -- --// g (R10) at 8(TP), m (R9) at 12(TP) --void --x_cgo_load_gm(void) --{ -- __asm__ __volatile__ ( -- "push {lr}\n\t" -- "bl __aeabi_read_tp\n\t" -- "ldr r10, [r0, #8]\n\t" -- "ldr r9, [r0, #12]\n\t" -- "pop {pc}\n\t" -- ); --} -- --void --x_cgo_save_gm(void) --{ -- __asm__ __volatile__ ( -- "push {lr}\n\t" -- "bl __aeabi_read_tp\n\t" -- "str r10, [r0, #8]\n\t" -- "str r9, [r0, #12]\n\t" -- "pop {pc}\n\t" -- ); --} -- --void --x_cgo_init(G *g) -+x_cgo_init(G *g, void (*setmg)(void*, void*)) - { - pthread_attr_t attr; - size_t size; -- x_cgo_save_gm(); // save g and m for the initial thread - -+ setmg_gcc = setmg; - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - g->stackguard = (uintptr)&attr - size + 4096; -@@ -92,7 +47,7 @@ - } - } - --extern void crosscall_arm2(void (*fn)(void), void *g, void *m); -+extern void crosscall_arm2(void (*fn)(void)); - static void* - threadentry(void *v) - { -@@ -109,6 +64,8 @@ - */ - ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; - -- crosscall_arm2(ts.fn, (void *)ts.g, (void *)ts.m); -+ setmg_gcc((void*)ts.m, (void*)ts.g); -+ -+ crosscall_arm2(ts.fn); - return nil; - } -diff -r af0c031528c3 src/pkg/runtime/cgo/gcc_netbsd_arm.c ---- a/src/pkg/runtime/cgo/gcc_netbsd_arm.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/cgo/gcc_netbsd_arm.c Mon Jun 24 15:26:24 2013 +0200 -@@ -10,64 +10,15 @@ - - static void *threadentry(void*); - --// We have to resort to TLS variable to save g(R10) and --// m(R9). One reason is that external code might trigger --// SIGSEGV, and our runtime.sigtramp don't even know we --// are in external code, and will continue to use R10/R9, --// this might as well result in another SIGSEGV. --// Note: all three functions will clobber R0, and the last --// two can be called from 5c ABI code. --void __aeabi_read_tp(void) __attribute__((naked)); --void x_cgo_save_gm(void) __attribute__((naked)); --void x_cgo_load_gm(void) __attribute__((naked)); -+static void (*setmg_gcc)(void*, void*); - - void --__aeabi_read_tp(void) --{ -- // this function is only allowed to clobber r0 -- __asm__ __volatile__ ( -- "mrc p15, 0, r0, c13, c0, 3\n\t" -- "cmp r0, #0\n\t" -- "movne pc, lr\n\t" -- "push {r1,r2,r3,r12}\n\t" -- "svc 0x00a0013c\n\t" // _lwp_getprivate -- "pop {r1,r2,r3,r12}\n\t" -- "mov pc, lr\n\t" -- ); --} -- --// g (R10) at 8(TP), m (R9) at 12(TP) --void --x_cgo_load_gm(void) --{ -- __asm__ __volatile__ ( -- "push {lr}\n\t" -- "bl __aeabi_read_tp\n\t" -- "ldr r10, [r0, #8]\n\t" -- "ldr r9, [r0, #12]\n\t" -- "pop {pc}\n\t" -- ); --} -- --void --x_cgo_save_gm(void) --{ -- __asm__ __volatile__ ( -- "push {lr}\n\t" -- "bl __aeabi_read_tp\n\t" -- "str r10, [r0, #8]\n\t" -- "str r9, [r0, #12]\n\t" -- "pop {pc}\n\t" -- ); --} -- --void --x_cgo_init(G *g) -+x_cgo_init(G *g, void (*setmg)(void*, void*)) - { - pthread_attr_t attr; - size_t size; -- x_cgo_save_gm(); // save g and m for the initial thread - -+ setmg_gcc = setmg; - pthread_attr_init(&attr); - pthread_attr_getstacksize(&attr, &size); - g->stackguard = (uintptr)&attr - size + 4096; -@@ -117,6 +68,8 @@ - */ - ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096 * 2; - -- crosscall_arm2(ts.fn, (void *)ts.g, (void *)ts.m); -+ setmg_gcc((void*)ts.m, (void*)ts.g); -+ -+ crosscall_arm2(ts.fn); - return nil; - } -diff -r af0c031528c3 src/pkg/runtime/cgocall.c ---- a/src/pkg/runtime/cgocall.c Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/cgocall.c Mon Jun 24 15:26:24 2013 +0200 -@@ -86,11 +86,6 @@ - void *_cgo_init; /* filled in by dynamic linker when Cgo is available */ - static int64 cgosync; /* represents possible synchronization in C code */ - --// These two are only used by the architecture where TLS based storage isn't --// the default for g and m (e.g., ARM) --void *_cgo_load_gm; /* filled in by dynamic linker when Cgo is available */ --void *_cgo_save_gm; /* filled in by dynamic linker when Cgo is available */ -- - static void unwindm(void); - - // Call from Go to C. -diff -r af0c031528c3 src/pkg/runtime/sys_freebsd_arm.s ---- a/src/pkg/runtime/sys_freebsd_arm.s Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/sys_freebsd_arm.s Mon Jun 24 15:26:24 2013 +0200 -@@ -280,3 +280,7 @@ - // return 0; - TEXT runtime·cas(SB),7,$0 - B runtime·armcas(SB) -+ -+TEXT runtime·read_tls_fallback(SB),7,$-4 -+ MOVW $0xffff1000, R0 -+ MOVW (R0), R0 -diff -r af0c031528c3 src/pkg/runtime/sys_linux_arm.s ---- a/src/pkg/runtime/sys_linux_arm.s Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/sys_linux_arm.s Mon Jun 24 15:26:24 2013 +0200 -@@ -285,11 +285,11 @@ - TEXT runtime·sigtramp(SB),7,$24 - // this might be called in external code context, - // where g and m are not set. -- // first save R0, because _cgo_load_gm will clobber it -+ // first save R0, because runtime·load_gm will clobber it - MOVW R0, 4(R13) -- MOVW _cgo_load_gm(SB), R0 -+ MOVB runtime·iscgo(SB), R0 - CMP $0, R0 -- BL.NE (R0) -+ BL.NE runtime·load_gm(SB) - - CMP $0, m - BNE 3(PC) -@@ -439,3 +439,8 @@ - MOVW $SYS_fcntl, R7 - SWI $0 - RET -+ -+// b __kuser_get_tls @ 0xffff0fe0 -+TEXT runtime·read_tls_fallback(SB),7,$-4 -+ MOVW $0xffff0fe0, R0 -+ B (R0) -diff -r af0c031528c3 src/pkg/runtime/sys_netbsd_arm.s ---- a/src/pkg/runtime/sys_netbsd_arm.s Mon Jun 24 17:17:45 2013 +1000 -+++ b/src/pkg/runtime/sys_netbsd_arm.s Mon Jun 24 15:26:24 2013 +0200 -@@ -302,3 +302,9 @@ - // return 0; - TEXT runtime·cas(SB),7,$0 - B runtime·armcas(SB) -+ -+TEXT runtime·read_tls_fallback(SB),7,$-4 -+ MOVM.WP [R1, R2, R3, R12], (R13) -+ SWI $0x00a0013c // _lwp_getprivate -+ MOVM.IAW (R13), [R1, R2, R3, R12] -+ RET diff --git a/patches/series b/patches/series index 615acf7..d26884a 100644 --- a/patches/series +++ b/patches/series @@ -1,6 +1,3 @@ -merge-gm -5l-ext-linking -shared-lib shared-lib-runtime android-tls android-build-hacks diff --git a/patches/shared-lib b/patches/shared-lib deleted file mode 100644 index 05dcf9a..0000000 --- a/patches/shared-lib +++ /dev/null @@ -1,3438 +0,0 @@ -# HG changeset patch -# Parent 5f1bc87f81de9197d94966e1424f0bd9db79f6be - -diff -r 5f1bc87f81de src/cmd/5l/asm.c ---- a/src/cmd/5l/asm.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/5l/asm.c Thu Jun 27 16:06:56 2013 +0200 -@@ -93,12 +93,6 @@ - return (((uint32)a) & 0xff000000U) | (0x00ffffffU & (uint32)(a + b)); - } - --Sym * --lookuprel(void) --{ -- return lookup(".rel", 0); --} -- - void - adddynrela(Sym *rel, Sym *s, Reloc *r) - { -@@ -276,9 +270,12 @@ - break; - - case D_TLS: -- if(r->siz == 4) -- LPUT(R_ARM_TLS_LE32 | elfsym<<8); -- else -+ if(r->siz == 4) { -+ if(flag_shared) -+ LPUT(R_ARM_TLS_IE32 | elfsym<<8); -+ else -+ LPUT(R_ARM_TLS_LE32 | elfsym<<8); -+ } else - return -1; - break; - } -@@ -959,6 +956,8 @@ - rel->add = p->to.offset; - if(rel->sym == gmsym) { - rel->type = D_TLS; -+ if(flag_shared) -+ rel->add += pc - p->pcrel->pc - 8 - rel->siz; - rel->xadd = rel->add; - rel->xsym = rel->sym; - } else if(flag_shared) { -diff -r 5f1bc87f81de src/cmd/5l/l.h ---- a/src/cmd/5l/l.h Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/5l/l.h Thu Jun 27 16:06:56 2013 +0200 -@@ -184,7 +184,6 @@ - Reloc* r; - int32 nr; - int32 maxr; -- int rel_ro; - }; - - #define SIGNINTERN (1729*325*1729) -@@ -294,7 +293,6 @@ - EXTERN int32 INITRND; /* data round above text location */ - EXTERN int32 INITTEXT; /* text location */ - EXTERN char* INITENTRY; /* entry point */ --EXTERN char* LIBINITENTRY; /* shared library entry point */ - EXTERN int32 autosize; - EXTERN Auto* curauto; - EXTERN Auto* curhist; -diff -r 5f1bc87f81de src/cmd/5l/noop.c ---- a/src/cmd/5l/noop.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/5l/noop.c Thu Jun 27 16:06:56 2013 +0200 -@@ -179,15 +179,31 @@ - // - // MOV $runtime.tlsgm+tlsoffset(SB), REGTMP - // ADD REGTMP, -+ // -+ // In shared mode, runtime.tlsgm is relocated with -+ // R_ARM_TLS_IE32 and runtime.tlsgm(SB) will point -+ // to the GOT entry containing the TLS offset. -+ // -+ // MOV runtime.tlsgm(SB), REGTMP -+ // ADD REGTMP, -+ // SUB -tlsoffset, -+ // -+ // The SUB compensates for tlsoffset -+ // used in runtime.save_gm and runtime.load_gm. - q = p; - p = appendp(p); - p->as = AMOVW; - p->scond = 14; - p->reg = NREG; -- p->from.type = D_CONST; -+ if(flag_shared) { -+ p->from.type = D_OREG; -+ p->from.offset = 0; -+ } else { -+ p->from.type = D_CONST; -+ p->from.offset = tlsoffset; -+ } - p->from.sym = gmsym; - p->from.name = D_EXTERN; -- p->from.offset = tlsoffset; - p->to.type = D_REG; - p->to.reg = REGTMP; - p->to.offset = 0; -@@ -201,6 +217,18 @@ - p->to.type = D_REG; - p->to.reg = (q->to.offset & 0xf000) >> 12; - p->to.offset = 0; -+ -+ if(flag_shared) { -+ p = appendp(p); -+ p->as = ASUB; -+ p->scond = 14; -+ p->reg = NREG; -+ p->from.type = D_CONST; -+ p->from.offset = -tlsoffset; -+ p->to.type = D_REG; -+ p->to.reg = (q->to.offset & 0xf000) >> 12; -+ p->to.offset = 0; -+ } - } - } - } -diff -r 5f1bc87f81de src/cmd/5l/obj.c ---- a/src/cmd/5l/obj.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/5l/obj.c Thu Jun 27 16:06:56 2013 +0200 -@@ -81,7 +81,6 @@ - INITDAT = -1; - INITRND = -1; - INITENTRY = 0; -- LIBINITENTRY = 0; - linkmode = LinkAuto; - nuxiinit(); - -@@ -126,17 +125,20 @@ - flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); - flagcount("race", "enable race detector", &flag_race); - flagcount("s", "disable symbol table", &debug['s']); -+ flagcount("shared", "generate shared object (implies -linkmode external)", &flag_shared); - flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); - flagcount("u", "reject unsafe packages", &debug['u']); - flagcount("v", "print link trace", &debug['v']); - flagcount("w", "disable DWARF generation", &debug['w']); -- flagcount("shared", "generate shared object", &flag_shared); - - flagparse(&argc, &argv, usage); - - if(argc != 1) - usage(); - -+ if(flag_shared) -+ linkmode = LinkExternal; -+ - mywhatsys(); - - if(HEADTYPE == -1) -diff -r 5f1bc87f81de src/cmd/5l/pass.c ---- a/src/cmd/5l/pass.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/5l/pass.c Thu Jun 27 16:06:56 2013 +0200 -@@ -246,6 +246,13 @@ - p->cond = q; - } - } -+ if(flag_shared) { -+ s = lookup("init_array", 0); -+ s->type = SINITARR; -+ s->reachable = 1; -+ s->hide = 1; -+ addaddr(s, lookup(INITENTRY, 0)); -+ } - - for(cursym = textp; cursym != nil; cursym = cursym->next) { - for(p = cursym->text; p != P; p = p->link) { -diff -r 5f1bc87f81de src/cmd/5l/span.c ---- a/src/cmd/5l/span.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/5l/span.c Thu Jun 27 16:06:56 2013 +0200 -@@ -577,10 +577,7 @@ - if(s == S) - break; - instoffset = 0; // s.b. unused but just in case -- if(flag_shared) -- return C_LCONADDR; -- else -- return C_LCON; -+ return C_LCONADDR; - - case D_AUTO: - instoffset = autosize + a->offset; -diff -r 5f1bc87f81de src/cmd/6a/a.y ---- a/src/cmd/6a/a.y Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6a/a.y Thu Jun 27 16:06:56 2013 +0200 -@@ -494,6 +494,15 @@ - $$.scale = $8; - checkscale($$.scale); - } -+| con '(' LLREG ')' '(' LSREG '*' con ')' -+ { -+ $$ = nullgen; -+ $$.type = D_INDIR+$3; -+ $$.offset = $1; -+ $$.index = $6; -+ $$.scale = $8; -+ checkscale($$.scale); -+ } - | '(' LLREG ')' - { - $$ = nullgen; -diff -r 5f1bc87f81de src/cmd/6a/y.tab.c ---- a/src/cmd/6a/y.tab.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6a/y.tab.c Thu Jun 27 16:06:56 2013 +0200 -@@ -1,24 +1,21 @@ --/* A Bison parser, made by GNU Bison 2.3. */ -- --/* Skeleton implementation for Bison's Yacc-like parsers in C -- -- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 -- Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -+/* A Bison parser, made by GNU Bison 2.5. */ -+ -+/* Bison implementation for Yacc-like parsers in C -+ -+ Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. -+ -+ This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -+ the Free Software Foundation, either version 3 of the License, or -+ (at your option) any later version. -+ - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. -- -+ - You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. */ -+ along with this program. If not, see . */ - - /* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work -@@ -29,7 +26,7 @@ - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. -- -+ - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -@@ -47,7 +44,7 @@ - #define YYBISON 1 - - /* Bison version. */ --#define YYBISON_VERSION "2.3" -+#define YYBISON_VERSION "2.5" - - /* Skeleton name. */ - #define YYSKELETON_NAME "yacc.c" -@@ -55,11 +52,50 @@ - /* Pure parsers. */ - #define YYPURE 0 - -+/* Push parsers. */ -+#define YYPUSH 0 -+ -+/* Pull parsers. */ -+#define YYPULL 1 -+ - /* Using locations. */ - #define YYLSP_NEEDED 0 - - - -+/* Copy the first part of user declarations. */ -+ -+/* Line 268 of yacc.c */ -+#line 31 "a.y" -+ -+#include -+#include /* if we don't, bison will, and a.h re-#defines getc */ -+#include -+#include "a.h" -+ -+ -+/* Line 268 of yacc.c */ -+#line 79 "y.tab.c" -+ -+/* Enabling traces. */ -+#ifndef YYDEBUG -+# define YYDEBUG 0 -+#endif -+ -+/* Enabling verbose error messages. */ -+#ifdef YYERROR_VERBOSE -+# undef YYERROR_VERBOSE -+# define YYERROR_VERBOSE 1 -+#else -+# define YYERROR_VERBOSE 0 -+#endif -+ -+/* Enabling the token table. */ -+#ifndef YYTOKEN_TABLE -+# define YYTOKEN_TABLE 0 -+#endif -+ -+ - /* Tokens. */ - #ifndef YYTOKENTYPE - # define YYTOKENTYPE -@@ -139,59 +175,36 @@ - - - --/* Copy the first part of user declarations. */ --#line 31 "a.y" -- --#include --#include /* if we don't, bison will, and a.h re-#defines getc */ --#include --#include "a.h" -- -- --/* Enabling traces. */ --#ifndef YYDEBUG --# define YYDEBUG 0 --#endif -- --/* Enabling verbose error messages. */ --#ifdef YYERROR_VERBOSE --# undef YYERROR_VERBOSE --# define YYERROR_VERBOSE 1 --#else --# define YYERROR_VERBOSE 0 --#endif -- --/* Enabling the token table. */ --#ifndef YYTOKEN_TABLE --# define YYTOKEN_TABLE 0 --#endif -- - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - typedef union YYSTYPE -+{ -+ -+/* Line 293 of yacc.c */ - #line 37 "a.y" --{ -+ - Sym *sym; - vlong lval; - double dval; - char sval[8]; - Gen gen; - Gen2 gen2; --} --/* Line 193 of yacc.c. */ --#line 182 "y.tab.c" -- YYSTYPE; -+ -+ -+ -+/* Line 293 of yacc.c */ -+#line 196 "y.tab.c" -+} YYSTYPE; -+# define YYSTYPE_IS_TRIVIAL 1 - # define yystype YYSTYPE /* obsolescent; will be withdrawn */ - # define YYSTYPE_IS_DECLARED 1 --# define YYSTYPE_IS_TRIVIAL 1 - #endif - - -- - /* Copy the second part of user declarations. */ - - --/* Line 216 of yacc.c. */ --#line 195 "y.tab.c" -+/* Line 343 of yacc.c */ -+#line 208 "y.tab.c" - - #ifdef short - # undef short -@@ -266,14 +279,14 @@ - #if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) - static int --YYID (int i) -+YYID (int yyi) - #else - static int --YYID (i) -- int i; -+YYID (yyi) -+ int yyi; - #endif - { -- return i; -+ return yyi; - } - #endif - -@@ -294,11 +307,11 @@ - # define alloca _alloca - # else - # define YYSTACK_ALLOC alloca --# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ -+# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) - # include /* INFRINGES ON USER NAME SPACE */ --# ifndef _STDLIB_H --# define _STDLIB_H 1 -+# ifndef EXIT_SUCCESS -+# define EXIT_SUCCESS 0 - # endif - # endif - # endif -@@ -321,24 +334,24 @@ - # ifndef YYSTACK_ALLOC_MAXIMUM - # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM - # endif --# if (defined __cplusplus && ! defined _STDLIB_H \ -+# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) - # include /* INFRINGES ON USER NAME SPACE */ --# ifndef _STDLIB_H --# define _STDLIB_H 1 -+# ifndef EXIT_SUCCESS -+# define EXIT_SUCCESS 0 - # endif - # endif - # ifndef YYMALLOC - # define YYMALLOC malloc --# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ -+# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) - void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ - # endif - # endif - # ifndef YYFREE - # define YYFREE free --# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ -+# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) - void free (void *); /* INFRINGES ON USER NAME SPACE */ - # endif -@@ -354,9 +367,9 @@ - /* A type that is properly aligned for any stack member. */ - union yyalloc - { -- yytype_int16 yyss; -- YYSTYPE yyvs; -- }; -+ yytype_int16 yyss_alloc; -+ YYSTYPE yyvs_alloc; -+}; - - /* The size of the maximum gap between one aligned stack and the next. */ - # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) -@@ -367,6 +380,27 @@ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -+# define YYCOPY_NEEDED 1 -+ -+/* Relocate STACK from its old location to the new one. The -+ local variables YYSIZE and YYSTACKSIZE give the old and new number of -+ elements in the stack, and YYPTR gives the new location of the -+ stack. Advance YYPTR to a properly aligned location for the next -+ stack. */ -+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ -+ do \ -+ { \ -+ YYSIZE_T yynewbytes; \ -+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ -+ Stack = &yyptr->Stack_alloc; \ -+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ -+ yyptr += yynewbytes / sizeof (*yyptr); \ -+ } \ -+ while (YYID (0)) -+ -+#endif -+ -+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED - /* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ - # ifndef YYCOPY -@@ -384,24 +418,7 @@ - while (YYID (0)) - # endif - # endif -- --/* Relocate STACK from its old location to the new one. The -- local variables YYSIZE and YYSTACKSIZE give the old and new number of -- elements in the stack, and YYPTR gives the new location of the -- stack. Advance YYPTR to a properly aligned location for the next -- stack. */ --# define YYSTACK_RELOCATE(Stack) \ -- do \ -- { \ -- YYSIZE_T yynewbytes; \ -- YYCOPY (&yyptr->Stack, Stack, yysize); \ -- Stack = &yyptr->Stack; \ -- yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ -- yyptr += yynewbytes / sizeof (*yyptr); \ -- } \ -- while (YYID (0)) -- --#endif -+#endif /* !YYCOPY_NEEDED */ - - /* YYFINAL -- State number of the termination state. */ - #define YYFINAL 2 -@@ -413,9 +430,9 @@ - /* YYNNTS -- Number of nonterminals. */ - #define YYNNTS 40 - /* YYNRULES -- Number of rules. */ --#define YYNRULES 132 -+#define YYNRULES 133 - /* YYNRULES -- Number of states. */ --#define YYNSTATES 263 -+#define YYNSTATES 267 - - /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ - #define YYUNDEFTOK 2 -@@ -473,11 +490,11 @@ - 187, 191, 197, 199, 201, 203, 205, 208, 211, 213, - 215, 217, 219, 224, 227, 230, 232, 234, 236, 238, - 240, 242, 244, 247, 250, 253, 256, 259, 264, 270, -- 274, 276, 278, 280, 285, 290, 295, 302, 312, 316, -- 320, 326, 335, 337, 344, 350, 358, 359, 362, 365, -- 367, 369, 371, 373, 375, 378, 381, 384, 388, 390, -- 393, 397, 402, 404, 408, 412, 416, 420, 424, 429, -- 434, 438, 442 -+ 274, 276, 278, 280, 285, 290, 295, 302, 312, 322, -+ 326, 330, 336, 345, 347, 354, 360, 368, 369, 372, -+ 375, 377, 379, 381, 383, 385, 388, 391, 394, 398, -+ 400, 403, 407, 412, 414, 418, 422, 426, 430, 434, -+ 439, 444, 448, 452 - }; - - /* YYRHS -- A `-1'-separated list of the rules' RHS. */ -@@ -514,6 +531,7 @@ - 91, 50, 35, 51, -1, 91, 50, 42, 51, -1, - 91, 50, 36, 51, -1, 91, 50, 35, 10, 91, - 51, -1, 91, 50, 35, 51, 50, 35, 10, 91, -+ 51, -1, 91, 50, 35, 51, 50, 36, 10, 91, - 51, -1, 50, 35, 51, -1, 50, 42, 51, -1, - 50, 35, 10, 91, 51, -1, 50, 35, 51, 50, - 35, 10, 91, 51, -1, 88, -1, 88, 50, 35, -@@ -542,11 +560,11 @@ - 299, 304, 312, 313, 316, 317, 318, 322, 326, 327, - 330, 331, 334, 340, 349, 358, 363, 368, 373, 378, - 383, 388, 394, 402, 408, 419, 425, 431, 437, 443, -- 451, 452, 455, 461, 467, 473, 479, 488, 497, 502, -- 507, 515, 525, 529, 538, 545, 554, 557, 561, 567, -- 568, 572, 575, 576, 580, 584, 588, 592, 598, 602, -- 606, 611, 618, 619, 623, 627, 631, 635, 639, 643, -- 647, 651, 655 -+ 451, 452, 455, 461, 467, 473, 479, 488, 497, 506, -+ 511, 516, 524, 534, 538, 547, 554, 563, 566, 570, -+ 576, 577, 581, 584, 585, 589, 593, 597, 601, 607, -+ 611, 615, 620, 627, 628, 632, 636, 640, 644, 648, -+ 652, 656, 660, 664 - }; - #endif - -@@ -561,12 +579,12 @@ - "LTYPES", "LTYPEM", "LTYPEI", "LTYPEXC", "LTYPEX", "LTYPERT", "LCONST", - "LFP", "LPC", "LSB", "LBREG", "LLREG", "LSREG", "LFREG", "LMREG", - "LXREG", "LFCONST", "LSCONST", "LSP", "LNAME", "LLAB", "LVAR", "':'", -- "';'", "'='", "','", "'('", "')'", "'$'", "'~'", "$accept", "prog", "@1", -- "line", "@2", "@3", "inst", "nonnon", "rimrem", "remrim", "rimnon", -- "nonrem", "nonrel", "spec1", "spec2", "spec3", "spec4", "spec5", "spec6", -- "spec7", "spec8", "spec9", "spec10", "spec11", "rem", "rom", "rim", -- "rel", "reg", "imm2", "imm", "mem", "omem", "nmem", "nam", "offset", -- "pointer", "con", "con2", "expr", 0 -+ "';'", "'='", "','", "'('", "')'", "'$'", "'~'", "$accept", "prog", -+ "$@1", "line", "$@2", "$@3", "inst", "nonnon", "rimrem", "remrim", -+ "rimnon", "nonrem", "nonrel", "spec1", "spec2", "spec3", "spec4", -+ "spec5", "spec6", "spec7", "spec8", "spec9", "spec10", "spec11", "rem", -+ "rom", "rim", "rel", "reg", "imm2", "imm", "mem", "omem", "nmem", "nam", -+ "offset", "pointer", "con", "con2", "expr", 0 - }; - #endif - -@@ -597,10 +615,10 @@ - 80, 80, 81, 81, 81, 82, 82, 82, 82, 82, - 82, 82, 83, 84, 84, 84, 84, 84, 84, 84, - 85, 85, 86, 86, 86, 86, 86, 86, 86, 86, -- 86, 86, 87, 87, 88, 88, 89, 89, 89, 90, -- 90, 90, 91, 91, 91, 91, 91, 91, 92, 92, -- 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, -- 93, 93, 93 -+ 86, 86, 86, 87, 87, 88, 88, 89, 89, 89, -+ 90, 90, 90, 91, 91, 91, 91, 91, 91, 92, -+ 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, -+ 93, 93, 93, 93 - }; - - /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -@@ -615,45 +633,45 @@ - 3, 5, 1, 1, 1, 1, 2, 2, 1, 1, - 1, 1, 4, 2, 2, 1, 1, 1, 1, 1, - 1, 1, 2, 2, 2, 2, 2, 4, 5, 3, -- 1, 1, 1, 4, 4, 4, 6, 9, 3, 3, -- 5, 8, 1, 6, 5, 7, 0, 2, 2, 1, -- 1, 1, 1, 1, 2, 2, 2, 3, 1, 2, -- 3, 4, 1, 3, 3, 3, 3, 3, 4, 4, -- 3, 3, 3 -+ 1, 1, 1, 4, 4, 4, 6, 9, 9, 3, -+ 3, 5, 8, 1, 6, 5, 7, 0, 2, 2, -+ 1, 1, 1, 1, 1, 2, 2, 2, 3, 1, -+ 2, 3, 4, 1, 3, 3, 3, 3, 3, 4, -+ 4, 3, 3, 3 - }; - --/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state -- STATE-NUM when YYTABLE doesn't specify something else to do. Zero -+/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. -+ Performed when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ - static const yytype_uint8 yydefact[] = - { - 2, 3, 1, 0, 0, 31, 0, 0, 0, 0, - 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, - 0, 58, 0, 0, 0, 9, 4, 0, 11, 32, -- 14, 0, 0, 112, 75, 77, 80, 76, 78, 81, -- 79, 106, 113, 0, 0, 0, 15, 38, 62, 63, -- 90, 91, 102, 92, 0, 16, 70, 36, 71, 17, -- 0, 18, 0, 0, 106, 106, 0, 22, 46, 64, -+ 14, 0, 0, 113, 75, 77, 80, 76, 78, 81, -+ 79, 107, 114, 0, 0, 0, 15, 38, 62, 63, -+ 90, 91, 103, 92, 0, 16, 70, 36, 71, 17, -+ 0, 18, 0, 0, 107, 107, 0, 22, 46, 64, - 68, 69, 65, 92, 20, 0, 32, 47, 48, 23, -- 106, 0, 0, 19, 40, 0, 0, 21, 0, 30, -+ 107, 0, 0, 19, 40, 0, 0, 21, 0, 30, - 0, 24, 0, 25, 0, 26, 54, 27, 0, 28, -- 0, 29, 59, 7, 0, 5, 0, 10, 115, 114, -- 0, 0, 0, 0, 37, 0, 0, 122, 0, 116, -+ 0, 29, 59, 7, 0, 5, 0, 10, 116, 115, -+ 0, 0, 0, 0, 37, 0, 0, 123, 0, 117, - 0, 0, 0, 86, 85, 0, 84, 83, 35, 0, - 0, 66, 67, 73, 74, 45, 0, 0, 73, 39, - 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, -- 12, 0, 13, 106, 107, 108, 0, 0, 98, 99, -+ 12, 0, 13, 107, 108, 109, 0, 0, 99, 100, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -- 117, 0, 0, 0, 0, 89, 0, 0, 33, 34, -+ 118, 0, 0, 0, 0, 89, 0, 0, 33, 34, - 0, 0, 41, 0, 43, 0, 60, 0, 49, 51, -- 55, 0, 0, 8, 6, 0, 111, 109, 110, 0, -- 0, 0, 132, 131, 130, 0, 0, 123, 124, 125, -- 126, 127, 0, 0, 93, 95, 94, 0, 87, 72, -- 0, 0, 118, 82, 0, 0, 0, 0, 0, 0, -- 0, 104, 100, 0, 128, 129, 0, 0, 0, 88, -- 42, 119, 0, 44, 61, 50, 52, 56, 57, 0, -- 0, 103, 96, 0, 0, 120, 105, 0, 0, 121, -- 101, 0, 97 -+ 55, 0, 0, 8, 6, 0, 112, 110, 111, 0, -+ 0, 0, 133, 132, 131, 0, 0, 124, 125, 126, -+ 127, 128, 0, 0, 93, 95, 94, 0, 87, 72, -+ 0, 0, 119, 82, 0, 0, 0, 0, 0, 0, -+ 0, 105, 101, 0, 129, 130, 0, 0, 0, 88, -+ 42, 120, 0, 44, 61, 50, 52, 56, 57, 0, -+ 0, 104, 96, 0, 0, 0, 121, 106, 0, 0, -+ 0, 122, 102, 0, 0, 97, 98 - }; - - /* YYDEFGOTO[NTERM-NUM]. */ -@@ -672,46 +690,45 @@ - { - -97, 40, -97, 208, 5, -4, 140, 295, 295, 343, - 233, 15, 319, 381, 91, 91, 295, 295, 295, 222, -- 24, 24, -15, 22, 14, -97, -97, 30, -97, -97, -+ 24, 24, -15, 31, 14, -97, -97, 48, -97, -97, - -97, 486, 486, -97, -97, -97, -97, -97, -97, -97, - -97, 42, -97, 343, 406, 486, -97, -97, -97, -97, -- -97, -97, 45, 48, 399, -97, -97, 20, -97, -97, -- 67, -97, 68, 367, 42, 19, 271, -97, -97, -97, -- -97, -97, -97, 87, -97, 127, 343, -97, -97, -97, -- 19, 437, 486, -97, -97, 90, 92, -97, 94, -97, -- 96, -97, 104, -97, 105, -97, 111, -97, 118, -97, -- 119, -97, -97, -97, 486, -97, 486, -97, -97, -97, -- 133, 486, 486, 121, -97, 8, 122, -97, 80, -97, -- 134, 78, 413, -97, -97, 446, -97, -97, -97, 343, -- 295, -97, -97, 121, -97, -97, 7, 486, -97, -97, -- 437, 148, 453, 462, 343, 343, 343, 343, 343, 208, -- 284, 208, 284, 19, -97, -97, -1, 486, 131, -97, -- 486, 486, 486, 166, 177, 486, 486, 486, 486, 486, -- -97, 176, 10, 136, 137, -97, 480, 141, -97, -97, -- 143, 142, -97, 16, -97, 149, -97, 150, 151, 154, -- -97, 152, 155, -97, -97, 156, -97, -97, -97, 157, -- 159, 170, 99, 535, 542, 486, 486, 26, 26, -97, -- -97, -97, 486, 486, 161, -97, -97, 162, -97, -97, -- 24, 184, 198, -97, 163, 24, 181, 183, 486, 222, -- 205, -97, -97, 229, 114, 114, 193, 194, 211, -97, -- -97, 238, 219, -97, -97, -97, -97, -97, -97, 199, -- 486, -97, -97, 244, 232, -97, -97, 214, 486, -97, -- -97, 215, -97 -+ -97, -97, 66, 67, 399, -97, -97, 49, -97, -97, -+ 88, -97, 89, 367, 42, 19, 271, -97, -97, -97, -+ -97, -97, -97, 90, -97, 128, 343, -97, -97, -97, -+ 19, 437, 486, -97, -97, 93, 95, -97, 94, -97, -+ 104, -97, 105, -97, 111, -97, 118, -97, 119, -97, -+ 120, -97, -97, -97, 486, -97, 486, -97, -97, -97, -+ 164, 486, 486, 122, -97, 8, 129, -97, 80, -97, -+ 138, 78, 413, -97, -97, 446, -97, -97, -97, 343, -+ 295, -97, -97, 122, -97, -97, 7, 486, -97, -97, -+ 437, 149, 453, 462, 343, 343, 343, 343, 343, 208, -+ 284, 208, 284, 19, -97, -97, -1, 486, 134, -97, -+ 486, 486, 486, 180, 181, 486, 486, 486, 486, 486, -+ -97, 177, 10, 141, 143, -97, 480, 146, -97, -97, -+ 147, 142, -97, 16, -97, 150, -97, 151, 155, 158, -+ -97, 156, 157, -97, -97, 160, -97, -97, -97, 162, -+ 163, 172, 99, 535, 542, 486, 486, 26, 26, -97, -+ -97, -97, 486, 486, 161, -97, -97, 165, -97, -97, -+ 24, 178, 206, -97, 167, 24, 203, 209, 486, 222, -+ 211, -97, -97, 229, 114, 114, 195, 196, 30, -97, -+ -97, 239, 224, -97, -97, -97, -97, -97, -97, 214, -+ 486, -97, -97, 252, 256, 243, -97, -97, 223, 486, -+ 486, -97, -97, 234, 246, -97, -97 - }; - - /* YYPGOTO[NTERM-NUM]. */ - static const yytype_int16 yypgoto[] = - { -- -97, -97, -97, -96, -97, -97, -97, 261, -97, -97, -- -97, 262, -97, -97, -97, -97, -97, -97, -97, -97, -- -97, -97, -97, -97, 17, 218, -2, -11, -9, 61, -- -8, 51, 1, -3, -7, -56, -97, -10, -97, -87 -+ -97, -97, -97, -96, -97, -97, -97, 272, -97, -97, -+ -97, 286, -97, -97, -97, -97, -97, -97, -97, -97, -+ -97, -97, -97, -97, 17, 236, -2, -11, -9, 75, -+ -8, 54, 1, -3, -7, -56, -97, -10, -97, -87 - }; - - /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which -- number is the opposite. If zero, do what YYDEFACT says. -- If YYTABLE_NINF, syntax error. */ -+ number is the opposite. If YYTABLE_NINF, syntax error. */ - #define YYTABLE_NINF -1 - static const yytype_uint16 yytable[] = - { -@@ -721,31 +738,31 @@ - 196, 103, 197, 104, 117, 119, 167, 168, 169, 180, - 2, 198, 172, 173, 127, 29, 222, 126, 110, 174, - 111, 112, 28, 193, 131, 194, 73, 70, 41, 158, -- 114, 214, 106, 72, 132, 88, 90, 71, 105, 128, -- 139, 86, 117, 202, 203, 204, 54, 107, 207, 208, -+ 114, 214, 106, 72, 132, 253, 254, 71, 88, 90, -+ 139, 86, 117, 202, 203, 204, 54, 105, 207, 208, - 209, 210, 211, 160, 161, 162, 163, 164, 165, 166, -- 167, 168, 169, 114, 117, 120, 117, 195, 121, 31, -+ 167, 168, 169, 114, 117, 107, 117, 195, 128, 31, - 32, 154, 155, 161, 162, 163, 164, 165, 166, 167, -- 168, 169, 109, 172, 173, 117, 129, 130, 234, 235, -+ 168, 169, 109, 172, 173, 117, 120, 121, 234, 235, - 174, 33, 165, 166, 167, 168, 169, 181, 179, 182, -- 86, 170, 185, 187, 41, 186, 42, 136, 137, 140, -- 153, 44, 141, 142, 45, 143, 178, 200, 31, 32, -- 117, 117, 117, 144, 145, 117, 117, 117, 117, 117, -- 146, 188, 189, 190, 191, 192, 109, 147, 148, 171, -- 33, 156, 205, 159, 34, 35, 36, 37, 38, 39, -- 180, 201, 40, 41, 206, 42, 212, 215, 216, 43, -- 44, 220, 218, 45, 219, 117, 117, 226, 224, 225, -- 227, 228, 236, 237, 229, 233, 230, 242, 231, 4, -- 232, 238, 240, 239, 241, 183, 245, 244, 247, 246, -+ 86, 170, 185, 187, 41, 186, 42, 129, 130, 137, -+ 136, 44, 140, 142, 45, 141, 178, 200, 31, 32, -+ 117, 117, 117, 143, 144, 117, 117, 117, 117, 117, -+ 145, 188, 189, 190, 191, 192, 109, 146, 147, 148, -+ 33, 153, 156, 171, 34, 35, 36, 37, 38, 39, -+ 159, 180, 40, 41, 201, 42, 205, 212, 206, 43, -+ 44, 220, 215, 45, 216, 117, 117, 218, 219, 224, -+ 225, 226, 236, 237, 227, 228, 229, 233, 241, 4, -+ 230, 238, 240, 231, 232, 242, 239, 244, 247, 183, - 248, 5, 6, 7, 8, 9, 10, 11, 12, 13, -- 14, 15, 16, 17, 18, 19, 20, 21, 249, 250, -- 257, 31, 32, 63, 251, 252, 253, 254, 261, 255, -- 256, 22, 23, 24, 258, 25, 34, 35, 36, 37, -- 38, 39, 259, 33, 40, 260, 262, 34, 35, 36, -- 37, 38, 39, 77, 78, 40, 64, 65, 42, 31, -- 32, 63, 66, 44, 135, 243, 45, 160, 161, 162, -- 163, 164, 165, 166, 167, 168, 169, 0, 0, 0, -- 0, 33, 0, 31, 32, 34, 35, 36, 37, 38, -+ 14, 15, 16, 17, 18, 19, 20, 21, 245, 250, -+ 258, 31, 32, 63, 249, 246, 251, 252, 255, 263, -+ 264, 22, 23, 24, 256, 25, 34, 35, 36, 37, -+ 38, 39, 259, 33, 40, 257, 260, 34, 35, 36, -+ 37, 38, 39, 261, 262, 40, 64, 65, 42, 31, -+ 32, 63, 66, 44, 77, 265, 45, 160, 161, 162, -+ 163, 164, 165, 166, 167, 168, 169, 266, 78, 243, -+ 0, 33, 135, 31, 32, 34, 35, 36, 37, 38, - 39, 0, 0, 40, 64, 65, 42, 0, 0, 0, - 0, 44, 0, 0, 45, 33, 0, 31, 32, 34, - 35, 36, 37, 38, 39, 0, 0, 40, 41, 0, -@@ -773,6 +790,12 @@ - 165, 166, 167, 168, 169 - }; - -+#define yypact_value_is_default(yystate) \ -+ ((yystate) == (-97)) -+ -+#define yytable_value_is_error(yytable_value) \ -+ YYID (0) -+ - static const yytype_int16 yycheck[] = - { - 10, 10, 13, 13, 11, 13, 8, 10, 64, 65, -@@ -781,31 +804,31 @@ - 31, 46, 33, 48, 44, 45, 10, 11, 12, 32, - 0, 42, 35, 36, 54, 49, 30, 54, 6, 42, - 8, 9, 47, 149, 63, 151, 66, 66, 43, 51, -- 43, 51, 48, 66, 63, 14, 15, 66, 46, 49, -- 81, 81, 82, 160, 161, 162, 52, 47, 165, 166, -+ 43, 51, 48, 66, 63, 35, 36, 66, 14, 15, -+ 81, 81, 82, 160, 161, 162, 52, 46, 165, 166, - 167, 168, 169, 3, 4, 5, 6, 7, 8, 9, -- 10, 11, 12, 76, 104, 50, 106, 153, 50, 8, -+ 10, 11, 12, 76, 104, 47, 106, 153, 49, 8, - 9, 111, 112, 4, 5, 6, 7, 8, 9, 10, -- 11, 12, 122, 35, 36, 125, 49, 49, 205, 206, -+ 11, 12, 122, 35, 36, 125, 50, 50, 205, 206, - 42, 30, 8, 9, 10, 11, 12, 137, 130, 140, -- 140, 51, 142, 143, 43, 143, 45, 50, 11, 49, -- 7, 50, 50, 49, 53, 49, 129, 157, 8, 9, -+ 140, 51, 142, 143, 43, 143, 45, 49, 49, 11, -+ 50, 50, 49, 49, 53, 50, 129, 157, 8, 9, - 160, 161, 162, 49, 49, 165, 166, 167, 168, 169, -- 49, 144, 145, 146, 147, 148, 176, 49, 49, 35, -- 30, 50, 6, 51, 34, 35, 36, 37, 38, 39, -- 32, 50, 42, 43, 7, 45, 10, 51, 51, 49, -- 50, 49, 51, 53, 51, 205, 206, 46, 49, 49, -- 46, 49, 212, 213, 49, 35, 50, 9, 51, 1, -- 51, 50, 220, 51, 30, 52, 35, 225, 228, 36, -+ 49, 144, 145, 146, 147, 148, 176, 49, 49, 49, -+ 30, 7, 50, 35, 34, 35, 36, 37, 38, 39, -+ 51, 32, 42, 43, 50, 45, 6, 10, 7, 49, -+ 50, 49, 51, 53, 51, 205, 206, 51, 51, 49, -+ 49, 46, 212, 213, 46, 49, 49, 35, 30, 1, -+ 50, 50, 220, 51, 51, 9, 51, 225, 228, 52, - 229, 13, 14, 15, 16, 17, 18, 19, 20, 21, -- 22, 23, 24, 25, 26, 27, 28, 29, 33, 10, -- 250, 8, 9, 10, 51, 51, 35, 9, 258, 30, -- 51, 43, 44, 45, 10, 47, 34, 35, 36, 37, -- 38, 39, 30, 30, 42, 51, 51, 34, 35, 36, -- 37, 38, 39, 12, 12, 42, 43, 44, 45, 8, -- 9, 10, 49, 50, 66, 224, 53, 3, 4, 5, -- 6, 7, 8, 9, 10, 11, 12, -1, -1, -1, -- -1, 30, -1, 8, 9, 34, 35, 36, 37, 38, -+ 22, 23, 24, 25, 26, 27, 28, 29, 35, 10, -+ 250, 8, 9, 10, 33, 36, 51, 51, 9, 259, -+ 260, 43, 44, 45, 30, 47, 34, 35, 36, 37, -+ 38, 39, 10, 30, 42, 51, 10, 34, 35, 36, -+ 37, 38, 39, 30, 51, 42, 43, 44, 45, 8, -+ 9, 10, 49, 50, 12, 51, 53, 3, 4, 5, -+ 6, 7, 8, 9, 10, 11, 12, 51, 12, 224, -+ -1, 30, 66, 8, 9, 34, 35, 36, 37, 38, - 39, -1, -1, 42, 43, 44, 45, -1, -1, -1, - -1, 50, -1, -1, 53, 30, -1, 8, 9, 34, - 35, 36, 37, 38, 39, -1, -1, 42, 43, -1, -@@ -862,8 +885,8 @@ - 49, 9, 30, 92, 49, 49, 46, 46, 49, 49, - 50, 51, 51, 35, 93, 93, 91, 91, 50, 51, - 84, 30, 9, 83, 84, 35, 36, 91, 82, 33, -- 10, 51, 51, 35, 9, 30, 51, 91, 10, 30, -- 51, 91, 51 -+ 10, 51, 51, 35, 36, 9, 30, 51, 91, 10, -+ 10, 30, 51, 91, 91, 51, 51 - }; - - #define yyerrok (yyerrstatus = 0) -@@ -878,9 +901,18 @@ - - /* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. -- Once GCC version 2 has supplanted version 1, this can go. */ -+ Once GCC version 2 has supplanted version 1, this can go. However, -+ YYFAIL appears to be in use. Nevertheless, it is formally deprecated -+ in Bison 2.4.2's NEWS entry, where a plan to phase it out is -+ discussed. */ - - #define YYFAIL goto yyerrlab -+#if defined YYFAIL -+ /* This is here to suppress warnings from the GCC cpp's -+ -Wunused-macros. Normally we don't worry about that warning, but -+ some users do, and we want to make it easy for users to remove -+ YYFAIL uses, which will produce warnings from Bison 2.5. */ -+#endif - - #define YYRECOVERING() (!!yyerrstatus) - -@@ -890,7 +922,6 @@ - { \ - yychar = (Token); \ - yylval = (Value); \ -- yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ -@@ -932,19 +963,10 @@ - #endif - - --/* YY_LOCATION_PRINT -- Print the location on the stream. -- This macro was not mandated originally: define only if we know -- we won't break user code: when these are the locations we know. */ -+/* This macro is provided for backward compatibility. */ - - #ifndef YY_LOCATION_PRINT --# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL --# define YY_LOCATION_PRINT(File, Loc) \ -- fprintf (File, "%d.%d-%d.%d", \ -- (Loc).first_line, (Loc).first_column, \ -- (Loc).last_line, (Loc).last_column) --# else --# define YY_LOCATION_PRINT(File, Loc) ((void) 0) --# endif -+# define YY_LOCATION_PRINT(File, Loc) ((void) 0) - #endif - - -@@ -1048,17 +1070,20 @@ - #if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) - static void --yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) -+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) - #else - static void --yy_stack_print (bottom, top) -- yytype_int16 *bottom; -- yytype_int16 *top; -+yy_stack_print (yybottom, yytop) -+ yytype_int16 *yybottom; -+ yytype_int16 *yytop; - #endif - { - YYFPRINTF (stderr, "Stack now"); -- for (; bottom <= top; ++bottom) -- YYFPRINTF (stderr, " %d", *bottom); -+ for (; yybottom <= yytop; yybottom++) -+ { -+ int yybot = *yybottom; -+ YYFPRINTF (stderr, " %d", yybot); -+ } - YYFPRINTF (stderr, "\n"); - } - -@@ -1092,11 +1117,11 @@ - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { -- fprintf (stderr, " $%d = ", yyi + 1); -+ YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); -- fprintf (stderr, "\n"); -+ YYFPRINTF (stderr, "\n"); - } - } - -@@ -1133,7 +1158,6 @@ - # define YYMAXDEPTH 10000 - #endif - -- - - #if YYERROR_VERBOSE - -@@ -1236,115 +1260,142 @@ - } - # endif - --/* Copy into YYRESULT an error message about the unexpected token -- YYCHAR while in state YYSTATE. Return the number of bytes copied, -- including the terminating null byte. If YYRESULT is null, do not -- copy anything; just return the number of bytes that would be -- copied. As a special case, return 0 if an ordinary "syntax error" -- message will do. Return YYSIZE_MAXIMUM if overflow occurs during -- size calculation. */ --static YYSIZE_T --yysyntax_error (char *yyresult, int yystate, int yychar) -+/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message -+ about the unexpected token YYTOKEN for the state stack whose top is -+ YYSSP. -+ -+ Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is -+ not large enough to hold the message. In that case, also set -+ *YYMSG_ALLOC to the required number of bytes. Return 2 if the -+ required number of bytes is too large to store. */ -+static int -+yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, -+ yytype_int16 *yyssp, int yytoken) - { -- int yyn = yypact[yystate]; -- -- if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) -- return 0; -- else -+ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); -+ YYSIZE_T yysize = yysize0; -+ YYSIZE_T yysize1; -+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; -+ /* Internationalized format string. */ -+ const char *yyformat = 0; -+ /* Arguments of yyformat. */ -+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; -+ /* Number of reported tokens (one for the "unexpected", one per -+ "expected"). */ -+ int yycount = 0; -+ -+ /* There are many possibilities here to consider: -+ - Assume YYFAIL is not used. It's too flawed to consider. See -+ -+ for details. YYERROR is fine as it does not invoke this -+ function. -+ - If this state is a consistent state with a default action, then -+ the only way this function was invoked is if the default action -+ is an error action. In that case, don't check for expected -+ tokens because there are none. -+ - The only way there can be no lookahead present (in yychar) is if -+ this state is a consistent state with a default action. Thus, -+ detecting the absence of a lookahead is sufficient to determine -+ that there is no unexpected or expected token to report. In that -+ case, just report a simple "syntax error". -+ - Don't assume there isn't a lookahead just because this state is a -+ consistent state with a default action. There might have been a -+ previous inconsistent state, consistent state with a non-default -+ action, or user semantic action that manipulated yychar. -+ - Of course, the expected token list depends on states to have -+ correct lookahead information, and it depends on the parser not -+ to perform extra reductions after fetching a lookahead from the -+ scanner and before detecting a syntax error. Thus, state merging -+ (from LALR or IELR) and default reductions corrupt the expected -+ token list. However, the list is correct for canonical LR with -+ one exception: it will still contain any token that will not be -+ accepted due to an error action in a later state. -+ */ -+ if (yytoken != YYEMPTY) - { -- int yytype = YYTRANSLATE (yychar); -- YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); -- YYSIZE_T yysize = yysize0; -- YYSIZE_T yysize1; -- int yysize_overflow = 0; -- enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; -- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; -- int yyx; -- --# if 0 -- /* This is so xgettext sees the translatable formats that are -- constructed on the fly. */ -- YY_("syntax error, unexpected %s"); -- YY_("syntax error, unexpected %s, expecting %s"); -- YY_("syntax error, unexpected %s, expecting %s or %s"); -- YY_("syntax error, unexpected %s, expecting %s or %s or %s"); -- YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); --# endif -- char *yyfmt; -- char const *yyf; -- static char const yyunexpected[] = "syntax error, unexpected %s"; -- static char const yyexpecting[] = ", expecting %s"; -- static char const yyor[] = " or %s"; -- char yyformat[sizeof yyunexpected -- + sizeof yyexpecting - 1 -- + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) -- * (sizeof yyor - 1))]; -- char const *yyprefix = yyexpecting; -- -- /* Start YYX at -YYN if negative to avoid negative indexes in -- YYCHECK. */ -- int yyxbegin = yyn < 0 ? -yyn : 0; -- -- /* Stay within bounds of both yycheck and yytname. */ -- int yychecklim = YYLAST - yyn + 1; -- int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; -- int yycount = 1; -- -- yyarg[0] = yytname[yytype]; -- yyfmt = yystpcpy (yyformat, yyunexpected); -- -- for (yyx = yyxbegin; yyx < yyxend; ++yyx) -- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) -- { -- if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) -- { -- yycount = 1; -- yysize = yysize0; -- yyformat[sizeof yyunexpected - 1] = '\0'; -- break; -- } -- yyarg[yycount++] = yytname[yyx]; -- yysize1 = yysize + yytnamerr (0, yytname[yyx]); -- yysize_overflow |= (yysize1 < yysize); -- yysize = yysize1; -- yyfmt = yystpcpy (yyfmt, yyprefix); -- yyprefix = yyor; -- } -- -- yyf = YY_(yyformat); -- yysize1 = yysize + yystrlen (yyf); -- yysize_overflow |= (yysize1 < yysize); -- yysize = yysize1; -- -- if (yysize_overflow) -- return YYSIZE_MAXIMUM; -- -- if (yyresult) -- { -- /* Avoid sprintf, as that infringes on the user's name space. -- Don't have undefined behavior even if the translation -- produced a string with the wrong number of "%s"s. */ -- char *yyp = yyresult; -- int yyi = 0; -- while ((*yyp = *yyf) != '\0') -- { -- if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) -- { -- yyp += yytnamerr (yyp, yyarg[yyi++]); -- yyf += 2; -- } -- else -- { -- yyp++; -- yyf++; -- } -- } -- } -- return yysize; -+ int yyn = yypact[*yyssp]; -+ yyarg[yycount++] = yytname[yytoken]; -+ if (!yypact_value_is_default (yyn)) -+ { -+ /* Start YYX at -YYN if negative to avoid negative indexes in -+ YYCHECK. In other words, skip the first -YYN actions for -+ this state because they are default actions. */ -+ int yyxbegin = yyn < 0 ? -yyn : 0; -+ /* Stay within bounds of both yycheck and yytname. */ -+ int yychecklim = YYLAST - yyn + 1; -+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; -+ int yyx; -+ -+ for (yyx = yyxbegin; yyx < yyxend; ++yyx) -+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR -+ && !yytable_value_is_error (yytable[yyx + yyn])) -+ { -+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) -+ { -+ yycount = 1; -+ yysize = yysize0; -+ break; -+ } -+ yyarg[yycount++] = yytname[yyx]; -+ yysize1 = yysize + yytnamerr (0, yytname[yyx]); -+ if (! (yysize <= yysize1 -+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) -+ return 2; -+ yysize = yysize1; -+ } -+ } - } -+ -+ switch (yycount) -+ { -+# define YYCASE_(N, S) \ -+ case N: \ -+ yyformat = S; \ -+ break -+ YYCASE_(0, YY_("syntax error")); -+ YYCASE_(1, YY_("syntax error, unexpected %s")); -+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); -+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); -+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); -+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -+# undef YYCASE_ -+ } -+ -+ yysize1 = yysize + yystrlen (yyformat); -+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) -+ return 2; -+ yysize = yysize1; -+ -+ if (*yymsg_alloc < yysize) -+ { -+ *yymsg_alloc = 2 * yysize; -+ if (! (yysize <= *yymsg_alloc -+ && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) -+ *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; -+ return 1; -+ } -+ -+ /* Avoid sprintf, as that infringes on the user's name space. -+ Don't have undefined behavior even if the translation -+ produced a string with the wrong number of "%s"s. */ -+ { -+ char *yyp = *yymsg; -+ int yyi = 0; -+ while ((*yyp = *yyformat) != '\0') -+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) -+ { -+ yyp += yytnamerr (yyp, yyarg[yyi++]); -+ yyformat += 2; -+ } -+ else -+ { -+ yyp++; -+ yyformat++; -+ } -+ } -+ return 0; - } - #endif /* YYERROR_VERBOSE */ -- - - /*-----------------------------------------------. - | Release the memory associated to this symbol. | -@@ -1376,10 +1427,9 @@ - break; - } - } -- -+ - - /* Prevent warnings from -Wmissing-prototypes. */ -- - #ifdef YYPARSE_PARAM - #if defined __STDC__ || defined __cplusplus - int yyparse (void *YYPARSE_PARAM); -@@ -1395,18 +1445,16 @@ - #endif /* ! YYPARSE_PARAM */ - - -- --/* The look-ahead symbol. */ -+/* The lookahead symbol. */ - int yychar; - --/* The semantic value of the look-ahead symbol. */ -+/* The semantic value of the lookahead symbol. */ - YYSTYPE yylval; - - /* Number of syntax errors so far. */ - int yynerrs; - - -- - /*----------. - | yyparse. | - `----------*/ -@@ -1433,14 +1481,37 @@ - #endif - #endif - { -- -- int yystate; -+ int yystate; -+ /* Number of tokens to shift before error messages enabled. */ -+ int yyerrstatus; -+ -+ /* The stacks and their tools: -+ `yyss': related to states. -+ `yyvs': related to semantic values. -+ -+ Refer to the stacks thru separate pointers, to allow yyoverflow -+ to reallocate them elsewhere. */ -+ -+ /* The state stack. */ -+ yytype_int16 yyssa[YYINITDEPTH]; -+ yytype_int16 *yyss; -+ yytype_int16 *yyssp; -+ -+ /* The semantic value stack. */ -+ YYSTYPE yyvsa[YYINITDEPTH]; -+ YYSTYPE *yyvs; -+ YYSTYPE *yyvsp; -+ -+ YYSIZE_T yystacksize; -+ - int yyn; - int yyresult; -- /* Number of tokens to shift before error messages enabled. */ -- int yyerrstatus; -- /* Look-ahead token as an internal (translated) token number. */ -- int yytoken = 0; -+ /* Lookahead token as an internal (translated) token number. */ -+ int yytoken; -+ /* The variables used to return semantic value and location from the -+ action routines. */ -+ YYSTYPE yyval; -+ - #if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; -@@ -1448,51 +1519,28 @@ - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; - #endif - -- /* Three stacks and their tools: -- `yyss': related to states, -- `yyvs': related to semantic values, -- `yyls': related to locations. -- -- Refer to the stacks thru separate pointers, to allow yyoverflow -- to reallocate them elsewhere. */ -- -- /* The state stack. */ -- yytype_int16 yyssa[YYINITDEPTH]; -- yytype_int16 *yyss = yyssa; -- yytype_int16 *yyssp; -- -- /* The semantic value stack. */ -- YYSTYPE yyvsa[YYINITDEPTH]; -- YYSTYPE *yyvs = yyvsa; -- YYSTYPE *yyvsp; -- -- -- - #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - -- YYSIZE_T yystacksize = YYINITDEPTH; -- -- /* The variables used to return semantic value and location from the -- action routines. */ -- YYSTYPE yyval; -- -- - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - -+ yytoken = 0; -+ yyss = yyssa; -+ yyvs = yyvsa; -+ yystacksize = YYINITDEPTH; -+ - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; -- yychar = YYEMPTY; /* Cause a token to be read. */ -+ yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ -- - yyssp = yyss; - yyvsp = yyvs; - -@@ -1522,7 +1570,6 @@ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - -- - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might -@@ -1530,7 +1577,6 @@ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), -- - &yystacksize); - - yyss = yyss1; -@@ -1553,9 +1599,8 @@ - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; -- YYSTACK_RELOCATE (yyss); -- YYSTACK_RELOCATE (yyvs); -- -+ YYSTACK_RELOCATE (yyss_alloc, yyss); -+ YYSTACK_RELOCATE (yyvs_alloc, yyvs); - # undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); -@@ -1566,7 +1611,6 @@ - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - -- - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - -@@ -1576,6 +1620,9 @@ - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - -+ if (yystate == YYFINAL) -+ YYACCEPT; -+ - goto yybackup; - - /*-----------. -@@ -1584,16 +1631,16 @@ - yybackup: - - /* Do appropriate processing given the current state. Read a -- look-ahead token if we need one and don't already have one. */ -- -- /* First try to decide what to do without reference to look-ahead token. */ -+ lookahead token if we need one and don't already have one. */ -+ -+ /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; -- if (yyn == YYPACT_NINF) -+ if (yypact_value_is_default (yyn)) - goto yydefault; - -- /* Not known => get a look-ahead token if don't already have one. */ -- -- /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ -+ /* Not known => get a lookahead token if don't already have one. */ -+ -+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); -@@ -1619,26 +1666,22 @@ - yyn = yytable[yyn]; - if (yyn <= 0) - { -- if (yyn == 0 || yyn == YYTABLE_NINF) -- goto yyerrlab; -+ if (yytable_value_is_error (yyn)) -+ goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - -- if (yyn == YYFINAL) -- YYACCEPT; -- - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - -- /* Shift the look-ahead token. */ -+ /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - -- /* Discard the shifted token unless it is eof. */ -- if (yychar != YYEOF) -- yychar = YYEMPTY; -+ /* Discard the shifted token. */ -+ yychar = YYEMPTY; - - yystate = yyn; - *++yyvsp = yylval; -@@ -1678,6 +1721,8 @@ - switch (yyn) - { - case 3: -+ -+/* Line 1806 of yacc.c */ - #line 66 "a.y" - { - stmtline = lineno; -@@ -1685,6 +1730,8 @@ - break; - - case 5: -+ -+/* Line 1806 of yacc.c */ - #line 73 "a.y" - { - if((yyvsp[(1) - (2)].sym)->value != pc) -@@ -1694,6 +1741,8 @@ - break; - - case 7: -+ -+/* Line 1806 of yacc.c */ - #line 80 "a.y" - { - (yyvsp[(1) - (2)].sym)->type = LLAB; -@@ -1702,6 +1751,8 @@ - break; - - case 12: -+ -+/* Line 1806 of yacc.c */ - #line 91 "a.y" - { - (yyvsp[(1) - (3)].sym)->type = LVAR; -@@ -1710,6 +1761,8 @@ - break; - - case 13: -+ -+/* Line 1806 of yacc.c */ - #line 96 "a.y" - { - if((yyvsp[(1) - (3)].sym)->value != (yyvsp[(3) - (3)].lval)) -@@ -1719,91 +1772,127 @@ - break; - - case 14: -+ -+/* Line 1806 of yacc.c */ - #line 101 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 15: -+ -+/* Line 1806 of yacc.c */ - #line 102 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 16: -+ -+/* Line 1806 of yacc.c */ - #line 103 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 17: -+ -+/* Line 1806 of yacc.c */ - #line 104 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 18: -+ -+/* Line 1806 of yacc.c */ - #line 105 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 19: -+ -+/* Line 1806 of yacc.c */ - #line 106 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 20: -+ -+/* Line 1806 of yacc.c */ - #line 107 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 21: -+ -+/* Line 1806 of yacc.c */ - #line 108 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 22: -+ -+/* Line 1806 of yacc.c */ - #line 109 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 23: -+ -+/* Line 1806 of yacc.c */ - #line 110 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 24: -+ -+/* Line 1806 of yacc.c */ - #line 111 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 25: -+ -+/* Line 1806 of yacc.c */ - #line 112 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 26: -+ -+/* Line 1806 of yacc.c */ - #line 113 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 27: -+ -+/* Line 1806 of yacc.c */ - #line 114 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 28: -+ -+/* Line 1806 of yacc.c */ - #line 115 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 29: -+ -+/* Line 1806 of yacc.c */ - #line 116 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 30: -+ -+/* Line 1806 of yacc.c */ - #line 117 "a.y" - { outcode((yyvsp[(1) - (2)].lval), &(yyvsp[(2) - (2)].gen2)); } - break; - - case 31: -+ -+/* Line 1806 of yacc.c */ - #line 120 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1812,6 +1901,8 @@ - break; - - case 32: -+ -+/* Line 1806 of yacc.c */ - #line 125 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1820,6 +1911,8 @@ - break; - - case 33: -+ -+/* Line 1806 of yacc.c */ - #line 132 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -1828,6 +1921,8 @@ - break; - - case 34: -+ -+/* Line 1806 of yacc.c */ - #line 139 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -1836,6 +1931,8 @@ - break; - - case 35: -+ -+/* Line 1806 of yacc.c */ - #line 146 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (2)].gen); -@@ -1844,6 +1941,8 @@ - break; - - case 36: -+ -+/* Line 1806 of yacc.c */ - #line 151 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (1)].gen); -@@ -1852,6 +1951,8 @@ - break; - - case 37: -+ -+/* Line 1806 of yacc.c */ - #line 158 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1860,6 +1961,8 @@ - break; - - case 38: -+ -+/* Line 1806 of yacc.c */ - #line 163 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1868,6 +1971,8 @@ - break; - - case 39: -+ -+/* Line 1806 of yacc.c */ - #line 170 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1876,6 +1981,8 @@ - break; - - case 40: -+ -+/* Line 1806 of yacc.c */ - #line 175 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1884,6 +1991,8 @@ - break; - - case 41: -+ -+/* Line 1806 of yacc.c */ - #line 180 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -1892,6 +2001,8 @@ - break; - - case 42: -+ -+/* Line 1806 of yacc.c */ - #line 187 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (5)].gen); -@@ -1901,6 +2012,8 @@ - break; - - case 43: -+ -+/* Line 1806 of yacc.c */ - #line 195 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -1909,6 +2022,8 @@ - break; - - case 44: -+ -+/* Line 1806 of yacc.c */ - #line 200 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (5)].gen); -@@ -1918,6 +2033,8 @@ - break; - - case 45: -+ -+/* Line 1806 of yacc.c */ - #line 208 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1926,6 +2043,8 @@ - break; - - case 46: -+ -+/* Line 1806 of yacc.c */ - #line 213 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -1934,6 +2053,8 @@ - break; - - case 49: -+ -+/* Line 1806 of yacc.c */ - #line 224 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -1942,6 +2063,8 @@ - break; - - case 50: -+ -+/* Line 1806 of yacc.c */ - #line 229 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (5)].gen); -@@ -1953,6 +2076,8 @@ - break; - - case 51: -+ -+/* Line 1806 of yacc.c */ - #line 239 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -1961,6 +2086,8 @@ - break; - - case 52: -+ -+/* Line 1806 of yacc.c */ - #line 244 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (5)].gen); -@@ -1972,6 +2099,8 @@ - break; - - case 53: -+ -+/* Line 1806 of yacc.c */ - #line 254 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (2)].gen); -@@ -1980,6 +2109,8 @@ - break; - - case 54: -+ -+/* Line 1806 of yacc.c */ - #line 259 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (1)].gen); -@@ -1988,6 +2119,8 @@ - break; - - case 55: -+ -+/* Line 1806 of yacc.c */ - #line 264 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -1996,6 +2129,8 @@ - break; - - case 56: -+ -+/* Line 1806 of yacc.c */ - #line 271 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (5)].gen); -@@ -2005,6 +2140,8 @@ - break; - - case 57: -+ -+/* Line 1806 of yacc.c */ - #line 279 "a.y" - { - (yyval.gen2).from = (yyvsp[(3) - (5)].gen); -@@ -2016,6 +2153,8 @@ - break; - - case 58: -+ -+/* Line 1806 of yacc.c */ - #line 288 "a.y" - { - (yyval.gen2).from = nullgen; -@@ -2024,6 +2163,8 @@ - break; - - case 59: -+ -+/* Line 1806 of yacc.c */ - #line 293 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (1)].gen); -@@ -2032,6 +2173,8 @@ - break; - - case 60: -+ -+/* Line 1806 of yacc.c */ - #line 300 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (3)].gen); -@@ -2040,6 +2183,8 @@ - break; - - case 61: -+ -+/* Line 1806 of yacc.c */ - #line 305 "a.y" - { - (yyval.gen2).from = (yyvsp[(1) - (5)].gen); -@@ -2049,6 +2194,8 @@ - break; - - case 66: -+ -+/* Line 1806 of yacc.c */ - #line 319 "a.y" - { - (yyval.gen) = (yyvsp[(2) - (2)].gen); -@@ -2056,6 +2203,8 @@ - break; - - case 67: -+ -+/* Line 1806 of yacc.c */ - #line 323 "a.y" - { - (yyval.gen) = (yyvsp[(2) - (2)].gen); -@@ -2063,6 +2212,8 @@ - break; - - case 72: -+ -+/* Line 1806 of yacc.c */ - #line 335 "a.y" - { - (yyval.gen) = nullgen; -@@ -2072,6 +2223,8 @@ - break; - - case 73: -+ -+/* Line 1806 of yacc.c */ - #line 341 "a.y" - { - (yyval.gen) = nullgen; -@@ -2084,6 +2237,8 @@ - break; - - case 74: -+ -+/* Line 1806 of yacc.c */ - #line 350 "a.y" - { - (yyval.gen) = nullgen; -@@ -2094,6 +2249,8 @@ - break; - - case 75: -+ -+/* Line 1806 of yacc.c */ - #line 359 "a.y" - { - (yyval.gen) = nullgen; -@@ -2102,6 +2259,8 @@ - break; - - case 76: -+ -+/* Line 1806 of yacc.c */ - #line 364 "a.y" - { - (yyval.gen) = nullgen; -@@ -2110,6 +2269,8 @@ - break; - - case 77: -+ -+/* Line 1806 of yacc.c */ - #line 369 "a.y" - { - (yyval.gen) = nullgen; -@@ -2118,6 +2279,8 @@ - break; - - case 78: -+ -+/* Line 1806 of yacc.c */ - #line 374 "a.y" - { - (yyval.gen) = nullgen; -@@ -2126,6 +2289,8 @@ - break; - - case 79: -+ -+/* Line 1806 of yacc.c */ - #line 379 "a.y" - { - (yyval.gen) = nullgen; -@@ -2134,6 +2299,8 @@ - break; - - case 80: -+ -+/* Line 1806 of yacc.c */ - #line 384 "a.y" - { - (yyval.gen) = nullgen; -@@ -2142,6 +2309,8 @@ - break; - - case 81: -+ -+/* Line 1806 of yacc.c */ - #line 389 "a.y" - { - (yyval.gen) = nullgen; -@@ -2150,6 +2319,8 @@ - break; - - case 82: -+ -+/* Line 1806 of yacc.c */ - #line 395 "a.y" - { - (yyval.gen) = nullgen; -@@ -2159,6 +2330,8 @@ - break; - - case 83: -+ -+/* Line 1806 of yacc.c */ - #line 403 "a.y" - { - (yyval.gen) = nullgen; -@@ -2168,6 +2341,8 @@ - break; - - case 84: -+ -+/* Line 1806 of yacc.c */ - #line 409 "a.y" - { - (yyval.gen) = (yyvsp[(2) - (2)].gen); -@@ -2182,6 +2357,8 @@ - break; - - case 85: -+ -+/* Line 1806 of yacc.c */ - #line 420 "a.y" - { - (yyval.gen) = nullgen; -@@ -2191,6 +2368,8 @@ - break; - - case 86: -+ -+/* Line 1806 of yacc.c */ - #line 426 "a.y" - { - (yyval.gen) = nullgen; -@@ -2200,6 +2379,8 @@ - break; - - case 87: -+ -+/* Line 1806 of yacc.c */ - #line 432 "a.y" - { - (yyval.gen) = nullgen; -@@ -2209,6 +2390,8 @@ - break; - - case 88: -+ -+/* Line 1806 of yacc.c */ - #line 438 "a.y" - { - (yyval.gen) = nullgen; -@@ -2218,6 +2401,8 @@ - break; - - case 89: -+ -+/* Line 1806 of yacc.c */ - #line 444 "a.y" - { - (yyval.gen) = nullgen; -@@ -2227,6 +2412,8 @@ - break; - - case 92: -+ -+/* Line 1806 of yacc.c */ - #line 456 "a.y" - { - (yyval.gen) = nullgen; -@@ -2236,6 +2423,8 @@ - break; - - case 93: -+ -+/* Line 1806 of yacc.c */ - #line 462 "a.y" - { - (yyval.gen) = nullgen; -@@ -2245,6 +2434,8 @@ - break; - - case 94: -+ -+/* Line 1806 of yacc.c */ - #line 468 "a.y" - { - (yyval.gen) = nullgen; -@@ -2254,6 +2445,8 @@ - break; - - case 95: -+ -+/* Line 1806 of yacc.c */ - #line 474 "a.y" - { - (yyval.gen) = nullgen; -@@ -2263,6 +2456,8 @@ - break; - - case 96: -+ -+/* Line 1806 of yacc.c */ - #line 480 "a.y" - { - (yyval.gen) = nullgen; -@@ -2275,6 +2470,8 @@ - break; - - case 97: -+ -+/* Line 1806 of yacc.c */ - #line 489 "a.y" - { - (yyval.gen) = nullgen; -@@ -2287,23 +2484,43 @@ - break; - - case 98: -+ -+/* Line 1806 of yacc.c */ - #line 498 "a.y" - { - (yyval.gen) = nullgen; -+ (yyval.gen).type = D_INDIR+(yyvsp[(3) - (9)].lval); -+ (yyval.gen).offset = (yyvsp[(1) - (9)].lval); -+ (yyval.gen).index = (yyvsp[(6) - (9)].lval); -+ (yyval.gen).scale = (yyvsp[(8) - (9)].lval); -+ checkscale((yyval.gen).scale); -+ } -+ break; -+ -+ case 99: -+ -+/* Line 1806 of yacc.c */ -+#line 507 "a.y" -+ { -+ (yyval.gen) = nullgen; - (yyval.gen).type = D_INDIR+(yyvsp[(2) - (3)].lval); - } - break; - -- case 99: --#line 503 "a.y" -+ case 100: -+ -+/* Line 1806 of yacc.c */ -+#line 512 "a.y" - { - (yyval.gen) = nullgen; - (yyval.gen).type = D_INDIR+D_SP; - } - break; - -- case 100: --#line 508 "a.y" -+ case 101: -+ -+/* Line 1806 of yacc.c */ -+#line 517 "a.y" - { - (yyval.gen) = nullgen; - (yyval.gen).type = D_INDIR+D_NONE; -@@ -2313,8 +2530,10 @@ - } - break; - -- case 101: --#line 516 "a.y" -+ case 102: -+ -+/* Line 1806 of yacc.c */ -+#line 525 "a.y" - { - (yyval.gen) = nullgen; - (yyval.gen).type = D_INDIR+(yyvsp[(2) - (8)].lval); -@@ -2324,15 +2543,19 @@ - } - break; - -- case 102: --#line 526 "a.y" -+ case 103: -+ -+/* Line 1806 of yacc.c */ -+#line 535 "a.y" - { - (yyval.gen) = (yyvsp[(1) - (1)].gen); - } - break; - -- case 103: --#line 530 "a.y" -+ case 104: -+ -+/* Line 1806 of yacc.c */ -+#line 539 "a.y" - { - (yyval.gen) = (yyvsp[(1) - (6)].gen); - (yyval.gen).index = (yyvsp[(3) - (6)].lval); -@@ -2341,8 +2564,10 @@ - } - break; - -- case 104: --#line 539 "a.y" -+ case 105: -+ -+/* Line 1806 of yacc.c */ -+#line 548 "a.y" - { - (yyval.gen) = nullgen; - (yyval.gen).type = (yyvsp[(4) - (5)].lval); -@@ -2351,8 +2576,10 @@ - } - break; - -- case 105: --#line 546 "a.y" -+ case 106: -+ -+/* Line 1806 of yacc.c */ -+#line 555 "a.y" - { - (yyval.gen) = nullgen; - (yyval.gen).type = D_STATIC; -@@ -2361,174 +2588,232 @@ - } - break; - -- case 106: --#line 554 "a.y" -+ case 107: -+ -+/* Line 1806 of yacc.c */ -+#line 563 "a.y" - { - (yyval.lval) = 0; - } - break; - -- case 107: --#line 558 "a.y" -+ case 108: -+ -+/* Line 1806 of yacc.c */ -+#line 567 "a.y" - { - (yyval.lval) = (yyvsp[(2) - (2)].lval); - } - break; - -- case 108: --#line 562 "a.y" -+ case 109: -+ -+/* Line 1806 of yacc.c */ -+#line 571 "a.y" - { - (yyval.lval) = -(yyvsp[(2) - (2)].lval); - } - break; - -- case 110: --#line 569 "a.y" -+ case 111: -+ -+/* Line 1806 of yacc.c */ -+#line 578 "a.y" - { - (yyval.lval) = D_AUTO; - } - break; - -- case 113: --#line 577 "a.y" -+ case 114: -+ -+/* Line 1806 of yacc.c */ -+#line 586 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (1)].sym)->value; - } - break; - -- case 114: --#line 581 "a.y" -+ case 115: -+ -+/* Line 1806 of yacc.c */ -+#line 590 "a.y" - { - (yyval.lval) = -(yyvsp[(2) - (2)].lval); - } - break; - -- case 115: --#line 585 "a.y" -+ case 116: -+ -+/* Line 1806 of yacc.c */ -+#line 594 "a.y" - { - (yyval.lval) = (yyvsp[(2) - (2)].lval); - } - break; - -- case 116: --#line 589 "a.y" -+ case 117: -+ -+/* Line 1806 of yacc.c */ -+#line 598 "a.y" - { - (yyval.lval) = ~(yyvsp[(2) - (2)].lval); - } - break; - -- case 117: --#line 593 "a.y" -+ case 118: -+ -+/* Line 1806 of yacc.c */ -+#line 602 "a.y" - { - (yyval.lval) = (yyvsp[(2) - (3)].lval); - } - break; - -- case 118: --#line 599 "a.y" -+ case 119: -+ -+/* Line 1806 of yacc.c */ -+#line 608 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (1)].lval) & 0xffffffffLL; - } - break; - -- case 119: --#line 603 "a.y" -+ case 120: -+ -+/* Line 1806 of yacc.c */ -+#line 612 "a.y" - { - (yyval.lval) = -(yyvsp[(2) - (2)].lval) & 0xffffffffLL; - } - break; - -- case 120: --#line 607 "a.y" -+ case 121: -+ -+/* Line 1806 of yacc.c */ -+#line 616 "a.y" - { - (yyval.lval) = ((yyvsp[(1) - (3)].lval) & 0xffffffffLL) + - (((yyvsp[(3) - (3)].lval) & 0xffffLL) << 32); - } - break; - -- case 121: --#line 612 "a.y" -+ case 122: -+ -+/* Line 1806 of yacc.c */ -+#line 621 "a.y" - { - (yyval.lval) = (-(yyvsp[(2) - (4)].lval) & 0xffffffffLL) + - (((yyvsp[(4) - (4)].lval) & 0xffffLL) << 32); - } - break; - -- case 123: --#line 620 "a.y" -+ case 124: -+ -+/* Line 1806 of yacc.c */ -+#line 629 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) + (yyvsp[(3) - (3)].lval); - } - break; - -- case 124: --#line 624 "a.y" -+ case 125: -+ -+/* Line 1806 of yacc.c */ -+#line 633 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) - (yyvsp[(3) - (3)].lval); - } - break; - -- case 125: --#line 628 "a.y" -+ case 126: -+ -+/* Line 1806 of yacc.c */ -+#line 637 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) * (yyvsp[(3) - (3)].lval); - } - break; - -- case 126: --#line 632 "a.y" -+ case 127: -+ -+/* Line 1806 of yacc.c */ -+#line 641 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) / (yyvsp[(3) - (3)].lval); - } - break; - -- case 127: --#line 636 "a.y" -+ case 128: -+ -+/* Line 1806 of yacc.c */ -+#line 645 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) % (yyvsp[(3) - (3)].lval); - } - break; - -- case 128: --#line 640 "a.y" -+ case 129: -+ -+/* Line 1806 of yacc.c */ -+#line 649 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (4)].lval) << (yyvsp[(4) - (4)].lval); - } - break; - -- case 129: --#line 644 "a.y" -+ case 130: -+ -+/* Line 1806 of yacc.c */ -+#line 653 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (4)].lval) >> (yyvsp[(4) - (4)].lval); - } - break; - -- case 130: --#line 648 "a.y" -+ case 131: -+ -+/* Line 1806 of yacc.c */ -+#line 657 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) & (yyvsp[(3) - (3)].lval); - } - break; - -- case 131: --#line 652 "a.y" -+ case 132: -+ -+/* Line 1806 of yacc.c */ -+#line 661 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) ^ (yyvsp[(3) - (3)].lval); - } - break; - -- case 132: --#line 656 "a.y" -+ case 133: -+ -+/* Line 1806 of yacc.c */ -+#line 665 "a.y" - { - (yyval.lval) = (yyvsp[(1) - (3)].lval) | (yyvsp[(3) - (3)].lval); - } - break; - - --/* Line 1267 of yacc.c. */ --#line 2530 "y.tab.c" -+ -+/* Line 1806 of yacc.c */ -+#line 2804 "y.tab.c" - default: break; - } -+ /* User semantic actions sometimes alter yychar, and that requires -+ that yytoken be updated with the new translation. We take the -+ approach of translating immediately before every use of yytoken. -+ One alternative is translating here after every semantic action, -+ but that translation would be missed if the semantic action invokes -+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or -+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an -+ incorrect destructor might then be invoked immediately. In the -+ case of YYERROR or YYBACKUP, subsequent parser actions might lead -+ to an incorrect destructor call or verbose syntax error message -+ before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); - - YYPOPSTACK (yylen); -@@ -2537,7 +2822,6 @@ - - *++yyvsp = yyval; - -- - /* Now `shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ -@@ -2557,6 +2841,10 @@ - | yyerrlab -- here on detecting error | - `------------------------------------*/ - yyerrlab: -+ /* Make sure we have latest lookahead translation. See comments at -+ user semantic actions for why this is necessary. */ -+ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); -+ - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { -@@ -2564,37 +2852,36 @@ - #if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); - #else -+# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ -+ yyssp, yytoken) - { -- YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); -- if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) -- { -- YYSIZE_T yyalloc = 2 * yysize; -- if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) -- yyalloc = YYSTACK_ALLOC_MAXIMUM; -- if (yymsg != yymsgbuf) -- YYSTACK_FREE (yymsg); -- yymsg = (char *) YYSTACK_ALLOC (yyalloc); -- if (yymsg) -- yymsg_alloc = yyalloc; -- else -- { -- yymsg = yymsgbuf; -- yymsg_alloc = sizeof yymsgbuf; -- } -- } -- -- if (0 < yysize && yysize <= yymsg_alloc) -- { -- (void) yysyntax_error (yymsg, yystate, yychar); -- yyerror (yymsg); -- } -- else -- { -- yyerror (YY_("syntax error")); -- if (yysize != 0) -- goto yyexhaustedlab; -- } -+ char const *yymsgp = YY_("syntax error"); -+ int yysyntax_error_status; -+ yysyntax_error_status = YYSYNTAX_ERROR; -+ if (yysyntax_error_status == 0) -+ yymsgp = yymsg; -+ else if (yysyntax_error_status == 1) -+ { -+ if (yymsg != yymsgbuf) -+ YYSTACK_FREE (yymsg); -+ yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); -+ if (!yymsg) -+ { -+ yymsg = yymsgbuf; -+ yymsg_alloc = sizeof yymsgbuf; -+ yysyntax_error_status = 2; -+ } -+ else -+ { -+ yysyntax_error_status = YYSYNTAX_ERROR; -+ yymsgp = yymsg; -+ } -+ } -+ yyerror (yymsgp); -+ if (yysyntax_error_status == 2) -+ goto yyexhaustedlab; - } -+# undef YYSYNTAX_ERROR - #endif - } - -@@ -2602,7 +2889,7 @@ - - if (yyerrstatus == 3) - { -- /* If just tried and failed to reuse look-ahead token after an -+ /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) -@@ -2619,7 +2906,7 @@ - } - } - -- /* Else will try to reuse look-ahead token after shifting the error -+ /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - -@@ -2653,7 +2940,7 @@ - for (;;) - { - yyn = yypact[yystate]; -- if (yyn != YYPACT_NINF) -+ if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) -@@ -2676,9 +2963,6 @@ - YY_STACK_PRINT (yyss, yyssp); - } - -- if (yyn == YYFINAL) -- YYACCEPT; -- - *++yyvsp = yylval; - - -@@ -2703,7 +2987,7 @@ - yyresult = 1; - goto yyreturn; - --#ifndef yyoverflow -+#if !defined(yyoverflow) || YYERROR_VERBOSE - /*-------------------------------------------------. - | yyexhaustedlab -- memory exhaustion comes here. | - `-------------------------------------------------*/ -@@ -2714,9 +2998,14 @@ - #endif - - yyreturn: -- if (yychar != YYEOF && yychar != YYEMPTY) -- yydestruct ("Cleanup: discarding lookahead", -- yytoken, &yylval); -+ if (yychar != YYEMPTY) -+ { -+ /* Make sure we have latest lookahead translation. See comments at -+ user semantic actions for why this is necessary. */ -+ yytoken = YYTRANSLATE (yychar); -+ yydestruct ("Cleanup: discarding lookahead", -+ yytoken, &yylval); -+ } - /* Do not reclaim the symbols of the rule which action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); -diff -r 5f1bc87f81de src/cmd/6a/y.tab.h ---- a/src/cmd/6a/y.tab.h Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6a/y.tab.h Thu Jun 27 16:06:56 2013 +0200 -@@ -1,24 +1,21 @@ --/* A Bison parser, made by GNU Bison 2.3. */ -+/* A Bison parser, made by GNU Bison 2.5. */ - --/* Skeleton interface for Bison's Yacc-like parsers in C -- -- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 -- Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -+/* Bison interface for Yacc-like parsers in C -+ -+ Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. -+ -+ This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2, or (at your option) -- any later version. -- -+ the Free Software Foundation, either version 3 of the License, or -+ (at your option) any later version. -+ - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. -- -+ - You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, -- Boston, MA 02110-1301, USA. */ -+ along with this program. If not, see . */ - - /* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work -@@ -29,10 +26,11 @@ - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. -- -+ - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -+ - /* Tokens. */ - #ifndef YYTOKENTYPE - # define YYTOKENTYPE -@@ -114,22 +112,28 @@ - - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - typedef union YYSTYPE -+{ -+ -+/* Line 2068 of yacc.c */ - #line 37 "a.y" --{ -+ - Sym *sym; - vlong lval; - double dval; - char sval[8]; - Gen gen; - Gen2 gen2; --} --/* Line 1529 of yacc.c. */ --#line 128 "y.tab.h" -- YYSTYPE; -+ -+ -+ -+/* Line 2068 of yacc.c */ -+#line 131 "y.tab.h" -+} YYSTYPE; -+# define YYSTYPE_IS_TRIVIAL 1 - # define yystype YYSTYPE /* obsolescent; will be withdrawn */ - # define YYSTYPE_IS_DECLARED 1 --# define YYSTYPE_IS_TRIVIAL 1 - #endif - - extern YYSTYPE yylval; - -+ -diff -r 5f1bc87f81de src/cmd/6l/asm.c ---- a/src/cmd/6l/asm.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6l/asm.c Thu Jun 27 16:06:56 2013 +0200 -@@ -99,12 +99,6 @@ - static void addpltsym(Sym*); - static void addgotsym(Sym*); - --Sym * --lookuprel(void) --{ -- return lookup(".rela", 0); --} -- - void - adddynrela(Sym *rela, Sym *s, Reloc *r) - { -@@ -312,9 +306,12 @@ - break; - - case D_TLS: -- if(r->siz == 4) -- VPUT(R_X86_64_TPOFF32 | (uint64)elfsym<<32); -- else -+ if(r->siz == 4) { -+ if(flag_shared) -+ VPUT(R_X86_64_GOTTPOFF | (uint64)elfsym<<32); -+ else -+ VPUT(R_X86_64_TPOFF32 | (uint64)elfsym<<32); -+ } else - return -1; - break; - } -diff -r 5f1bc87f81de src/cmd/6l/l.h ---- a/src/cmd/6l/l.h Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6l/l.h Thu Jun 27 16:06:56 2013 +0200 -@@ -189,7 +189,6 @@ - Reloc* r; - int32 nr; - int32 maxr; -- int rel_ro; - }; - struct Optab - { -@@ -331,7 +330,6 @@ - EXTERN int64 INITTEXT; - EXTERN int64 INITDAT; - EXTERN char* INITENTRY; /* entry point */ --EXTERN char* LIBINITENTRY; /* shared library entry point */ - EXTERN char* pcstr; - EXTERN Auto* curauto; - EXTERN Auto* curhist; -diff -r 5f1bc87f81de src/cmd/6l/obj.c ---- a/src/cmd/6l/obj.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6l/obj.c Thu Jun 27 16:06:56 2013 +0200 -@@ -82,7 +82,6 @@ - INITDAT = -1; - INITRND = -1; - INITENTRY = 0; -- LIBINITENTRY = 0; - linkmode = LinkAuto; - nuxiinit(); - -@@ -119,7 +118,7 @@ - flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); - flagcount("race", "enable race detector", &flag_race); - flagcount("s", "disable symbol table", &debug['s']); -- flagcount("shared", "generate shared object", &flag_shared); -+ flagcount("shared", "generate shared object (implies -linkmode external)", &flag_shared); - flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); - flagcount("u", "reject unsafe packages", &debug['u']); - flagcount("v", "print link trace", &debug['v']); -@@ -140,6 +139,9 @@ - if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0) - linkmode = LinkInternal; - -+ if(flag_shared) -+ linkmode = LinkExternal; -+ - switch(HEADTYPE) { - default: - if(linkmode == LinkAuto) -@@ -365,7 +367,7 @@ - adrgotype = zsym(pn, f, h); - s = a->sym; - t = a->type; -- if(t == D_INDIR+D_GS) -+ if(t == D_INDIR+D_GS || a->index == D_GS) - a->offset += tlsoffset; - if(t != D_AUTO && t != D_PARAM) { - if(s && adrgotype) -diff -r 5f1bc87f81de src/cmd/6l/pass.c ---- a/src/cmd/6l/pass.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6l/pass.c Thu Jun 27 16:06:56 2013 +0200 -@@ -271,7 +271,7 @@ - { - int32 c; - Prog *p, *q; -- Sym *s; -+ Sym *s, *gmsym; - int32 vexit; - - if(debug['v']) -@@ -282,6 +282,17 @@ - Bprint(&bso, "%5.2f patch\n", cputime()); - Bflush(&bso); - -+ if(flag_shared) { -+ s = lookup("init_array", 0); -+ s->type = SINITARR; -+ s->reachable = 1; -+ s->hide = 1; -+ addaddr(s, lookup(INITENTRY, 0)); -+ } -+ -+ gmsym = lookup("runtime.tlsgm", 0); -+ if(linkmode != LinkExternal) -+ gmsym->reachable = 0; - s = lookup("exit", 0); - vexit = s->value; - for(cursym = textp; cursym != nil; cursym = cursym->next) -@@ -317,6 +328,59 @@ - p->from.type = D_INDIR+D_FS; - if(p->to.type == D_INDIR+D_GS) - p->to.type = D_INDIR+D_FS; -+ if(p->from.index == D_GS) -+ p->from.index = D_FS; -+ if(p->to.index == D_GS) -+ p->to.index = D_FS; -+ if(!flag_shared) { -+ // Convert g() or m() accesses of the form -+ // op n(reg)(GS*1), reg -+ // to -+ // op n(GS*1), reg -+ if(p->from.index == D_FS) { -+ p->from.index = D_NONE; -+ p->from.type = D_INDIR + D_FS; -+ } -+ // Convert g() or m() accesses of the form -+ // op reg, n(reg)(GS*1) -+ // to -+ // op reg, n(GS*1) -+ if(p->to.index == D_FS) { -+ p->to.index = D_NONE; -+ p->to.type = D_INDIR + D_FS; -+ } -+ // Convert get_tls access of the form -+ // op runtime.tlsgm(SB), reg -+ // to -+ // NOP -+ if(gmsym != S && p->from.sym == gmsym) { -+ p->as = ANOP; -+ p->from.type = D_NONE; -+ p->to.type = D_NONE; -+ p->from.sym = nil; -+ p->to.sym = nil; -+ continue; -+ } -+ } else { -+ // Convert TLS reads of the form -+ // op n(GS), reg -+ // to -+ // MOVQ $runtime.tlsgm(SB), reg -+ // op n(reg)(GS*1), reg -+ if(p->from.type == D_INDIR+D_FS && p->to.type >= D_AX && p->to.type <= D_DI) { -+ q = appendp(p); -+ q->to = p->to; -+ q->as = p->as; -+ q->from.type = D_INDIR+p->to.type; -+ q->from.index = D_FS; -+ q->from.scale = 1; -+ q->from.offset = p->from.offset; -+ p->as = AMOVQ; -+ p->from.type = D_EXTERN; -+ p->from.sym = gmsym; -+ p->from.offset = 0; -+ } -+ } - } - if(p->as == ACALL || (p->as == AJMP && p->to.type != D_BRANCH) || (p->as == ARET && p->to.sym != nil)) { - s = p->to.sym; -@@ -411,7 +475,10 @@ - int32 autoffset, deltasp; - int a, pcsize; - uint32 moreconst1, moreconst2, i; -+ Sym *gmsym; - -+ -+ gmsym = lookup("runtime.tlsgm", 0); - for(i=0; itype != STEXT) -@@ -442,6 +509,14 @@ - diag("nosplit func likely to overflow stack"); - - if(!(p->from.scale & NOSPLIT)) { -+ if(flag_shared) { -+ // Load TLS offset with MOVQ $runtime.tlsgm(SB), CX -+ p = appendp(p); -+ p->as = AMOVQ; -+ p->from.type = D_EXTERN; -+ p->from.sym = gmsym; -+ p->to.type = D_CX; -+ } - p = appendp(p); // load g into CX - p->as = AMOVQ; - if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd -@@ -450,6 +525,11 @@ - p->from.type = D_INDIR+D_FS; - else - p->from.type = D_INDIR+D_GS; -+ if(flag_shared) { -+ // Add TLS offset stored in CX -+ p->from.index = p->from.type - D_INDIR; -+ p->from.type = D_INDIR + D_CX; -+ } - p->from.offset = tlsoffset+0; - p->to.type = D_CX; - if(HEADTYPE == Hwindows) { -diff -r 5f1bc87f81de src/cmd/6l/span.c ---- a/src/cmd/6l/span.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/6l/span.c Thu Jun 27 16:06:56 2013 +0200 -@@ -358,6 +358,18 @@ - case D_INDIR+D_GS: - return 0x65; - } -+ switch(a->index) { -+ case D_CS: -+ return 0x2e; -+ case D_DS: -+ return 0x3e; -+ case D_ES: -+ return 0x26; -+ case D_FS: -+ return 0x64; -+ case D_GS: -+ return 0x65; -+ } - return 0; - } - -@@ -735,15 +747,20 @@ - diag("need reloc for %D", a); - errorexit(); - } -- if(flag_shared) -- r->type = D_PCREL; -- else -- r->type = D_ADDR; - r->siz = 4; // TODO: 8 for external symbols - r->off = -1; // caller must fill in - r->sym = s; - r->add = v; - v = 0; -+ if(flag_shared) { -+ if(s->type == STLSBSS) { -+ r->xadd = r->add - r->siz; -+ r->type = D_TLS; -+ r->xsym = s; -+ } else -+ r->type = D_PCREL; -+ } else -+ r->type = D_ADDR; - } - return v; - } -@@ -760,7 +777,7 @@ - v = a->offset; - t = a->type; - rel.siz = 0; -- if(a->index != D_NONE) { -+ if(a->index != D_NONE && a->index != D_FS && a->index != D_GS) { - if(t < D_INDIR) { - switch(t) { - default: -diff -r 5f1bc87f81de src/cmd/8l/asm.c ---- a/src/cmd/8l/asm.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/8l/asm.c Thu Jun 27 16:06:56 2013 +0200 -@@ -95,12 +95,6 @@ - static void addpltsym(Sym*); - static void addgotsym(Sym*); - --Sym * --lookuprel(void) --{ -- return lookup(".rel", 0); --} -- - void - adddynrela(Sym *rela, Sym *s, Reloc *r) - { -diff -r 5f1bc87f81de src/cmd/8l/l.h ---- a/src/cmd/8l/l.h Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/8l/l.h Thu Jun 27 16:06:56 2013 +0200 -@@ -171,7 +171,6 @@ - Reloc* r; - int32 nr; - int32 maxr; -- int rel_ro; - }; - struct Optab - { -@@ -287,7 +286,6 @@ - EXTERN int32 INITTEXT; - EXTERN int32 INITDAT; - EXTERN char* INITENTRY; /* entry point */ --EXTERN char* LIBINITENTRY; /* shared library entry point */ - EXTERN char* pcstr; - EXTERN Auto* curauto; - EXTERN Auto* curhist; -diff -r 5f1bc87f81de src/cmd/8l/obj.c ---- a/src/cmd/8l/obj.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/8l/obj.c Thu Jun 27 16:06:56 2013 +0200 -@@ -89,7 +89,6 @@ - INITDAT = -1; - INITRND = -1; - INITENTRY = 0; -- LIBINITENTRY = 0; - linkmode = LinkAuto; - nuxiinit(); - -diff -r 5f1bc87f81de src/cmd/cgo/out.go ---- a/src/cmd/cgo/out.go Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/cgo/out.go Thu Jun 27 16:06:56 2013 +0200 -@@ -474,7 +474,7 @@ - - // Gcc wrapper unpacks the C argument struct - // and calls the actual C function. -- fmt.Fprintf(fgcc, "void\n") -+ fmt.Fprintf(fgcc, "__attribute__ ((visibility (\"hidden\"))) void\n") - fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle) - fmt.Fprintf(fgcc, "{\n") - if n.AddError { -diff -r 5f1bc87f81de src/cmd/dist/buildruntime.c ---- a/src/cmd/dist/buildruntime.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/dist/buildruntime.c Thu Jun 27 16:06:56 2013 +0200 -@@ -162,15 +162,19 @@ - "#define m(r) 8(GS)\n" - "#define procid(r) 16(GS)\n" - }, -+ // The TLS accessors here are defined here to use initial exec model. -+ // If the linker is not outputting a shared library, it will reduce -+ // the TLS accessors to the local exec model, effectively removing -+ // get_tls(). - {"amd64", "", - "// The offsets 0 and 8 are known to:\n" - "// ../../cmd/6l/pass.c:/D_GS\n" - "// cgo/gcc_linux_amd64.c:/^threadentry\n" - "// cgo/gcc_darwin_amd64.c:/^threadentry\n" - "//\n" -- "#define get_tls(r)\n" -- "#define g(r) 0(GS)\n" -- "#define m(r) 8(GS)\n" -+ "#define get_tls(r) MOVQ runtime·tlsgm(SB), r\n" -+ "#define g(r) 0(r)(GS*1)\n" -+ "#define m(r) 8(r)(GS*1)\n" - }, - - {"arm", "", -diff -r 5f1bc87f81de src/cmd/ld/data.c ---- a/src/cmd/ld/data.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/ld/data.c Thu Jun 27 16:06:56 2013 +0200 -@@ -307,8 +307,6 @@ - dynrelocsym(Sym *s) - { - Reloc *r; -- Sym *rel; -- Sym *got; - - if(HEADTYPE == Hwindows) { - Sym *rel, *targ; -@@ -345,22 +343,9 @@ - return; - } - -- got = rel = nil; -- if(flag_shared) { -- rel = lookuprel(); -- got = lookup(".got", 0); -- } -- s->rel_ro = 0; - for(r=s->r; rr+s->nr; r++) { - if(r->sym != S && r->sym->type == SDYNIMPORT || r->type >= 256) - adddynrel(s, r); -- if(flag_shared && r->sym != S && s->type != SDYNIMPORT && r->type == D_ADDR -- && (s == got || s->type == SDATA || s->type == SGOSTRING || s->type == STYPE || s->type == SRODATA)) { -- // Create address based RELATIVE relocation -- adddynrela(rel, s, r); -- if(s->type < SNOPTRDATA) -- s->rel_ro = 1; -- } - } - } - -@@ -1100,12 +1085,6 @@ - } - *l = nil; - -- if(flag_shared) { -- for(s=datap; s != nil; s = s->next) { -- if(s->rel_ro) -- s->type = SDATARELRO; -- } -- } - datap = listsort(datap, datcmp, offsetof(Sym, next)); - - /* -@@ -1139,12 +1118,12 @@ - - /* pointer-free data */ - sect = addsection(&segdata, ".noptrdata", 06); -- sect->align = maxalign(s, SDATARELRO-1); -+ sect->align = maxalign(s, SINITARR-1); - datsize = rnd(datsize, sect->align); - sect->vaddr = datsize; - lookup("noptrdata", 0)->sect = sect; - lookup("enoptrdata", 0)->sect = sect; -- for(; s != nil && s->type < SDATARELRO; s = s->next) { -+ for(; s != nil && s->type < SINITARR; s = s->next) { - datsize = aligndatsize(datsize, s); - s->sect = sect; - s->type = SDATA; -@@ -1153,18 +1132,14 @@ - } - sect->len = datsize - sect->vaddr; - -- /* dynamic relocated rodata */ - if(flag_shared) { -- sect = addsection(&segdata, ".data.rel.ro", 06); -- sect->align = maxalign(s, SDATARELRO); -+ sect = addsection(&segdata, ".init_array", 06); -+ sect->align = maxalign(s, SINITARR); - datsize = rnd(datsize, sect->align); - sect->vaddr = datsize; -- lookup("datarelro", 0)->sect = sect; -- lookup("edatarelro", 0)->sect = sect; -- for(; s != nil && s->type == SDATARELRO; s = s->next) { -+ for(; s != nil && s->type == SINITARR; s = s->next) { - datsize = aligndatsize(datsize, s); - s->sect = sect; -- s->type = SDATA; - s->value = datsize; - growdatsize(&datsize, s); - } -@@ -1179,7 +1154,7 @@ - lookup("data", 0)->sect = sect; - lookup("edata", 0)->sect = sect; - for(; s != nil && s->type < SBSS; s = s->next) { -- if(s->type == SDATARELRO) { -+ if(s->type == SINITARR) { - cursym = s; - diag("unexpected symbol type %d", s->type); - } -@@ -1393,7 +1368,7 @@ - void - address(void) - { -- Section *s, *text, *data, *rodata, *symtab, *pclntab, *noptr, *bss, *noptrbss, *datarelro; -+ Section *s, *text, *data, *rodata, *symtab, *pclntab, *noptr, *bss, *noptrbss; - Section *typelink; - Sym *sym, *sub; - uvlong va; -@@ -1425,7 +1400,6 @@ - noptr = nil; - bss = nil; - noptrbss = nil; -- datarelro = nil; - for(s=segdata.sect; s != nil; s=s->next) { - vlen = s->len; - if(s->next) -@@ -1441,8 +1415,6 @@ - bss = s; - if(strcmp(s->name, ".noptrbss") == 0) - noptrbss = s; -- if(strcmp(s->name, ".data.rel.ro") == 0) -- datarelro = s; - } - segdata.filelen = bss->vaddr - segdata.vaddr; - -@@ -1468,10 +1440,6 @@ - xdefine("erodata", SRODATA, rodata->vaddr + rodata->len); - xdefine("typelink", SRODATA, typelink->vaddr); - xdefine("etypelink", SRODATA, typelink->vaddr + typelink->len); -- if(datarelro != nil) { -- xdefine("datarelro", SRODATA, datarelro->vaddr); -- xdefine("edatarelro", SRODATA, datarelro->vaddr + datarelro->len); -- } - - sym = lookup("gcdata", 0); - xdefine("egcdata", SRODATA, symaddr(sym) + sym->size); -diff -r 5f1bc87f81de src/cmd/ld/elf.c ---- a/src/cmd/ld/elf.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/ld/elf.c Thu Jun 27 16:06:56 2013 +0200 -@@ -903,8 +903,6 @@ - addstring(shstrtab, ".elfdata"); - addstring(shstrtab, ".rodata"); - addstring(shstrtab, ".typelink"); -- if(flag_shared) -- addstring(shstrtab, ".data.rel.ro"); - addstring(shstrtab, ".gosymtab"); - addstring(shstrtab, ".gopclntab"); - -@@ -934,6 +932,14 @@ - addstring(shstrtab, ".note.GNU-stack"); - } - -+ if(flag_shared) { -+ addstring(shstrtab, ".init_array"); -+ if(thechar == '6') -+ addstring(shstrtab, ".rela.init_array"); -+ else -+ addstring(shstrtab, ".rel.init_array"); -+ } -+ - if(!debug['s']) { - addstring(shstrtab, ".symtab"); - addstring(shstrtab, ".strtab"); -@@ -1062,13 +1068,6 @@ - - elfwritedynent(s, DT_DEBUG, 0); - -- if(flag_shared) { -- Sym *init_sym = lookup(LIBINITENTRY, 0); -- if(init_sym->type != STEXT) -- diag("entry not text: %s", init_sym->name); -- elfwritedynentsym(s, DT_INIT, init_sym); -- } -- - // Do not write DT_NULL. elfdynhash will finish it. - } - } -@@ -1459,9 +1458,7 @@ - eh->ident[EI_DATA] = ELFDATA2LSB; - eh->ident[EI_VERSION] = EV_CURRENT; - -- if(flag_shared) -- eh->type = ET_DYN; -- else if(linkmode == LinkExternal) -+ if(linkmode == LinkExternal) - eh->type = ET_REL; - else - eh->type = ET_EXEC; -diff -r 5f1bc87f81de src/cmd/ld/elf.h ---- a/src/cmd/ld/elf.h Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/ld/elf.h Thu Jun 27 16:06:56 2013 +0200 -@@ -569,6 +569,7 @@ - #define R_ARM_GOT_PREL 96 - #define R_ARM_GNU_VTENTRY 100 - #define R_ARM_GNU_VTINHERIT 101 -+#define R_ARM_TLS_IE32 107 - #define R_ARM_TLS_LE32 108 - #define R_ARM_RSBREL32 250 - #define R_ARM_THM_RPC22 251 -diff -r 5f1bc87f81de src/cmd/ld/go.c ---- a/src/cmd/ld/go.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/ld/go.c Thu Jun 27 16:06:56 2013 +0200 -@@ -499,6 +499,9 @@ - local = expandpkg(local, pkg); - s = lookup(local, 0); - -+ if(flag_shared && s == lookup("main", 0)) -+ continue; -+ - // export overrides import, for openbsd/cgo. - // see issue 4878. - if(s->dynimplib != nil) { -@@ -674,8 +677,6 @@ - Bprint(&bso, "%5.2f deadcode\n", cputime()); - - mark(lookup(INITENTRY, 0)); -- if(flag_shared) -- mark(lookup(LIBINITENTRY, 0)); - for(i=0; itype = SXREF; -- if(flag_shared) { -- if(LIBINITENTRY == nil) { -- LIBINITENTRY = mal(strlen(goarch)+strlen(goos)+20); -- sprint(LIBINITENTRY, "_rt0_%s_%s_lib", goarch, goos); -- } -- lookup(LIBINITENTRY, 0)->type = SXREF; -- } - } - - void -@@ -294,6 +291,12 @@ - int i, w, x; - Sym *s, *gmsym; - -+ if(flag_shared) { -+ s = lookup("runtime.islibrary", 0); -+ s->dupok = 1; -+ adduint8(s, 1); -+ } -+ - loadinternal("runtime"); - if(thechar == '5') - loadinternal("math"); -@@ -341,13 +344,15 @@ - } else - s->type = 0; - } -- } else if(linkmode == LinkExternal) { -- gmsym = lookup("runtime.tlsgm", 0); -- gmsym->type = STLSBSS; -- gmsym->size = 2*PtrSize; -- gmsym->hide = 1; -+ } -+ gmsym = lookup("runtime.tlsgm", 0); -+ gmsym->type = STLSBSS; -+ gmsym->size = 2*PtrSize; -+ gmsym->hide = 1; -+ if(linkmode == LinkExternal) - gmsym->reachable = 1; -- } -+ else -+ gmsym->reachable = 0; - - // Now that we know the link mode, trim the dynexp list. - x = CgoExportDynamic; -@@ -659,7 +664,7 @@ - p = strchr(p + 1, ' '); - } - -- argv = malloc((10+nhostobj+nldflag+c)*sizeof argv[0]); -+ argv = malloc((13+nhostobj+nldflag+c)*sizeof argv[0]); - argc = 0; - if(extld == nil) - extld = "gcc"; -@@ -682,6 +687,10 @@ - } - if(HEADTYPE == Hdarwin) - argv[argc++] = "-Wl,-no_pie,-pagezero_size,4000000"; -+ if(flag_shared) { -+ argv[argc++] = "-Wl,-Bsymbolic"; -+ argv[argc++] = "-shared"; -+ } - argv[argc++] = "-o"; - argv[argc++] = outfile; - -diff -r 5f1bc87f81de src/cmd/ld/lib.h ---- a/src/cmd/ld/lib.h Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/ld/lib.h Thu Jun 27 16:06:56 2013 +0200 -@@ -47,7 +47,7 @@ - SMACHO, /* Mach-O __nl_symbol_ptr */ - SMACHOGOT, - SNOPTRDATA, -- SDATARELRO, -+ SINITARR, - SDATA, - SWINDOWS, - SBSS, -@@ -212,7 +212,6 @@ - void usage(void); - void adddynrel(Sym*, Reloc*); - void adddynrela(Sym*, Sym*, Reloc*); --Sym* lookuprel(void); - void ldobj1(Biobuf *f, char*, int64 len, char *pn); - void ldobj(Biobuf*, char*, int64, char*, char*, int); - void ldelf(Biobuf*, char*, int64, char*); -diff -r 5f1bc87f81de src/cmd/ld/symtab.c ---- a/src/cmd/ld/symtab.c Thu Jun 27 12:17:26 2013 +0200 -+++ b/src/cmd/ld/symtab.c Thu Jun 27 16:06:56 2013 +0200 -@@ -468,10 +468,6 @@ - xdefine("etypelink", SRODATA, 0); - xdefine("rodata", SRODATA, 0); - xdefine("erodata", SRODATA, 0); -- if(flag_shared) { -- xdefine("datarelro", SDATARELRO, 0); -- xdefine("edatarelro", SDATARELRO, 0); -- } - xdefine("noptrdata", SNOPTRDATA, 0); - xdefine("enoptrdata", SNOPTRDATA, 0); - xdefine("data", SDATA, 0); diff --git a/patches/shared-lib-runtime b/patches/shared-lib-runtime index ba4e186..aef1280 100644 --- a/patches/shared-lib-runtime +++ b/patches/shared-lib-runtime @@ -1,5 +1,5 @@ # HG changeset patch -# Parent 70734d763b860585b8b80371d1c67b6533986cc6 +# Parent 84975e4930dd0f5a08101f6af726477279f7192c diff --git a/misc/cgo/testshared/main.c b/misc/cgo/testshared/main.c new file mode 100644 @@ -224,22 +224,34 @@ new file mode 100755 + exit 1; +fi +rm -rf $dylib $dylib2 mainmult main mainadv *.dSYM +diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go +--- a/src/cmd/cgo/out.go ++++ b/src/cmd/cgo/out.go +@@ -512,7 +512,7 @@ + + // Gcc wrapper unpacks the C argument struct + // and calls the actual C function. +- fmt.Fprintf(fgcc, "void\n") ++ fmt.Fprintf(fgcc, "__attribute__ ((visibility (\"hidden\"))) void\n") + fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle) + fmt.Fprintf(fgcc, "{\n") + if n.AddError { diff --git a/src/pkg/runtime/asm_386.s b/src/pkg/runtime/asm_386.s --- a/src/pkg/runtime/asm_386.s +++ b/src/pkg/runtime/asm_386.s -@@ -1228,3 +1228,8 @@ +@@ -1353,3 +1353,8 @@ SETEQ CX // 1 if alen == blen LEAL -1(CX)(AX*2), AX // 1,0,-1 result RET + +// Not implemented on 386 yet -+TEXT runtime·lib_init(SB),7,$-4 ++TEXT runtime·lib_init(SB),NOSPLIT,$-4 + MOVW $0, AX + MOVW (AX), AX diff --git a/src/pkg/runtime/asm_amd64.s b/src/pkg/runtime/asm_amd64.s --- a/src/pkg/runtime/asm_amd64.s +++ b/src/pkg/runtime/asm_amd64.s -@@ -86,7 +86,8 @@ +@@ -88,7 +88,8 @@ CALL runtime·schedinit(SB) // create a new goroutine to start program @@ -247,53 +259,64 @@ diff --git a/src/pkg/runtime/asm_amd64.s b/src/pkg/runtime/asm_amd64.s + MOVQ $runtime·main·f(SB),AX + PUSHQ AX // entry PUSHQ $0 // arg size + ARGSIZE(16) CALL runtime·newproc(SB) - POPQ AX -@@ -781,7 +782,8 @@ +@@ -246,7 +247,8 @@ + + // Save our own state as the PC and SP to restore + // if this goroutine needs to be restarted. +- MOVQ $runtime·newstackcall(SB), (g_sched+gobuf_pc)(AX) ++ MOVQ $runtime·newstackcall(SB), DX ++ MOVQ DX, (g_sched+gobuf_pc)(AX) + MOVQ SP, (g_sched+gobuf_sp)(AX) + + // Set up morestack arguments to call f on a new stack. +@@ -878,7 +880,8 @@ // a page boundary, so we can load it directly. MOVOU (AX), X1 ADDQ CX, CX -- PAND masks(SB)(CX*8), X1 -+ MOVQ $masks(SB), AX -+ PAND (AX)(CX*8), X1 +- PAND masks<>(SB)(CX*8), X1 ++ MOVQ $masks<>(SB), AX ++ PAND (AX)(CX*8), X1 JMP partial highpartial: // address ends in 1111xxxx. Might be up against -@@ -789,7 +791,8 @@ +@@ -886,7 +889,8 @@ // Then shift bytes down using pshufb. MOVOU -16(AX)(CX*1), X1 ADDQ CX, CX -- PSHUFB shifts(SB)(CX*8), X1 -+ MOVQ $shifts(SB), AX -+ PSHUFB (AX)(CX*8), X1 +- PSHUFB shifts<>(SB)(CX*8), X1 ++ MOVQ $shifts<>(SB), AX ++ PSHUFB (AX)(CX*8), X1 partial: // incorporate partial block into hash AESENC X3, X0 -@@ -1138,3 +1141,9 @@ - SETEQ CX // 1 if alen == blen +@@ -1221,6 +1225,11 @@ LEAQ -1(CX)(AX*2), AX // 1,0,-1 result RET -+ -+TEXT runtime·lib_init(SB),7,$-8 + ++TEXT runtime·lib_init(SB),NOSPLIT,$-8 + MOVQ _cgo_lib_init(SB), AX + CALL AX + RET + + TEXT bytes·IndexByte(SB),NOSPLIT,$0 + MOVQ s+0(FP), SI + MOVQ s_len+8(FP), BX diff --git a/src/pkg/runtime/asm_arm.s b/src/pkg/runtime/asm_arm.s --- a/src/pkg/runtime/asm_arm.s +++ b/src/pkg/runtime/asm_arm.s -@@ -525,6 +525,11 @@ - MOVW 12(R0), m - RET +@@ -648,6 +648,10 @@ + MOVW R1, g + B runtime·save_gm(SB) -+TEXT runtime·lib_init(SB),7,$0 ++TEXT runtime·lib_init(SB),NOSPLIT,$0 + MOVW _cgo_lib_init(SB), R4 + BL (R4) + RET -+ - // void setmg_gcc(M*, G*); set m and g called from gcc. - TEXT setmg_gcc<>(SB),7,$0 - MOVW R0, m + + // TODO: share code with memeq? + TEXT bytes·Equal(SB),NOSPLIT,$0 diff --git a/src/pkg/runtime/cgo/gcc_sharedlib_linux.c b/src/pkg/runtime/cgo/gcc_sharedlib_linux.c new file mode 100644 --- /dev/null @@ -479,10 +502,10 @@ new file mode 100644 diff --git a/src/pkg/runtime/os_linux_arm.c b/src/pkg/runtime/os_linux_arm.c --- a/src/pkg/runtime/os_linux_arm.c +++ b/src/pkg/runtime/os_linux_arm.c -@@ -33,13 +33,52 @@ +@@ -34,13 +34,88 @@ } - #pragma textflag 7 + #pragma textflag NOSPLIT -void -runtime·setup_auxv(int32 argc, byte **argv) +static void @@ -510,7 +533,41 @@ diff --git a/src/pkg/runtime/os_linux_arm.c b/src/pkg/runtime/os_linux_arm.c + } +} + -+#pragma textflag 7 ++static uint8 *vfp = (uint8*)"vfpv3"; ++ ++#pragma textflag NOSPLIT ++static void ++parse_cpuinfo(void) ++{ ++ int32 fd; ++ uint8 buf[32]; ++ int32 idx, n, i; ++ ++ idx = 0; ++ fd = runtime·open((int8*)"/proc/cpuinfo", O_RDONLY, 0); ++ if(fd < 0) ++ return; ++ while((n = runtime·read(fd, buf, sizeof buf)) > 0) { ++ for(i = 0; i < n; i++) { ++ if(idx >= 3) { ++ runtime·hwcap |= HWCAP_VFP; ++ } ++ if(idx == 5) { ++ runtime·hwcap |= HWCAP_VFPv3; ++ goto done; ++ } else { ++ if(buf[i] == vfp[idx]) ++ idx++; ++ else ++ idx = 0; ++ } ++ } ++ } ++done: ++ runtime·close(fd); ++} ++ ++#pragma textflag NOSPLIT +static void +setup_auxv_from_proc(void) +{ @@ -518,14 +575,16 @@ diff --git a/src/pkg/runtime/os_linux_arm.c b/src/pkg/runtime/os_linux_arm.c + uint32 auxv_entry[2]; + + auxv_fd = runtime·open((int8*)"/proc/self/auxv", O_RDONLY, 0); -+ if(auxv_fd < 0) ++ if(auxv_fd < 0) { ++ parse_cpuinfo(); + return; ++ } + while(runtime·read(auxv_fd, auxv_entry, sizeof auxv_entry) == sizeof auxv_entry) + parse_auxv_entry(auxv_entry[0], auxv_entry[1]); + runtime·close(auxv_fd); +} + -+#pragma textflag 7 ++#pragma textflag NOSPLIT +static void +setup_auxv_from_argv(int32 argc, byte **argv) { @@ -536,7 +595,7 @@ diff --git a/src/pkg/runtime/os_linux_arm.c b/src/pkg/runtime/os_linux_arm.c // skip envp to get to ELF auxiliary vector. for(envp = &argv[argc+1]; *envp != nil; envp++) -@@ -47,28 +86,21 @@ +@@ -48,28 +123,21 @@ envp++; for(auxv=(uint32*)envp; auxv[0] != AT_NULL; auxv += 2) { @@ -562,7 +621,7 @@ diff --git a/src/pkg/runtime/os_linux_arm.c b/src/pkg/runtime/os_linux_arm.c } } - #pragma textflag 7 + #pragma textflag NOSPLIT +void +runtime·setup_auxv(int32 argc, byte **argv) +{ @@ -572,24 +631,24 @@ diff --git a/src/pkg/runtime/os_linux_arm.c b/src/pkg/runtime/os_linux_arm.c + setup_auxv_from_proc(); +} + -+#pragma textflag 7 ++#pragma textflag NOSPLIT int64 runtime·cputicks(void) { diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c -@@ -63,6 +63,7 @@ +@@ -66,6 +66,7 @@ + int32 runtime·gomaxprocs; uint32 runtime·needextram; - bool runtime·singleproc; bool runtime·iscgo; +uint8 runtime·islibrary; // set by 5l in shared library mode - uint32 runtime·gcwaiting; M runtime·m0; G runtime·g0; // idle goroutine for m0 -@@ -161,6 +162,17 @@ + G* runtime·allg; +@@ -169,6 +170,17 @@ - static FuncVal scavenger = {runtime·MHeap_Scavenger}; + static FuncVal initDone = { runtime·unlockOSThread }; +// Initalize runtime in shared library mode +extern void runtime·lib_init(void); @@ -605,7 +664,7 @@ diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c // The main goroutine. void runtime·main(void) -@@ -181,6 +193,15 @@ +@@ -213,6 +225,15 @@ runtime·unlockOSThread(); main·main(); @@ -621,7 +680,7 @@ diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c if(raceenabled) runtime·racefini(); -@@ -594,11 +615,15 @@ +@@ -697,11 +718,15 @@ M *mp; if(runtime·needextram) { @@ -645,12 +704,12 @@ diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c diff --git a/src/pkg/runtime/rt0_linux_amd64.s b/src/pkg/runtime/rt0_linux_amd64.s --- a/src/pkg/runtime/rt0_linux_amd64.s +++ b/src/pkg/runtime/rt0_linux_amd64.s -@@ -11,3 +11,9 @@ - TEXT main(SB),7,$-8 +@@ -13,3 +13,9 @@ + TEXT main(SB),NOSPLIT,$-8 MOVQ $_rt0_go(SB), AX JMP AX + -+TEXT _rt0_amd64_linux_lib(SB),7,$0 ++TEXT _rt0_amd64_linux_lib(SB),NOSPLIT,$0 + MOVQ $_rt0_go(SB), DI + MOVQ _cgo_lib_setup(SB), AX + CALL AX @@ -658,20 +717,19 @@ diff --git a/src/pkg/runtime/rt0_linux_amd64.s b/src/pkg/runtime/rt0_linux_amd64 diff --git a/src/pkg/runtime/rt0_linux_arm.s b/src/pkg/runtime/rt0_linux_arm.s --- a/src/pkg/runtime/rt0_linux_arm.s +++ b/src/pkg/runtime/rt0_linux_arm.s -@@ -83,3 +83,9 @@ +@@ -89,3 +89,8 @@ MOVW $_rt0_arm_linux1(SB), R4 B (R4) -+TEXT _rt0_arm_linux_lib(SB),7,$0 ++TEXT _rt0_arm_linux_lib(SB),NOSPLIT,$0 + MOVW $_rt0_arm_linux1(SB), R0 + MOVW _cgo_lib_setup(SB), R3 + BL (R3) -+ + RET diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c -@@ -75,6 +75,7 @@ +@@ -76,6 +76,7 @@ Slice syscall·envs; void (*runtime·sysargs)(int32, uint8**); @@ -679,7 +737,7 @@ diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c void runtime·args(int32 c, uint8 **v) -@@ -116,13 +117,22 @@ +@@ -117,13 +118,22 @@ { String *s; int32 i, n; @@ -707,18 +765,18 @@ diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h -@@ -699,6 +699,7 @@ +@@ -711,6 +711,7 @@ extern int8* runtime·goos; extern int32 runtime·ncpu; extern bool runtime·iscgo; +extern bool runtime·islibrary; extern void (*runtime·sysargs)(int32, uint8**); - extern uint32 runtime·maxstring; + extern uintptr runtime·maxstring; extern uint32 runtime·Hchansize; diff --git a/src/pkg/runtime/softfloat_arm.c b/src/pkg/runtime/softfloat_arm.c --- a/src/pkg/runtime/softfloat_arm.c +++ b/src/pkg/runtime/softfloat_arm.c -@@ -201,6 +201,16 @@ +@@ -202,6 +202,16 @@ runtime·printf("*** cpu PC += %x\n", (delta+2)*4); return delta+2; } @@ -818,7 +876,7 @@ diff --git a/src/pkg/runtime/vdso_linux_amd64.c b/src/pkg/runtime/vdso_linux_amd diff --git a/src/run.bash b/src/run.bash --- a/src/run.bash +++ b/src/run.bash -@@ -108,6 +108,20 @@ +@@ -135,6 +135,20 @@ ) || exit $? [ "$CGO_ENABLED" != 1 ] || @@ -838,4 +896,4 @@ diff --git a/src/run.bash b/src/run.bash +[ "$CGO_ENABLED" != 1 ] || [ "$GOHOSTOS" == windows ] || (xcd ../misc/cgo/testso - ./test.bash + ./test.bash || exit 1