使用 $Super$$ 和 $Sub$$ 覆盖符号定义

在某些情况下,无法修改现有符号,例如,由于符号位于外部库或 ROM 代码中。可以使用 $Super$$ 和 $Sub$$ 模式来修补现有符号。

例如,要修补函数 foo() 的定义,请按如下方式使用 $Super$$foo() 和 $Sub$$foo():

$Super$$foo

标识未修补的原始函数 foo()。 使用它可以直接调用原函数。

标识未修补的原始函数 foo()。 使用它可以直接调用原函数。
$Sub$$foo

标识调用的新函数,而不是原始函数 foo()。可以使用此模式在原始函数之前或之后添加处理。

标识调用的新函数,而不是原始函数 foo()。可以使用此模式在原始函数之前或之后添加处理。
$Super$$foo 标识未修补的原始函数 foo()。 使用它可以直接调用原函数。 $Sub$$foo 标识调用的新函数,而不是原始函数 foo()。可以使用此模式在原始函数之前或之后添加处理。

$Sub 和 $Super 机制只在静态链接时起作用,$Super$$ 引用无法导入或导出到动态符号表中。

$Sub 和 $Super 机制只在静态链接时起作用,$Super$$ 引用无法导入或导出到动态符号表中。

例如:

extern void ExtraFunc(void); extern void $Super$$foo(void): /* this function is called instead of the original foo() */ void $Sub$$foo(void) { ExtraFunc(); /* does some extra setup work */ $Super$$foo(); /* calls the original foo() function */ }

摘自<ELF for arm..>

A symbol $Sub$$name is the sub-class version of name. A symbol $Super$$name is the super-class version of name. In the presence of a defintion of both name and $Sub$$name:

1. A reference to name resovles to the definition of $Sub$$name. 2. A reference to $Super$$name resolves to the definition of name.

It is an error to refer to $Sub$$name, or to define $Super$$name, or to use $Sub$$… or $Super$$… recursively. A platform standard may mandate support of sub- and super-class symbols. There are outstanding defects for sub- and super-class symbols DE-316140.

经验分享 程序员 微信小程序 职场和发展