mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 16:33:40 +00:00
compiler: add nounwind attribute
This attribute is also set by Clang when it compiles C source files (unless -fexceptions is set). The advantage is that no unwind tables are emitted on Linux (and perhaps other systems). It also avoids __aeabi_unwind_cpp_pr0 on ARM when using the musl libc.
This commit is contained in:
committed by
Ron Evans
parent
112b369636
commit
478dd3a28d
@@ -323,6 +323,21 @@ func getParams(sig *types.Signature) []*types.Var {
|
||||
return params
|
||||
}
|
||||
|
||||
// addStandardAttributes adds the set of attributes that are added to every
|
||||
// function emitted by TinyGo (even thunks/wrappers), possibly depending on the
|
||||
// architecture.
|
||||
func (c *compilerContext) addStandardAttributes(llvmFn llvm.Value) {
|
||||
// TinyGo does not currently raise exceptions, so set the 'nounwind' flag.
|
||||
// This behavior matches Clang when compiling C source files.
|
||||
// It reduces binary size on Linux a little bit on non-x86_64 targets by
|
||||
// eliminating exception tables for these functions.
|
||||
llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nounwind"), 0))
|
||||
if strings.Split(c.Triple, "-")[0] == "x86_64" {
|
||||
// Required by the ABI.
|
||||
llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("uwtable"), 0))
|
||||
}
|
||||
}
|
||||
|
||||
// globalInfo contains some information about a specific global. By default,
|
||||
// linkName is equal to .RelString(nil) on a global and extern is false, but for
|
||||
// some symbols this is different (due to //go:extern for example).
|
||||
|
||||
Reference in New Issue
Block a user