Commit 19c9d587 authored by Kirill Smelkov's avatar Kirill Smelkov

X Consisteny checks via link failures work

parent 84c4f5f2
...@@ -512,6 +512,13 @@ var traceEventImportTmpl = template.Must(template.New("traceimport").Parse(` ...@@ -512,6 +512,13 @@ var traceEventImportTmpl = template.Must(template.New("traceimport").Parse(`
func {{.ImportSpec.PkgName}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.ArgvTypedRelativeTo .ImporterPkg .ImportedAs}})) *tracing.Probe func {{.ImportSpec.PkgName}}_{{.Name}}_Attach(*tracing.ProbeGroup, func({{.ArgvTypedRelativeTo .ImporterPkg .ImportedAs}})) *tracing.Probe
`)) `))
// traceEventImportCheckTmpl is code template generated to check consistency with one imported package
var traceEventImportCheckTmpl = template.Must(template.New("traceimportcheck").Parse(`
//go:linkname {{.ImportSpec.PkgName}}_trace_exporthash {{.ImportSpec.PkgPath}}._trace_exporthash_{{.ExportHash}}
func {{.ImportSpec.PkgName}}_trace_exporthash()
func init() { {{.ImportSpec.PkgName}}_trace_exporthash() } // rerun "gotrace gen" if you see link failure here
`))
// magic begins all files generated by gotrace // magic begins all files generated by gotrace
const magic = "// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.\n" const magic = "// Code generated by lab.nexedi.com/kirr/go123/tracing/cmd/gotrace; DO NOT EDIT.\n"
...@@ -744,15 +751,6 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error { ...@@ -744,15 +751,6 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error {
text := &Buffer{} text := &Buffer{}
// export hash symbol so that if importing package is out of
// sync - it will have it different and linking will fail.
if len(tpkg.Eventv) > 0 {
//text.emit("\n---- 8< ---- (export signature)")
//fmt.Fprintf(text, "%s", traceExport(tpkg, kind))
//text.emit("---- 8< ----")
text.emit("\nvar _t_exporthash_%s bool", traceExportHash(tpkg, kind))
}
// code for trace:event definitions // code for trace:event definitions
for _, event := range tpkg.Eventv { for _, event := range tpkg.Eventv {
needPkg.Add(event.NeedPkgv()...) needPkg.Add(event.NeedPkgv()...)
...@@ -762,6 +760,16 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error { ...@@ -762,6 +760,16 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error {
} }
} }
// export hash symbol so that if importing package is out of
// sync - it will have it different and linking will fail.
if len(tpkg.Eventv) > 0 {
text.emit("\n// trace export signature")
//text.emit("---- 8< ----")
//fmt.Fprintf(text, "%s", traceExport(tpkg, kind))
//text.emit("---- 8< ----")
text.emit("func _trace_exporthash_%s() {}", traceExportHash(tpkg, kind))
}
// code for trace:import imports // code for trace:import imports
for _, timport := range tpkg.Importv { for _, timport := range tpkg.Importv {
text.emit("\n// traceimport: %s", timport.ImportSpec()) text.emit("\n// traceimport: %s", timport.ImportSpec())
...@@ -787,13 +795,20 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error { ...@@ -787,13 +795,20 @@ func tracegen1(P *Program, tpkg *Package, pkgdir string, kind string) error {
return fmt.Errorf("%v: package %v does not export anything trace-related", timport.Pos, timport.PkgPath) return fmt.Errorf("%v: package %v does not export anything trace-related", timport.Pos, timport.PkgPath)
} }
// verify export hash // verify export hash so link fails if it gets out of sync with imported package
text.emit("\nzzz_t_exporthash_%s", traceExportHash(impPkg, ""/*regular pkg*/)) err = traceEventImportCheckTmpl.Execute(text, struct{
ImportSpec *traceImport
ExportHash string}{
timport,
traceExportHash(impPkg, ""/*regular package*/)})
text.emit("")
// import individual events
for _, event := range impPkg.Eventv { for _, event := range impPkg.Eventv {
needPkg.Add(event.NeedPkgv()...) needPkg.Add(event.NeedPkgv()...)
importedEvent := traceImported{ importedEvent := traceImported{
traceEvent: event, traceEvent: event,
ImportSpec: timport, ImportSpec: timport,
ImporterPkg: tpkg.Pkgi.Pkg, ImporterPkg: tpkg.Pkgi.Pkg,
ImportedAs: importedAs, ImportedAs: importedAs,
......
...@@ -16,6 +16,6 @@ import "C" ...@@ -16,6 +16,6 @@ import "C"
//trace:event traceHello() //trace:event traceHello()
func Hello() { func Hello() {
traceHello() //traceHello()
C.hello() C.hello()
} }
...@@ -117,3 +117,6 @@ func traceURLParsed_Attach(pg *tracing.ProbeGroup, probe func(u *url.URL)) *trac ...@@ -117,3 +117,6 @@ func traceURLParsed_Attach(pg *tracing.ProbeGroup, probe func(u *url.URL)) *trac
tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceURLParsed)), &p.Probe) tracing.AttachProbe(pg, (**tracing.Probe)(unsafe.Pointer(&_traceURLParsed)), &p.Probe)
return &p.Probe return &p.Probe
} }
// trace export signature
func _trace_exporthash_965fa599dc3a61119faba1eacf8493973c5d87ad() {}
...@@ -38,8 +38,16 @@ func traceDoSomething_Attach(pg *tracing.ProbeGroup, probe func(i, j int, q stri ...@@ -38,8 +38,16 @@ func traceDoSomething_Attach(pg *tracing.ProbeGroup, probe func(i, j int, q stri
return &p.Probe return &p.Probe
} }
// trace export signature
func _trace_exporthash_80ddfc2f6c72bdf357dedbb2f0bbec85e93106fc() {}
// traceimport: "a/pkg1" // traceimport: "a/pkg1"
//go:linkname pkg1_trace_exporthash a/pkg1._trace_exporthash_965fa599dc3a61119faba1eacf8493973c5d87ad
func pkg1_trace_exporthash()
func init() { pkg1_trace_exporthash() } // rerun "gotrace gen" if you see link failure here
//go:linkname pkg1_traceDoSomething_Attach a/pkg1.traceDoSomething_Attach //go:linkname pkg1_traceDoSomething_Attach a/pkg1.traceDoSomething_Attach
func pkg1_traceDoSomething_Attach(*tracing.ProbeGroup, func(topic string)) *tracing.Probe func pkg1_traceDoSomething_Attach(*tracing.ProbeGroup, func(topic string)) *tracing.Probe
......
...@@ -13,6 +13,11 @@ import ( ...@@ -13,6 +13,11 @@ import (
// traceimport: aaa1 "a/pkg1" // traceimport: aaa1 "a/pkg1"
//go:linkname aaa1_trace_exporthash a/pkg1._trace_exporthash_965fa599dc3a61119faba1eacf8493973c5d87ad
func aaa1_trace_exporthash()
func init() { aaa1_trace_exporthash() } // rerun "gotrace gen" if you see link failure here
//go:linkname aaa1_traceDoSomething_Attach a/pkg1.traceDoSomething_Attach //go:linkname aaa1_traceDoSomething_Attach a/pkg1.traceDoSomething_Attach
func aaa1_traceDoSomething_Attach(*tracing.ProbeGroup, func(topic string)) *tracing.Probe func aaa1_traceDoSomething_Attach(*tracing.ProbeGroup, func(topic string)) *tracing.Probe
......
...@@ -10,5 +10,10 @@ import ( ...@@ -10,5 +10,10 @@ import (
// traceimport: "b/pkg2" // traceimport: "b/pkg2"
//go:linkname pkg2_trace_exporthash b/pkg2._trace_exporthash_80ddfc2f6c72bdf357dedbb2f0bbec85e93106fc
func pkg2_trace_exporthash()
func init() { pkg2_trace_exporthash() } // rerun "gotrace gen" if you see link failure here
//go:linkname pkg2_traceDoSomething_Attach b/pkg2.traceDoSomething_Attach //go:linkname pkg2_traceDoSomething_Attach b/pkg2.traceDoSomething_Attach
func pkg2_traceDoSomething_Attach(*tracing.ProbeGroup, func(i, j int, q string)) *tracing.Probe func pkg2_traceDoSomething_Attach(*tracing.ProbeGroup, func(i, j int, q string)) *tracing.Probe
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment