compiler: Implement -ffunction-sections work

This commit is contained in:
Ayke van Laethem
2018-04-27 01:27:33 +02:00
parent f7c2d0124d
commit 5bbd41e9fb
2 changed files with 13 additions and 1 deletions
+12
View File
@@ -1082,6 +1082,16 @@ func (c *Compiler) LinkModule(mod llvm.Module) error {
return llvm.LinkModules(c.mod, mod)
}
func (c *Compiler) ApplyFunctionSections() {
llvmFn := c.mod.FirstFunction()
for !llvmFn.IsNil() {
if !llvmFn.IsDeclaration() {
llvmFn.SetSection(".text." + llvmFn.Name())
}
llvmFn = llvm.NextFunction(llvmFn)
}
}
func (c *Compiler) Optimize(optLevel, sizeLevel int) {
builder := llvm.NewPassManagerBuilder()
defer builder.Dispose()
@@ -1159,6 +1169,8 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR bool) error {
return err
}
c.ApplyFunctionSections() // -ffunction-sections
if err := c.Verify(); err != nil {
return err
}