aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-10-12 22:05:38 +0000
committerRon Evans <[email protected]>2022-10-19 22:23:19 +0200
commit0ddcf4af96a9bf89d27678531c8215981f90807d (patch)
tree0e122ea614364177d18892abbe79b9b991c65820 /compiler
parentd435fc868b9caef76b7a9b30a9c33adc3a79cab4 (diff)
downloadtinygo-0ddcf4af96a9bf89d27678531c8215981f90807d.tar.gz
tinygo-0ddcf4af96a9bf89d27678531c8215981f90807d.zip
riscv: add "target-abi" metadata flag
This flag is necessary in LLVM 15 because it appears that LLVM 15 has changed the default target ABI from lp64 to lp64d. This results in a linker failure. Setting the "target-abi" forces the RISC-V backend to use the intended target ABI.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/compiler.go13
-rw-r--r--compiler/compiler_test.go1
2 files changed, 14 insertions, 0 deletions
diff --git a/compiler/compiler.go b/compiler/compiler.go
index fc47c29c1..8b6e86619 100644
--- a/compiler/compiler.go
+++ b/compiler/compiler.go
@@ -41,6 +41,7 @@ type Config struct {
Triple string
CPU string
Features string
+ ABI string
GOOS string
GOARCH string
CodeModel string
@@ -321,6 +322,18 @@ func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package,
c.dibuilder.Destroy()
}
+ // Add the "target-abi" flag, which is necessary on RISC-V otherwise it will
+ // pick one that doesn't match the -mabi Clang flag.
+ if c.ABI != "" {
+ c.mod.AddNamedMetadataOperand("llvm.module.flags",
+ c.ctx.MDNode([]llvm.Metadata{
+ llvm.ConstInt(c.ctx.Int32Type(), 1, false).ConstantAsMetadata(), // Error on mismatch
+ c.ctx.MDString("target-abi"),
+ c.ctx.MDString(c.ABI),
+ }),
+ )
+ }
+
return c.mod, c.diagnostics
}
diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go
index 2ed26921f..a5cd9c6bf 100644
--- a/compiler/compiler_test.go
+++ b/compiler/compiler_test.go
@@ -73,6 +73,7 @@ func TestCompiler(t *testing.T) {
compilerConfig := &Config{
Triple: config.Triple(),
Features: config.Features(),
+ ABI: config.ABI(),
GOOS: config.GOOS(),
GOARCH: config.GOARCH(),
CodeModel: config.CodeModel(),