Skip to content

embed:reduce binary size #1571

@luoliwoshang

Description

@luoliwoshang

background

esp32c3/esp32 target

will got DRAM overflowed

ld.lld: error: region DRAM overflowed by .data and .bss sections
ld.lld: error: region DRAM overflowed by .data and .bss sections
ld.lld: error: region DRAM overflowed by .data and .bss sections
ld.lld: error: region DRAM overflowed by .data and .bss sections

related issue

resolution


Reflect Keep Live

 type Foo struct{}

  func (f *Foo) Method1() { println("1") }
  func (f *Foo) Method2() { println("2") }  // no body call
  func (f *Foo) method3() { println("3") }  // private

  func main() {
      f := &Foo{}

     // convert to interface
      v := reflect.ValueOf(f)

      // compile know it convert to a interface ! keep all public method!
  }

直接调用:有显式调用或被内联展开的函数,会被标记可达,不会裁。

  • 接口路径:被接口断言/转换用到的类型,其匹配到的接口方法(R_USEIFACE、R_USEIFACEMETHOD、R_METHODOFF)会被标记可达;否则方法表入口写成 -1。
  • 反射路径:一旦遇到反射 Method/MethodByName/Call 等 ReflectMethod 标记或常量方法名重定位,已可达类型的导出方法(动态链接则全部方法)会被标记可达;否则可能被裁。
  • 动态导出/插件/根符号:main/runtime 必需、导出/插件符号、unreachableMethod 本身为根,一定保留。
  • 其他:未被上述路径触达的函数/方法(含跨包未导出、未通过接口/反射用到)会被 deadcode 判为不可达,方法表的 Ifn/Tfn 写成 -1,正文不排版进最终二进制;被弱引用且未达的
    普通符号也会被忽略/重定向。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions