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.
Этот коммит содержится в:
родитель
d435fc868b
коммит
0ddcf4af96
8 изменённых файлов: 38 добавлений и 6 удалений
|
@ -163,6 +163,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
||||||
Triple: config.Triple(),
|
Triple: config.Triple(),
|
||||||
CPU: config.CPU(),
|
CPU: config.CPU(),
|
||||||
Features: config.Features(),
|
Features: config.Features(),
|
||||||
|
ABI: config.ABI(),
|
||||||
GOOS: config.GOOS(),
|
GOOS: config.GOOS(),
|
||||||
GOARCH: config.GOARCH(),
|
GOARCH: config.GOARCH(),
|
||||||
CodeModel: config.CodeModel(),
|
CodeModel: config.CodeModel(),
|
||||||
|
|
|
@ -155,6 +155,9 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
|
||||||
args = append(args, "-mcpu="+cpu)
|
args = append(args, "-mcpu="+cpu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if config.ABI() != "" {
|
||||||
|
args = append(args, "-mabi="+config.ABI())
|
||||||
|
}
|
||||||
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
|
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
|
||||||
if strings.Split(target, "-")[2] == "linux" {
|
if strings.Split(target, "-")[2] == "linux" {
|
||||||
args = append(args, "-fno-unwind-tables", "-fno-asynchronous-unwind-tables")
|
args = append(args, "-fno-unwind-tables", "-fno-asynchronous-unwind-tables")
|
||||||
|
@ -170,10 +173,10 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
|
||||||
args = append(args, "-mdouble=64")
|
args = append(args, "-mdouble=64")
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(target, "riscv32-") {
|
if strings.HasPrefix(target, "riscv32-") {
|
||||||
args = append(args, "-march=rv32imac", "-mabi=ilp32", "-fforce-enable-int128")
|
args = append(args, "-march=rv32imac", "-fforce-enable-int128")
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(target, "riscv64-") {
|
if strings.HasPrefix(target, "riscv64-") {
|
||||||
args = append(args, "-march=rv64gc", "-mabi=lp64")
|
args = append(args, "-march=rv64gc")
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(target, "xtensa") {
|
if strings.HasPrefix(target, "xtensa") {
|
||||||
// Hack to work around an issue in the Xtensa port:
|
// Hack to work around an issue in the Xtensa port:
|
||||||
|
|
|
@ -47,6 +47,12 @@ func (c *Config) Features() string {
|
||||||
return c.Target.Features + "," + c.Options.LLVMFeatures
|
return c.Target.Features + "," + c.Options.LLVMFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ABI returns the -mabi= flag for this target (like -mabi=lp64). A zero-length
|
||||||
|
// string is returned if the target doesn't specify an ABI.
|
||||||
|
func (c *Config) ABI() string {
|
||||||
|
return c.Target.ABI
|
||||||
|
}
|
||||||
|
|
||||||
// GOOS returns the GOOS of the target. This might not always be the actual OS:
|
// GOOS returns the GOOS of the target. This might not always be the actual OS:
|
||||||
// for example, bare-metal targets will usually pretend to be linux to get the
|
// for example, bare-metal targets will usually pretend to be linux to get the
|
||||||
// standard library to compile.
|
// standard library to compile.
|
||||||
|
@ -230,6 +236,9 @@ func (c *Config) LibcPath(name string) (path string, precompiled bool) {
|
||||||
if c.CPU() != "" {
|
if c.CPU() != "" {
|
||||||
archname += "-" + c.CPU()
|
archname += "-" + c.CPU()
|
||||||
}
|
}
|
||||||
|
if c.ABI() != "" {
|
||||||
|
archname += "-" + c.ABI()
|
||||||
|
}
|
||||||
|
|
||||||
// Try to load a precompiled library.
|
// Try to load a precompiled library.
|
||||||
precompiledDir := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", archname, name)
|
precompiledDir := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", archname, name)
|
||||||
|
@ -338,6 +347,10 @@ func (c *Config) CFlags() []string {
|
||||||
cflags = append(cflags, "-mcpu="+c.Target.CPU)
|
cflags = append(cflags, "-mcpu="+c.Target.CPU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Set the -mabi flag, if needed.
|
||||||
|
if c.ABI() != "" {
|
||||||
|
cflags = append(cflags, "-mabi="+c.ABI())
|
||||||
|
}
|
||||||
return cflags
|
return cflags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ type TargetSpec struct {
|
||||||
Inherits []string `json:"inherits"`
|
Inherits []string `json:"inherits"`
|
||||||
Triple string `json:"llvm-target"`
|
Triple string `json:"llvm-target"`
|
||||||
CPU string `json:"cpu"`
|
CPU string `json:"cpu"`
|
||||||
|
ABI string `json:"target-abi"` // rougly equivalent to -mabi= flag
|
||||||
Features string `json:"features"`
|
Features string `json:"features"`
|
||||||
GOOS string `json:"goos"`
|
GOOS string `json:"goos"`
|
||||||
GOARCH string `json:"goarch"`
|
GOARCH string `json:"goarch"`
|
||||||
|
|
|
@ -41,6 +41,7 @@ type Config struct {
|
||||||
Triple string
|
Triple string
|
||||||
CPU string
|
CPU string
|
||||||
Features string
|
Features string
|
||||||
|
ABI string
|
||||||
GOOS string
|
GOOS string
|
||||||
GOARCH string
|
GOARCH string
|
||||||
CodeModel string
|
CodeModel string
|
||||||
|
@ -321,6 +322,18 @@ func CompilePackage(moduleName string, pkg *loader.Package, ssaPkg *ssa.Package,
|
||||||
c.dibuilder.Destroy()
|
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
|
return c.mod, c.diagnostics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ func TestCompiler(t *testing.T) {
|
||||||
compilerConfig := &Config{
|
compilerConfig := &Config{
|
||||||
Triple: config.Triple(),
|
Triple: config.Triple(),
|
||||||
Features: config.Features(),
|
Features: config.Features(),
|
||||||
|
ABI: config.ABI(),
|
||||||
GOOS: config.GOOS(),
|
GOOS: config.GOOS(),
|
||||||
GOARCH: config.GOARCH(),
|
GOARCH: config.GOARCH(),
|
||||||
CodeModel: config.CodeModel(),
|
CodeModel: config.CodeModel(),
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"inherits": ["riscv"],
|
"inherits": ["riscv"],
|
||||||
"llvm-target": "riscv32-unknown-none",
|
"llvm-target": "riscv32-unknown-none",
|
||||||
|
"target-abi": "ilp32",
|
||||||
"build-tags": ["tinygo.riscv32"],
|
"build-tags": ["tinygo.riscv32"],
|
||||||
"scheduler": "tasks",
|
"scheduler": "tasks",
|
||||||
"default-stack-size": 2048,
|
"default-stack-size": 2048,
|
||||||
"cflags": [
|
"cflags": [
|
||||||
"-march=rv32imac",
|
"-march=rv32imac"
|
||||||
"-mabi=ilp32"
|
|
||||||
],
|
],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"-melf32lriscv"
|
"-melf32lriscv"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"inherits": ["riscv"],
|
"inherits": ["riscv"],
|
||||||
"llvm-target": "riscv64-unknown-none",
|
"llvm-target": "riscv64-unknown-none",
|
||||||
|
"target-abi": "lp64",
|
||||||
"build-tags": ["tinygo.riscv64"],
|
"build-tags": ["tinygo.riscv64"],
|
||||||
"cflags": [
|
"cflags": [
|
||||||
"-march=rv64gc",
|
"-march=rv64gc"
|
||||||
"-mabi=lp64"
|
|
||||||
],
|
],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"-melf64lriscv"
|
"-melf64lriscv"
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче