{"id":16587024,"url":"https://github.com/zchee/golang-gollvm","last_synced_at":"2025-06-10T10:04:13.084Z","repository":{"id":77304736,"uuid":"145738568","full_name":"zchee/golang-gollvm","owner":"zchee","description":"Fork of https://go.googlesource.com/gollvm/","archived":false,"fork":false,"pushed_at":"2018-08-22T17:03:01.000Z","size":736,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T08:37:12.126Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://go.googlesource.com/gollvm/","language":"C++","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zchee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-22T17:02:12.000Z","updated_at":"2023-05-07T19:46:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb242ff1-e247-4f8f-9b3a-68fd0036ba86","html_url":"https://github.com/zchee/golang-gollvm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zchee%2Fgolang-gollvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zchee%2Fgolang-gollvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zchee%2Fgolang-gollvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zchee%2Fgolang-gollvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zchee","download_url":"https://codeload.github.com/zchee/golang-gollvm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zchee%2Fgolang-gollvm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259053220,"owners_count":22798423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T22:53:07.909Z","updated_at":"2025-06-10T10:04:13.044Z","avatar_url":"https://github.com/zchee.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Gollvm\n\nGollvm is an LLVM-based Go compiler. It incorporates \"gofrontend\" (a Go language front end written in C++ and shared with GCCGO), a bridge component (which translates from gofrontend IR to LLVM IR), and a driver that sends the resulting IR through the LLVM back end.\n\nGollvm is set up to be a subproject within the LLVM tools directory, similar to\nhow things work for \"clang\" or \"compiler-rt\": you check out a copy of the LLVM\nsource tree, then within the LLVM tree you check out additional git repos.\n\n\n# Table of contents \u003ca name=\"toc\"\u003e\u003c/a\u003e\n\n * [Building gollvm](#building)\n * [Work area setup](#workarea)\n * [Invoking cmake and ninja](#cmakeninja)\n * [Installing gollvm](#installing)\n * [Using an installed copy of gollvm](#using)\n * [Information for gollvm developers](#developers)\n\n[FAQ](#FAQ)\n\n  * [Where should I post questions about gollvm?](#wheretopostquestions)\n  * [Where should I file gollvm bugs?](#wheretofile)\n  * [How can I go about contributing to gollvm?](#contributing)\n  * [Is gollvm a replacement for the main Go compiler (gc)?](#replacegc)\n  * [Which architectures and operating systems are supported for gollvm?](#supported)\n  * [How does the gollvm runtime differ from the main Go runtime?](#runtimediffs)\n  * [Shared linkage is the default for gollvm. How do I build non-shared?](#buildstatic)\n  * [What command line options are supported for gollvm?](#cmdlineopts)\n  * [How do I see the LLVM IR generated by gollvm?](#seetheir)\n  * [What is the relationship between gollvm and gccgo?](#gollvmandgccgo)\n  * [Can I use FDO or Thin LTO with gollvm?](#thinltofdo)\n  * [Can I use the race detector?](#racedetector)\n\n# Building gollvm \u003ca name=\"building\"\u003e\u003c/a\u003e\n\nGollvm is currently in development -- releases are not yet available for download.  Instructions for building gollvm follow.\n\n## Setting up a gollvm work area \u003ca name=\"workarea\"\u003e\u003c/a\u003e\n\nTo set up a work area for Gollvm, check out a copy of LLVM, the overlay the gollvm repo (and other associated dependencies) within the LLVM tools subdir, as follows:\n\n```\n// Here 'workarea' will contain a copy of the LLVM source tree and one or more build areas\n% mkdir workarea\n% cd workarea\n\n// Sources\n% git clone http://llvm.org/git/llvm.git\n...\n% cd llvm/tools\n% git clone https://go.googlesource.com/gollvm\n...\n% cd gollvm\n% git clone https://go.googlesource.com/gofrontend\n...\n% cd libgo\n% git clone https://github.com/libffi/libffi.git\n...\n% git clone https://github.com/ianlancetaylor/libbacktrace.git\n...\n%\n```\n\n## Building gollvm with cmake and ninja  \u003ca name=\"cmakeninja\"\u003e\u003c/a\u003e\n\nYou'll need to have an up-to-date copy of cmake on your system (3.6 or later vintage) to build Gollvm.\n\nCreate a build directory (separate from the source tree) and run 'cmake' within the build area to set up for the build. Assuming that 'workarea' is the directory created as above:\n\n```\n% cd workarea\n% mkdir build-debug\n% cd build-debug\n% cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_USE_LINKER=gold -G Ninja ../llvm\n...\n% ninja gollvm\n...\n%\n```\n\nThis will build the various tools and libraries needed for Gollvm.\n\n## Installing gollvm \u003ca name=\"installing\"\u003e\u003c/a\u003e\n\nA gollvm installation will contain 'llvm-goc' (the compiler driver), the libgo standard Go libraries, and the standard Go tools (\"go\", \"vet\", \"cgo\", etc).\n\nThe installation directory for gollvm needs to be specified when invoking cmake prior to the build:\n\n```\n% mkdir build.rel\n% cd build.rel\n% cmake -DCMAKE_INSTALL_PREFIX=/my/install/dir -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_LINKER=gold -G Ninja ../llvm\n\n// Build all of gollvm\n% ninja gollvm\n...\n\n// Install gollvm to \"/my/install/dir\"\n% ninja install-gollvm\n\n```\n\n## Using an installed copy of gollvm  \u003ca name=\"using\"\u003e\u003c/a\u003e\n\nPrograms build with the Gollvm Go compiler default to shared linkage, meaning that they need to pick up the Go runtime library via LD_LIBRARY_PATH:\n\n```\n// Root of Gollvm install is /tmp/gollvm-install\n% export LD_LIBRARY_PATH=/tmp/gollvm-install/lib64\n% export PATH=/tmp/gollvm-install/bin:$PATH\n% go run himom.go\nhi mom!\n%\n```\n\n# Information for gollvm developers \u003ca name=\"developers\"\u003e\u003c/a\u003e\n\n## Source code structure\n\nWithin \\\u003cworkarea\\\u003e/llvm/tools/gollvm, the following directories are of interest:\n\n.../llvm/tools/gollvm:\n\n * contains rules to build third party libraries needed for gollvm,\n   along with common definitions for subdirs.\n\n.../llvm/tools/gollvm/driver,\n.../llvm/tools/gollvm/driver-main:\n\n * contains build rules and source code for llvm-goc\n\n.../llvm/tools/gollvm/gofrontend:\n\n * source code for gofrontend and libgo (note: no cmake files here)\n\n.../llvm/tools/gollvm/bridge:\n\n * contains build rules for the libLLVMCppGoFrontEnd.a, a library that contains both the gofrontend code and the LLVM-specific middle layer (for example, the definition of the class Llvm_backend, which inherits from Backend).\n\n.../llvm/tools/gollvm/libgo:\n\n * build rules and supporting infrastructure to build Gollvm's copy of the Go runtime and standard packages.\n\n.../llvm/tools/gollvm/unittests:\n\n * source code for the unit tests\n\n## The llvm-goc program\n\nThe executable llvm-goc is the main compiler driver for gollvm; it functions as a compiler (consuming source for a Go package and producing an object file), an assembler, and/or a linker.  While it is possible to build and run llvm-goc directly from the command line, in practice there is little point in doing this (better to build using \"go build\", which will invoke llvm-goc on your behalf.\n\n```\n// From within \u003cworkarea\u003e/build.opt:\n\n% ninja llvm-goc\n...\n% cat micro.go\npackage foo\nfunc Bar() int {\n\treturn 1\n}\n% ./bin/llvm-goc -fgo-pkgpath=foo -O3 -S -o micro.s micro.go\n%\n```\n\n\n## Building and running the unit tests\n\nHere are instructions on building and running the unit tests for the middle layer:\n\n```\n// From within \u003cworkarea\u003e/build.opt:\n\n// Build unit test\n% ninja GoBackendCoreTests\n\n// Run a unit test\n% ./tools/gollvm/unittests/BackendCore/GoBackendCoreTests\n[==========] Running 10 tests from 2 test cases.\n[----------] Global test environment set-up.\n[----------] 9 tests from BackendCoreTests\n[ RUN      ] BackendCoreTests.MakeBackend\n[       OK ] BackendCoreTests.MakeBackend (1 ms)\n[ RUN      ] BackendCoreTests.ScalarTypes\n[       OK ] BackendCoreTests.ScalarTypes (0 ms)\n[ RUN      ] BackendCoreTests.StructTypes\n[       OK ] BackendCoreTests.StructTypes (1 ms)\n[ RUN      ] BackendCoreTests.ComplexTypes\n[       OK ] BackendCoreTests.ComplexTypes (0 ms)\n[ RUN      ] BackendCoreTests.FunctionTypes\n[       OK ] BackendCoreTests.FunctionTypes (0 ms)\n[ RUN      ] BackendCoreTests.PlaceholderTypes\n[       OK ] BackendCoreTests.PlaceholderTypes (0 ms)\n[ RUN      ] BackendCoreTests.ArrayTypes\n[       OK ] BackendCoreTests.ArrayTypes (0 ms)\n[ RUN      ] BackendCoreTests.NamedTypes\n[       OK ] BackendCoreTests.NamedTypes (0 ms)\n[ RUN      ] BackendCoreTests.TypeUtils\n\n...\n\n[  PASSED  ] 10 tests.\n```\n\nThe unit tests currently work by instantiating an LLVM Backend instance and making backend method calls (to mimic what the frontend would do), then inspects the results to make sure they are as expected. Here is an example:\n\n```\nTEST(BackendCoreTests, ComplexTypes) {\n  LLVMContext C;\n\n  Type *ft = Type::getFloatTy(C);\n  Type *dt = Type::getDoubleTy(C);\n\n  std::unique_ptr\u003cBackend\u003e be(go_get_backend(C));\n  Btype *c32 = be-\u003ecomplex_type(64);\n  ASSERT_TRUE(c32 != NULL);\n  ASSERT_EQ(c32-\u003etype(), mkTwoFieldLLvmStruct(C, ft, ft));\n  Btype *c64 = be-\u003ecomplex_type(128);\n  ASSERT_TRUE(c64 != NULL);\n  ASSERT_EQ(c64-\u003etype(), mkTwoFieldLLvmStruct(C, dt, dt));\n}\n```\n\nThe test above makes sure that the LLVM type we get as a result of calling Backend::complex_type() is kosher and matches up to expectations.\n\n## Building libgo (Go runtime and standard libraries)\n\nTo build the Go runtime and standard libraries, use the following:\n\n```\n// From within \u003cworkarea\u003e/build.opt:\n\n// Build Go runtime and standard libraries\n% ninja libgo_all\n\n```\n\nThis will compile static (\\*.a) and dynamic (\\*.so) versions of the library.\n\n# FAQ \u003ca name=\"FAQ\"\u003e\u003c/a\u003e\n\n## Where should I post questions about gollvm? \u003ca name=\"wheretopostquestions\"\u003e\u003c/a\u003e\n\nPlease send questions about gollvm to the [golang-nuts](https://groups.google.com/d/forum/golang-nuts) mailing list. Posting questions to the issue tracker is generally not the right way to start discussions or get information.\n\n## Where should I file gollvm bugs? \u003ca name=\"wheretofile\"\u003e\u003c/a\u003e\n\nPlease file an issue on the golang [issue tracker](https://github.com/golang/go/issues); please be sure to use \"gollvm\" somewhere in the headline.\n\n## How can I go about contributing to gollvm? \u003ca name=\"contributing\"\u003e\u003c/a\u003e\n\nPlease see the Go project guidelines at [https://golang.org/doc/contribute.html](https://golang.org/doc/contribute.html). Changes to [https://go.googlesource.com/gollvm](https://go.googlesource.com/gollvm) can be made by any Go contributor; for changes to gofrontend see [the gccgo guidelines](https://golang.org/doc/gccgo_contribute.html).\n\n## Is gollvm a replacement for the main Go compiler? (gc) \u003ca name=\"replacegc\"\u003e\u003c/a\u003e\n\nGollvm is not intended as a replacement for the main Go compiler -- the\nexpectation is that the bulk of users will want to continue to use the main Go\ncompiler due to its superior compilation speed, ease of use, broader\nfunctionality, and higher-performance runtime. Gollvm is intended to provide a\nGo compiler with a more powerful back end, enabling such benefits as better\ninlining, vectorization, register allocation, etc.\n\n## Which architectures and operating systems are supported for gollvm? \u003ca name=\"supported\"\u003e\u003c/a\u003e\n\nGollvm is currently supported only for x86_64 Linux.\n\n## How does the gollvm runtime differ from the main Go runtime?  \u003ca name=\"runtimediffs\"\u003e\u003c/a\u003e\n\nThe main Go runtime supports generation of accurate stack maps, which allows the\ngarbage collector to do precise stack scanning; gollvm does not yet support\nstack map generation (note that we're actively working on fixing this), hence\nfor gollvm the garbage collector has to scan stacks conservatively (which can\nlead to longer scan times and increased memory usage). The main Go runtime\ncompiles to a different calling convention, whereas Gollvm uses the standard\nC/C++ calling convention. There are many other smaller differences as well.\n\n## Shared linkage is the default for gollvm. How do I build non-shared?  \u003ca name=\"buildstatic\"\u003e\u003c/a\u003e\n\nLinking with \"-static-libgo\" will yield a binary that incorporates a full copy of the Go runtime. Example:\n\n```\n % go build -gccgoflags -static-libgo myprogram.go\n```\n\nNote that this will increase binary size.\n\n## What command line options are supported for gollvm?  \u003ca name=\"cmdlineopts\"\u003e\u003c/a\u003e\n\nYou can run 'llvm-goc -help' to see a full set of supported options. These can be passed to the compiler via '-gccgoflags' option. Example:\n\n```\n% go build -gccgoflags -fno-inline mumble.go\n```\n\n## How do I see the LLVM IR generated by gollvm?  \u003ca name=\"seetheir\"\u003e\u003c/a\u003e\n\nThe 'llvm-goc' command supports the -emit-llvm flag, however passing this option\nto a \"go build\" command is not practical, since the \"go build\" won't be\nexpecting the compiler to emit LLVM bitcode or assembly.\n\nA better recipe is to run \"go build\" with \"-x -work\" to capture the commands\nbeing executed, then rerun the llvm-goc command shown adding \"-S -emit-llvm\".\nThe resulting output will be an LLVM IR dump. Example:\n\n```\n% go build -work -x mypackage.go 1\u003e transcript.txt 2\u003e\u00261\n% egrep '(WORK=|llvm-goc -c)' transcript.txt\nWORK=/tmp/go-build887931787\n/t/bin/llvm-goc -c -g -m64 -fdebug-prefix-map=$WORK=/tmp/go-build \\\n  -gno-record-gcc-switches -fgo-pkgpath=command-line-arguments \\\n  -fgo-relative-import-path=/mygopath/src/tmp -o $WORK/b001/_go_.o \\\n  -I $WORK/b001/_importcfgroot_ ./mypackage.go\n% /t/bin/llvm-goc -c -g -m64 -fdebug-prefix-map=$WORK=/tmp/go-build \\\n  -gno-record-gcc-switches -fgo-pkgpath=command-line-arguments \\\n  -fgo-relative-import-path=/mygopath/src/tmp \\\n  -I $WORK/b001/_importcfgroot_ -o mypackage.ll -S -emit-llvm \\\n  ./mypackage.go\n% ls -l mypackage.ll\n...\n%\n```\n\n\n## What is the relationship between gollvm and gccgo?  \u003ca name=\"gollvmandgccgo\"\u003e\u003c/a\u003e\n\nGollvm and gccgo share a common front end (gofrontend) and associated runtime\n(libgo), however each uses a separate back end. When using \"go build\", the Go\ncommand currently treats gollvm as an instance of gccgo (hence the need to pass\ncompile flags via \"-gccgoflags\"). This is expected to be temporary.\n\n## Can I use FDO or ThinLTO with gollvm?  \u003ca name=\"thinltofdo\"\u003e\u003c/a\u003e\n\nThere are plans to support FDO, AutoFDO, and ThinLTO for gollvm, however these features have not yet been implemented.\n\n## Can I use the race detector?  \u003ca name=\"racedetector\"\u003e\u003c/a\u003e\n\nGollvm does not support the Go race detector; please use the main Go compiler for this purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzchee%2Fgolang-gollvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzchee%2Fgolang-gollvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzchee%2Fgolang-gollvm/lists"}