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(), | ||||
| 		CPU:             config.CPU(), | ||||
| 		Features:        config.Features(), | ||||
| 		ABI:             config.ABI(), | ||||
| 		GOOS:            config.GOOS(), | ||||
| 		GOARCH:          config.GOARCH(), | ||||
| 		CodeModel:       config.CodeModel(), | ||||
|  |  | |||
|  | @ -155,6 +155,9 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ | |||
| 			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.Split(target, "-")[2] == "linux" { | ||||
| 			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") | ||||
| 	} | ||||
| 	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-") { | ||||
| 		args = append(args, "-march=rv64gc", "-mabi=lp64") | ||||
| 		args = append(args, "-march=rv64gc") | ||||
| 	} | ||||
| 	if strings.HasPrefix(target, "xtensa") { | ||||
| 		// 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 | ||||
| } | ||||
| 
 | ||||
| // 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: | ||||
| // for example, bare-metal targets will usually pretend to be linux to get the | ||||
| // standard library to compile. | ||||
|  | @ -230,6 +236,9 @@ func (c *Config) LibcPath(name string) (path string, precompiled bool) { | |||
| 	if c.CPU() != "" { | ||||
| 		archname += "-" + c.CPU() | ||||
| 	} | ||||
| 	if c.ABI() != "" { | ||||
| 		archname += "-" + c.ABI() | ||||
| 	} | ||||
| 
 | ||||
| 	// Try to load a precompiled library. | ||||
| 	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) | ||||
| 		} | ||||
| 	} | ||||
| 	// Set the -mabi flag, if needed. | ||||
| 	if c.ABI() != "" { | ||||
| 		cflags = append(cflags, "-mabi="+c.ABI()) | ||||
| 	} | ||||
| 	return cflags | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ type TargetSpec struct { | |||
| 	Inherits         []string `json:"inherits"` | ||||
| 	Triple           string   `json:"llvm-target"` | ||||
| 	CPU              string   `json:"cpu"` | ||||
| 	ABI              string   `json:"target-abi"` // rougly equivalent to -mabi= flag | ||||
| 	Features         string   `json:"features"` | ||||
| 	GOOS             string   `json:"goos"` | ||||
| 	GOARCH           string   `json:"goarch"` | ||||
|  |  | |||
|  | @ -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 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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(), | ||||
|  |  | |||
|  | @ -1,12 +1,12 @@ | |||
| { | ||||
| 	"inherits": ["riscv"], | ||||
| 	"llvm-target": "riscv32-unknown-none", | ||||
| 	"target-abi": "ilp32", | ||||
| 	"build-tags": ["tinygo.riscv32"], | ||||
| 	"scheduler": "tasks", | ||||
| 	"default-stack-size": 2048, | ||||
| 	"cflags": [ | ||||
| 		"-march=rv32imac", | ||||
| 		"-mabi=ilp32" | ||||
| 		"-march=rv32imac" | ||||
| 	], | ||||
| 	"ldflags": [ | ||||
| 		"-melf32lriscv" | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| { | ||||
| 	"inherits": ["riscv"], | ||||
| 	"llvm-target": "riscv64-unknown-none", | ||||
| 	"target-abi": "lp64", | ||||
| 	"build-tags": ["tinygo.riscv64"], | ||||
| 	"cflags": [ | ||||
| 		"-march=rv64gc", | ||||
| 		"-mabi=lp64" | ||||
| 		"-march=rv64gc" | ||||
| 	], | ||||
| 	"ldflags": [ | ||||
| 		"-melf64lriscv" | ||||
|  |  | |||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Ayke van Laethem
						Ayke van Laethem