Skip to content

Commit

Permalink
fix fastcaller inline bug
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Aug 18, 2024
1 parent e879787 commit 29412f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 23 additions & 0 deletions fastcaller_go1.23.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ func pcFileLine(pc uintptr) (file string, line int) {
return
}

entry := funcInfoEntry(f)

if pc > entry {
// We store the pc of the start of the instruction following
// the instruction in question (the call or the inline mark).
// This is done for historical reasons, and to make FuncForPC
// work correctly for entries in the result of runtime.Callers.
pc--
}

return (*runtime.Func)(unsafe.Pointer(f._func)).FileLine(pc)
}

Expand All @@ -32,6 +42,16 @@ func pcFileLineName(pc uintptr) (file string, line int, name string) {
return
}

entry := funcInfoEntry(f)

if pc > entry {
// We store the pc of the start of the instruction following
// the instruction in question (the call or the inline mark).
// This is done for historical reasons, and to make FuncForPC
// work correctly for entries in the result of runtime.Callers.
pc--
}

file, line = (*runtime.Func)(unsafe.Pointer(f._func)).FileLine(pc)
str := &f.datap.funcnametab[f.nameOff]
ss := stringStruct{str: unsafe.Pointer(str), len: findnull(str)}
Expand Down Expand Up @@ -121,3 +141,6 @@ type moduledata struct {

//go:linkname findfunc runtime.findfunc
func findfunc(pc uintptr) funcInfo

//go:linkname funcInfoEntry runtime.funcInfo.entry
func funcInfoEntry(f funcInfo) uintptr
10 changes: 0 additions & 10 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,6 @@ func (e *Entry) TimesFormat(key string, timefmt string, a []time.Time) *Entry {
}

// Bool append append the val as a bool to the entry.
//
//go:noinline
func (e *Entry) Bool(key string, b bool) *Entry {
if e == nil {
return nil
Expand All @@ -797,8 +795,6 @@ func (e *Entry) Bool(key string, b bool) *Entry {
}

// Bools adds the field key with val as a []bool to the entry.
//
//go:noinline
func (e *Entry) Bools(key string, b []bool) *Entry {
if e == nil {
return nil
Expand Down Expand Up @@ -925,8 +921,6 @@ func (e *Entry) Durs(key string, d []time.Duration) *Entry {
}

// Err adds the field "error" with serialized err to the entry.
//
//go:noinline
func (e *Entry) Err(err error) *Entry {
return e.AnErr("error", err)
}
Expand Down Expand Up @@ -2285,8 +2279,6 @@ func (e *Entry) KeysAndValues(keysAndValues ...any) *Entry {
type Fields map[string]any

// Fields is a helper function to use a map to set fields using type assertion.
//
//go:noinline
func (e *Entry) Fields(fields Fields) *Entry {
if e == nil {
return nil
Expand Down Expand Up @@ -2317,8 +2309,6 @@ func (e *Entry) Value() Context {
}

// Context sends the contextual fields to entry.
//
//go:noinline
func (e *Entry) Context(ctx Context) *Entry {
if e == nil {
return nil
Expand Down

0 comments on commit 29412f8

Please sign in to comment.