compiler: Implement -ffunction-sections work
Этот коммит содержится в:
родитель
f7c2d0124d
коммит
5bbd41e9fb
2 изменённых файлов: 13 добавлений и 1 удалений
2
Makefile
2
Makefile
|
@ -18,7 +18,7 @@ TARGET ?= unix
|
||||||
|
|
||||||
ifeq ($(TARGET),pca10040)
|
ifeq ($(TARGET),pca10040)
|
||||||
GCC = arm-none-eabi-gcc
|
GCC = arm-none-eabi-gcc
|
||||||
LD = arm-none-eabi-ld -T arm.ld
|
LD = arm-none-eabi-ld -T arm.ld --gc-sections
|
||||||
SIZE = arm-none-eabi-size
|
SIZE = arm-none-eabi-size
|
||||||
OBJCOPY = arm-none-eabi-objcopy
|
OBJCOPY = arm-none-eabi-objcopy
|
||||||
LLFLAGS += -target armv7m-none-eabi
|
LLFLAGS += -target armv7m-none-eabi
|
||||||
|
|
12
tgo.go
12
tgo.go
|
@ -1082,6 +1082,16 @@ func (c *Compiler) LinkModule(mod llvm.Module) error {
|
||||||
return llvm.LinkModules(c.mod, mod)
|
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) {
|
func (c *Compiler) Optimize(optLevel, sizeLevel int) {
|
||||||
builder := llvm.NewPassManagerBuilder()
|
builder := llvm.NewPassManagerBuilder()
|
||||||
defer builder.Dispose()
|
defer builder.Dispose()
|
||||||
|
@ -1159,6 +1169,8 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.ApplyFunctionSections() // -ffunction-sections
|
||||||
|
|
||||||
if err := c.Verify(); err != nil {
|
if err := c.Verify(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче