Giter Site home page Giter Site logo

go-linkname's Introduction

Go LinkName

測試

go run cmd/main.go

学习知识点

1. 使用 //go:linkname 開頭不能有空白

// go:linkname 這樣會錯誤因為 //g 中間有空白

如果有了空白會變成報錯

# command-line-arguments
main.main: relocation target github.com/go-project-action/go-linkname/src/b.Hi not defined

2. 没有实现的包要加一个 .s 汇编档案绕过检查

試試看把 b.s 刪掉

# github.com/go-project-action/go-linkname/src/b
src/b/b.go:7:6: missing function body

3. 使用 //go:linkname 的包要加上 _ "unsafe"

unsafe 拿到會報錯

# github.com/go-project-action/go-linkname/src/a
src/a/a.go:5:3: //go:linkname only allowed in Go files that import "unsafe"

問題:

1. 为什么 time.Sleep 的实现要这么搞?

timeSleep 函數有用調用到 runtime/internal 的代碼,所以必須寫在 runtime 包裡面。

timeSleep 用到 assignBucket() 函數,assignBucket() 函數用到 timers structtimers struct 用到 internal/cpuCacheLinePadSize

如果 timeSleep 大寫也可以給別人調用。不過為了讓代碼分的更詳細一點,就在 time 下面加了一個 Sleep 函數,並且把 timeSleep 連接到 time.Sleep

go-linkname's People

Contributors

maxyzli avatar

Stargazers

Jusk avatar

Watchers

James Cloos avatar

Forkers

acv-er

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.