mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
495a351e10
perf(build): enable size_optimize_config on 130 SO targets
Created-by: RuiChen_01
Commit-by: RuiChen_01
Merged-by: openharmony_ci
Description: **IssueNo**:
**Description**:
Enable size optimization on the 130 SO targets that previously shipped without any optimization config (audit list attached in review discussions).
New `services/common:size_optimize_config`:
- `-Oz`, `-fdata-sections`, `-ffunction-sections`, `-fstack-protector-strong`, `-D_FORTIFY_SOURCE=2` + `-Wl,--gc-sections`
- **No explicit `-flto`** — the toolchain already forces ThinLTO globally (`build/config/compiler`), and targets must not override the LTO mode; this config only adds per-function/data-section granularity so the linker drops unreferenced code, shrinking ROM without touching link policy.
Applied to 130 `ohos_shared_library` targets across:
- frameworks/js/napi, frameworks/ets/ani, frameworks/cj (ffi + extension modules)
- agent_runtime_framework (9 SOs)
- ets_environment, cj_environment
- interfaces/inner_api (ability_manager parts, error_utils, base contexts, deps_wrapper, page_config_manager, insight intent client)
- services: libappms, libupms(+plugins), perm_verification, hisysevent_report, user_controller
- service_router_framework: libsrms, srms_fwk
- utils: runtime_utils, freeze_util, startup_util
Notes:
- The 8 cj ffi targets already carrying `-O2` keep their target-level flag ordering (target flags win over configs; they still gain sections + gc-sections).
- The 110 existing `optimize_config` users are intentionally untouched.
- Insertion verified programmatically: every `configs +=` line lands inside its intended target block (0 misplaced after fix; conditional `if(){}`-wrapped module targets handled via brace-matching, not column-0 heuristics).
Net: 98 files, +155 lines, no behavior change beyond size optimization.
**稳定性自检:**
| 自检项 | 自检结果 |
|---|---|
| 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发 | N/A |
| 成员变量进行赋值或创建需要排查并发 | N/A |
| 谨慎在lambda表达式中使用引用捕获 | N/A |
| 谨慎在未经拷贝的情况下使用外部传入的string、C字符串 | N/A |
| map\vector\list\set等stl模板类使用时需要排查并发 | N/A |
| 谨慎考虑加锁范围 | N/A |
| 在IPC通信中谨慎使用同步通信方式 | N/A |
| 禁止传递this指针至其他模块或线程 | N/A |
| 禁止将外部传入的裸指针在内部直接构造智能指针 | N/A |
| 禁止多个独立创建的智能指针管理同一地址 | N/A |
| 禁止在析构函数中抛异步任务 | N/A |
| 禁止js对象在非js线程创建、使用或销毁 | N/A |
| 禁止在对外接口中未经判空直接使用外部传入的指针 | N/A |
| 禁止接口返回局部变量引用 | N/A |
| 禁止在信号函数中加锁 | N/A |
| 禁止在关键流程执行耗时操作 | OK(仅编译选项) |
| 禁止将同一个cpp编译在不同的so中 | N/A |
**安全编码自检:**
| 自检项 | 自检结果 |
|---|---|
| 裸指针避免通过隐式转换构造为sptr | N/A |
| json对象取值前先判断类型 | N/A |
| 序列化校验数组大小 | N/A |
| 使用明确位宽整型 | N/A |
| 外部路径规范化校验 | N/A |
| 变量赋初值 | N/A |
| readParcelable判空 | N/A |
| 内存分配释放成对 | N/A |
| 异常退出内存释放 | N/A |
| 内存大小合法性校验 | N/A |
| 分配后判成功 | N/A |
| 禁止realloc/alloca | N/A |
| 禁止打印敏感信息 | N/A |
| 禁止打印内存地址 | N/A |
| 整数运算防溢出 | N/A |
| 禁止有符号位操作 | N/A |
| 禁止指针逻辑/位运算 | N/A |
| 外部控制循环次数需校验 | N/A |
| 禁止内存操作危险函数 | N/A |
| 谨慎不可重入函数 | N/A |
| 检查安全函数返回值 | N/A |
| 禁止仅凭TokenType绕过权限校验 | N/A |
See merge request: openharmony/ability_ability_runtime!20226