Source file src/cmd/cgo/internal/testplugin/testdata/issue81303/main.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Issue 81303: a plugin has its own copies of the itabs of the host.
     6  // The runtime added these copies to the itab table as second entries
     7  // for the same interface/type pairs. After the table grew, a lookup
     8  // could return the copy from the plugin. A type switch compares the
     9  // itab with the itab of the host, so it took the default case.
    10  //
    11  // Each plugin imports package p, which uses go/ast, so each plugin
    12  // adds a copy of every go/ast itab of the host. The host walks a
    13  // syntax tree before and after each plugin loads. The three plugins
    14  // are the same because plugin.Open loads a plugin path only once.
    15  
    16  package main
    17  
    18  import (
    19  	"log"
    20  	"plugin"
    21  
    22  	"testplugin/issue81303/p"
    23  )
    24  
    25  func main() {
    26  	p.Walk()
    27  	for _, name := range []string{"issue81303p1.so", "issue81303p2.so", "issue81303p3.so"} {
    28  		pl, err := plugin.Open(name)
    29  		if err != nil {
    30  			log.Fatal(err)
    31  		}
    32  		f, err := pl.Lookup("F")
    33  		if err != nil {
    34  			log.Fatal(err)
    35  		}
    36  		f.(func())()
    37  		p.Walk()
    38  	}
    39  }
    40  

View as plain text