Ver código fonte

Script to generate binutils test binaries for MacOS and Linux (#452)

Kalyana Chadalavada 6 anos atrás
pai
commit
b421f19a5c

+ 6
- 0
internal/binutils/binutils_test.go Ver arquivo

@@ -218,6 +218,9 @@ func findSymbol(syms []*plugin.Sym, name string) *plugin.Sym {
218 218
 }
219 219
 
220 220
 func TestObjFile(t *testing.T) {
221
+	// If this test fails, check the address for main function in testdata/exe_linux_64
222
+	// using the command 'nm -n '. Update the hardcoded addresses below to match
223
+	// the addresses from the output.
221 224
 	skipUnlessLinuxAmd64(t)
222 225
 	for _, tc := range []struct {
223 226
 		desc                 string
@@ -264,6 +267,9 @@ func TestObjFile(t *testing.T) {
264 267
 }
265 268
 
266 269
 func TestMachoFiles(t *testing.T) {
270
+	// If this test fails, check the address for main function in testdata/exe_mac_64
271
+	// and testdata/lib_mac_64 using addr2line or gaddr2line. Update the
272
+	// hardcoded addresses below to match the addresses from the output.
267 273
 	skipUnlessDarwinAmd64(t)
268 274
 
269 275
 	// Load `file`, pretending it was mapped at `start`. Then get the symbol

+ 58
- 0
internal/binutils/testdata/build_binaries.sh Ver arquivo

@@ -0,0 +1,58 @@
1
+#!/bin/bash -x
2
+
3
+# Copyright 2019 Google Inc. All Rights Reserved.
4
+#
5
+# Licensed under the Apache License, Version 2.0 (the "License");
6
+# you may not use this file except in compliance with the License.
7
+# You may obtain a copy of the License at
8
+#
9
+#     http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+# Unless required by applicable law or agreed to in writing, software
12
+# distributed under the License is distributed on an "AS IS" BASIS,
13
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+# See the License for the specific language governing permissions and
15
+# limitations under the License.
16
+
17
+# This is a script that generates the test executables for MacOS and Linux
18
+# in this directory. It should be needed very rarely to run this script.
19
+# It is mostly provided as a future reference on how the original binary
20
+# set was created.
21
+
22
+# When a new executable is generated, hardcoded addresses in the
23
+# functions TestObjFile, TestMachoFiles in binutils_test.go must be updated.
24
+
25
+set -o errexit
26
+
27
+cat <<EOF >/tmp/hello.c
28
+#include <stdio.h>
29
+
30
+int main() {
31
+  printf("Hello, world!\n");
32
+  return 0;
33
+}
34
+EOF
35
+
36
+cd $(dirname $0)
37
+
38
+if [[ "$OSTYPE" == "linux-gnu" ]]; then
39
+  rm -rf exe_linux_64*
40
+  cc -g -o exe_linux_64 /tmp/hello.c
41
+elif [[ "$OSTYPE" == "darwin"* ]]; then
42
+  cat <<EOF >/tmp/lib.c
43
+  int foo() {
44
+    return 1;
45
+  }
46
+
47
+  int bar() {
48
+    return 2;
49
+  }
50
+  EOF
51
+
52
+  rm -rf exe_mac_64* lib_mac_64*
53
+  clang -g -o exe_mac_64 /tmp/hello.c
54
+  clang -g -o lib_mac_64 -dynamiclib /tmp/lib.ca
55
+else
56
+  echo "Unknown OS: $OSTYPE"
57
+  exit 1
58
+fi

+ 0
- 45
internal/binutils/testdata/build_mac.sh Ver arquivo

@@ -1,45 +0,0 @@
1
-# Copyright 2018 Google Inc. All Rights Reserved.
2
-#
3
-# Licensed under the Apache License, Version 2.0 (the "License");
4
-# you may not use this file except in compliance with the License.
5
-# You may obtain a copy of the License at
6
-#
7
-#     http://www.apache.org/licenses/LICENSE-2.0
8
-#
9
-# Unless required by applicable law or agreed to in writing, software
10
-# distributed under the License is distributed on an "AS IS" BASIS,
11
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-# See the License for the specific language governing permissions and
13
-# limitations under the License.
14
-
15
-#!/bin/bash -x
16
-
17
-# This is a script that generates the test MacOS executables in this directory.
18
-# It should be needed very rarely to run this script. It is mostly provided
19
-# as a future reference on how the original binary set was created.
20
-
21
-set -o errexit
22
-
23
-cat <<EOF >/tmp/hello.cc
24
-#include <stdio.h>
25
-
26
-int main() {
27
-  printf("Hello, world!\n");
28
-  return 0;
29
-}
30
-EOF
31
-
32
-cat <<EOF >/tmp/lib.c
33
-int foo() {
34
-  return 1;
35
-}
36
-
37
-int bar() {
38
-  return 2;
39
-}
40
-EOF
41
-
42
-cd $(dirname $0)
43
-rm -rf exe_mac_64* lib_mac_64*
44
-clang -g -o exe_mac_64 /tmp/hello.c
45
-clang -g -o lib_mac_64 -dynamiclib /tmp/lib.c