[cgolinkext] go list ./usesInternalCgo
[!cgolinkext] go build '-ldflags=-tmpdir=tmp5 -linkmode=internal' -o $devnull ./usesInternalCgo &
+# Sixth build: explicit CGO use in a non-main package.
+go build -o p.a ./nonMainPackageUsesExplicitCgo &
+
wait
# Check first build: no external linking expected
# Fifth build: explicit CGO, -linkmode=internal.
! exists tmp5/go.o
+# Sixth build: make sure that "go tool nm" doesn't get confused
+# by the presence of the "preferlinkext" sentinel.
+go tool nm p.a
+
-- go.mod --
module cgo.example
func main() {
println(C.meaningOfLife())
}
+
+-- nonMainPackageUsesExplicitCgo/main.go --
+
+package p
+
+/*
+int meaningOfLife() { return 42; }
+*/
+import "C"
+
+func PrintIt() {
+ println(C.meaningOfLife())
+}
EntryPkgDef EntryType = iota
EntryGoObj
EntryNativeObj
+ EntrySentinelNonObj
)
func (e *Entry) String() string {
Data: Data{r.offset, size},
})
r.skip(size)
+ case "preferlinkext", "dynimportfail":
+ if size == 0 {
+ // These are not actual objects, but rather sentinel
+ // entries put into the archive by the Go command to
+ // be read by the linker. See #62036.
+ r.a.Entries = append(r.a.Entries, Entry{
+ Name: name,
+ Type: EntrySentinelNonObj,
+ Mtime: mtime,
+ Uid: uid,
+ Gid: gid,
+ Mode: mode,
+ Data: Data{r.offset, size},
+ })
+ break
+ }
+ fallthrough
default:
var typ EntryType
var o *GoObj
L:
for _, e := range a.Entries {
switch e.Type {
- case archive.EntryPkgDef:
+ case archive.EntryPkgDef, archive.EntrySentinelNonObj:
continue
case archive.EntryGoObj:
o := e.Obj