xref: /aosp_15_r20/external/bazelbuild-rules_go/tests/core/go_binary/static_test.go (revision 9bb1b549b6a84214c53be0924760be030e66b93a)
1// Copyright 2019 The Bazel Authors. 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// +build linux
16
17package static_cgo_test
18
19import (
20	"debug/elf"
21	"testing"
22
23	"github.com/bazelbuild/rules_go/go/tools/bazel"
24)
25
26func TestStatic(t *testing.T) {
27	for _, name := range []string{"static_bin", "static_cgo_bin", "static_pure_bin"} {
28		t.Run(name, func(t *testing.T) {
29			path, ok := bazel.FindBinary("tests/core/go_binary", name)
30			if !ok {
31				t.Fatal("could not find static_cgo_bin")
32			}
33			f, err := elf.Open(path)
34			if err != nil {
35				t.Fatal(err)
36			}
37			defer f.Close()
38			for _, prog := range f.Progs {
39				if prog.Type == elf.PT_INTERP {
40					t.Fatalf("binary %s has PT_INTERP segment, indicating dynamic linkage", path)
41				}
42			}
43		})
44	}
45}
46