tinygo-org / go-llvm Goto Github PK
View Code? Open in Web Editor NEWGo bindings to LLVM. Used as part of TinyGo.
Home Page: https://tinygo.org
License: Other
Go bindings to LLVM. Used as part of TinyGo.
Home Page: https://tinygo.org
License: Other
I understand that the library allows for the generation of LLVM IR. How can one programmatically compile the IR to machine code?
Hey, is there any reason for you to not to include LLVM's intrinsic functions like LLVMLookupIntrinsicID
, LLVMGetIntrinsicDeclaration
? They provide easy way to handle intrinsic functions, especially for overloaded ones.
I did
go get github.com/tinygo-org/go-llvm
But it can't seem to link LLVM.
# runtime/cgo
ld: library not found for -lLLVM-12.0.0
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
I installed LLVM through homebrew:
brew install llvm
brew info llvm
gives me
llvm: stable 12.0.0 (bottled), HEAD [keg-only]
Next-gen compiler infrastructure
https://llvm.org/
/usr/local/Cellar/llvm/12.0.0_1 (9,789 files, 1.5GB)
Poured from bottle on 2021-05-17 at 18:19:34
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/llvm.rb
License: Apache-2.0 with LLVM-exception
==> Dependencies
Build: cmake ✔, swig ✔
Required: [email protected] ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have llvm first in your PATH, run:
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> /Users/nishant/.bash_profile
For compilers to find llvm you may need to set:
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
==> Analytics
install: 25,459 (30 days), 71,165 (90 days), 235,541 (365 days)
install-on-request: 20,777 (30 days), 57,293 (90 days), 188,131 (365 days)
build-error: 0 (30 days)
$ brew install llvm # v16
$ cat main.go
package main
import (
"fmt"
"tinygo.org/x/go-llvm"
)
func main() {
_ = llvm.FlagAppleBlock
fmt.Println("hello")
}
$ go run main.go
# tinygo.org/x/go-llvm
../../Library/Application Support/go/pkg/mod/tinygo.org/x/[email protected]/analysis.go:16:10: fatal error: 'llvm-c/Analysis.h' file not found
#include "llvm-c/Analysis.h" // If you are getting an error here you need to build or install LLVM, see https://tinygo.org/docs/guides/build/
^~~~~~~~~~~~~~~~~~~
1 error generated.
Installing v15 instead works:
$ brew install llvm@15
$ go run main.go
hello
Currently the darwin config hard-codes LLVM 11. It should be modified to use the same tags as Linux (e.g. llvm13
) or updated to use LLVM 13.
Hello, is it possible to support LLVM version 13.0.0?
for copying tinygo this is critically important to support go on e2k platforms (Elbrus)
I plan to insert go-llvm into the assembly pipeline with llcrt https://gitflic.ru/project/e2khome/lccrt
Hello, and thank you for your project! I wrote a compiler in Go for a compiler course, and this project has made converting the compiler over to an LLVM backend super easy.
As I was working on calling some external C code that uses structs, I was trying to use the byval
attribute, and noticed that Verify
was crashing with a null pointer exception. As of r362128, byval
can optionally accept a type, and LLVMCreateEnumAttribute returns the attribute with a null type causing a null pointer access when Verify
is checking the module.
The solution here is to use LLVMCreateTypeAttribute which allows you to pass in the attribute kind and type.
I'll try to get a PR for this, but if you feel free if you beat me to it.
Does this binding work for all of Go?
Its hosted by the TinyGo project, and the readme does say nothing about the scope.
Maybe resolve this by a commit to the readme.
System info:
sayotte@x270:~/go/pkg/mod/tinygo.org/x$ cat /etc/issue
Ubuntu 20.04.3 LTS \n \l
sayotte@x270:~/go/pkg/mod/tinygo.org/x$ dpkg-query -l | grep llvm
ii libllvm12:amd64 1:12.0.0-3ubuntu1~20.04.5 amd64 Modular compiler and toolchain technologies, runtime library
ii libllvm12:i386 1:12.0.0-3ubuntu1~20.04.5 i386 Modular compiler and toolchain technologies, runtime library
ii libllvm14:amd64 1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64 Modular compiler and toolchain technologies, runtime library
ii llvm-14 1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64 Modular compiler and toolchain technologies
ii llvm-14-dev 1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64 Modular compiler and toolchain technologies, libraries and headers
ii llvm-14-linker-tools 1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64 Modular compiler and toolchain technologies - Plugins
ii llvm-14-runtime 1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64 Modular compiler and toolchain technologies, IR interpreter
ii llvm-14-tools 1:14.0.6~++20221117072312+f28c006a5895-1~exp1~20221117192323.163 amd64 Modular compiler and toolchain technologies, tools
sayotte@x270:~/go/pkg/mod/tinygo.org/x$ llvm-as-14 --version
Ubuntu LLVM version 14.0.6
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: skylake
go get
fails to find header files:
sayotte@x270:~/go/pkg/mod/tinygo.org/x$ go get tinygo.org/x/go-llvm
# tinygo.org/x/go-llvm
[email protected]/analysis.go:16:10: fatal error: llvm-c/Analysis.h: No such file or directory
16 | #include "llvm-c/Analysis.h" // If you are getting an error here you need to build or install LLVM, see https://tinygo.org/docs/guides/build/
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Modify Makefile
to use the installed version:
sayotte@x270:~/go/pkg/mod/tinygo.org/x/[email protected]$ sudo sed -i 's|VERSION=9.0.0|VERSION=14.0.6|' Makefile
sayotte@x270:~/go/pkg/mod/tinygo.org/x/[email protected]$ sudo PATH=$PATH make config
go install
still fails on the same import:
sayotte@x270:~/go/pkg/mod/tinygo.org/x/[email protected]$ go install
# tinygo.org/x/go-llvm
./analysis.go:16:10: fatal error: llvm-c/Analysis.h: No such file or directory
16 | #include "llvm-c/Analysis.h" // If you are getting an error here you need to build or install LLVM, see https://tinygo.org/docs/guides/build/
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
An attempt with setting CGO_
flags using llvm-config-14
overcomes` that problem, but dies in linking because it's looking for LLVM-15 for some reason???:
sayotte@x270:~/go/pkg/mod/tinygo.org/x/[email protected]$ cat ~/build.sh
#!/bin/bash
export CGO_CPPFLAGS=$(llvm-config-14 --cppflags)
export CGO_CFLAGS=$(llvm-config-14 --cflags)
export CGO_LDFLAGS=$(llvm-config-14 --ldflags)
go install
sayotte@x270:~/go/pkg/mod/tinygo.org/x/[email protected]$ ~/build.sh >~/log 2>&1
sayotte@x270:~/go/pkg/mod/tinygo.org/x/[email protected]$ cat ~/log
# tinygo.org/x/go-llvm
/usr/bin/ld: cannot find -lLLVM-15
collect2: error: ld returned 1 exit statu
I then tried deleting llvm_config_linux_llvm15.go
, hoping it was unnecessary and the culprit, but the linker barfed on boatloads of unresolved symbols.
hello,
I'm trying to run a command specified in the README.
go get github.com/tinygo-org/go-llvm
it gives the following error:
go: github.com/tinygo-org/[email protected]: parsing go.mod:
module declares its path as: tinygo.org/x/go-llvm
but was required as: github.com/tinygo-org/go-llvm
how can I download this module when the github url and module name are different?
I see that there's a file for Darwin support, but when I try getting this package on macOS, I get these compilation errors.
Is it possible that this package is trying to use Apple's LLVM (installed through Xcode) instead of the Homebrew version?
$ go get github.com/tinygo-org/go-llvm
# github.com/tinygo-org/go-llvm
In file included from IRBindings.cpp:13:
In file included from go/src/github.com/tinygo-org/go-llvm/IRBindings.h:16:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/Core.h:19:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/Types.h:17:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/DataTypes.h:28:
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:315:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:749:12: note: 'finite' declared here
In file included from IRBindings.cpp:13:
In file included from go/src/github.com/tinygo-org/go-llvm/IRBindings.h:16:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/Core.h:19:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/Types.h:17:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/DataTypes.h:28:
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:316:9: error: no member named 'isinf' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:317:9: error: no member named 'isnan' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:318:9: error: no member named 'isnormal' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:319:9: error: no member named 'isgreater' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:320:9: error: no member named 'isgreaterequal' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:321:9: error: no member named 'isless' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:322:9: error: no member named 'islessequal' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:323:9: error: no member named 'islessgreater' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:324:9: error: no member named 'isunordered' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:331:9: error: no member named 'abs' in the global namespace; did you mean 'fabs'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:417:15: note: 'fabs' declared here
In file included from IRBindings.cpp:13:
In file included from go/src/github.com/tinygo-org/go-llvm/IRBindings.h:16:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/Core.h:19:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/Types.h:17:
In file included from /usr/local/Cellar/llvm/9.0.0_1/include/llvm-c/DataTypes.h:28:
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:551:38: error: no template named 'is_floating_point'
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:551:76: error: definition or redeclaration of 'type' cannot name the global scope
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:551:76: error: no member named 'type' in the global namespace
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:551:80: error: expected ';' at end of declaration
/usr/local/opt/llvm/bin/../include/c++/v1/cmath:552:27: error: unknown type name '_A1'
fatal error: too many errors emitted, stopping now [-ferror-limit=]
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.1
$ brew info llvm
llvm: stable 9.0.0 (bottled), HEAD [keg-only]
Next-gen compiler infrastructure
https://llvm.org/
/usr/local/Cellar/llvm/9.0.0_1 (6,839 files, 3.7GB)
Poured from bottle on 2019-11-06 at 10:12:51
This is a great project!
Would it be possible to add support for the LLVM MC (Machine Code) library as well?
https://raywang.tech/2017/12/04/Using-the-LLVM-MC-Disassembly-API/#mcdisassembly
Also this might be a dumb question, but I see you using come Cpp files, does that mean you can link against the C++ API as well?
If so would you be able to link against the C++ version of the MC lib? That would allow for doing all kinds of interesting static code analysis in Go ❤️
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.