ARM Technical Support Knowledge Articles

How to use $Super$$ and $Sub$$ for patching data?

Applies to: DS-5, RealView Development Suite (RVDS)

Answer

The $Sub and $Super mechanism applies to Global Symbols.

The linker applies the following transformation:
1.) Definition of $Sub$$<Symbol Name> is renamed to <Symbol Name>
2.) Original definition of <Symbol Name> is renamed to <$Super$$Name>

This has the effect of swapping $Sub$$<Symbol Name> with <Symbol Name> allowing access to the original with $Super$$<Symbol Name>.

It is not restricted to Code Symbols, although that is the most common use case. It is possible to use $Super/$Sub to patch const data as well. Please see the following example:

---test1.c---
const int aa = 0;
---end---

---test2.c
const int $Sub$$aa = 2;
---end---

---main.c---
#include <stdio.h>

extern const int aa;

int main()
{
printf("aa = %d \n", aa);
return 0;
}
---end---
[1] Command lines:

armcc -c -g test1.c main.c
armlink -o main.axf test1.o main.o

Results:
aa = 0
-----
[2] Command lines:

armcc -c -g test1.c test2.c main.c
armlink -o main.axf test1.o test2.c main.o

Results:
aa = 2


Notes:

This can be more complicated if you are trying to patch const data generated in the compiler. In general if the data is Global and visible outside the object the compiler has to label the data with a Symbol, which can in theory be "patched" by the $Sub/$Super mechanism. However we must be careful about optimisations that the compiler might make, for example if there are multiple const data symbols the compiler will load a pointer to the start of the data section and access the data as an offset from that base (base pointer sharing optimization). The $Sub/$Super mechanism will not work in this case as the compiler has not used a relocation to the name of the data.

If the code can be rewritten it is possible to prevent the compiler from using the base pointer optimisation by compiling the .constdata separately from the code accessing it.

If performance is not critical then data access could be abstracted behind a non-inline function. To patch the data, simply patch the function.

Reference:
1. Using $Super$$ and $Sub$$ to patch symbol definitions

Article last edited on: 2011-09-30 17:07:23

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential