aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/testdata/testRO
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-09-10 11:14:27 -0400
committerCherry Zhang <cherryyz@google.com>2020-09-11 15:41:20 +0000
commit1ed4f12f4a6b9d783cf9a6fc3a292a433b8539c6 (patch)
tree0d2292755b7dd63c41fdf47e53b90810726b4fb8 /src/cmd/link/testdata/testRO
parentffd95aadcddc34ec2c83971346f04cf7234e0fca (diff)
downloadgo-1ed4f12f4a6b9d783cf9a6fc3a292a433b8539c6.tar.xz
cmd/link: add a test to test RODATA is indeed read-only
Updates #38830. Change-Id: Ie1f6ccef40a773f038aac587dfc26bf70a1a8536 Reviewed-on: https://go-review.googlesource.com/c/go/+/253921 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/link/testdata/testRO')
-rw-r--r--src/cmd/link/testdata/testRO/x.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cmd/link/testdata/testRO/x.go b/src/cmd/link/testdata/testRO/x.go
new file mode 100644
index 0000000000..d77db6d563
--- /dev/null
+++ b/src/cmd/link/testdata/testRO/x.go
@@ -0,0 +1,22 @@
+// Copyright 2020 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.
+
+// Test that read-only data is indeed read-only. This
+// program attempts to modify read-only data, and it
+// should fail.
+
+package main
+
+import "unsafe"
+
+var s = "hello"
+
+func main() {
+ println(s)
+ *(*struct {
+ p *byte
+ l int
+ })(unsafe.Pointer(&s)).p = 'H'
+ println(s)
+}