linux-uconsole/include
Russ Dill 2ecab0b339 PIE: Support embedding position independent executables
This commit adds support for embedding PIEs into the kernel, loading them
into genalloc sections, performing necessary relocations, and running code
from them. This allows platforms that need to run code from SRAM, such
an during suspend/resume, to develop that code in C instead of assembly.

Functions and data for each PIE should be grouped into sections with the
__pie(<group>) and __pie_data(<group>) macros respectively. Any symbols or
functions that are to be accessed from outside the PIE should be marked with
EXPORT_PIE_SYMBOL(<sym>). For example:

static struct ddr_timings xyz_timings __pie_data(platformxyz) = {
	[...]
};

void __pie(platformxyz) xyz_ddr_on(void *addr)
{
	[...]
}
EXPORT_PIE_SYMBOL(xyz_ddr_on);

While the kernel can access exported symbols from the PIE, the PIE cannot
access symbols from the kernel, but can access data from the kernel and
call functions in the kernel so long as addresses are passed into the PIE.

PIEs are loaded from the kernel into a genalloc pool with pie_load_sections.
pie_load_sections allocates space within the pool, copies the neccesary
code/data, and performs any necessary relocations. A chunk identifier is
returned for removing the PIE from the pool, and for translating symbols.

Because the PIEs are dynamically relocated, special accessors must be used
to access PIE symbols from kernel code:

- kern_to_pie(chunk, ptr):   Translate a PIE symbol to the virtual address
                             it is loaded into within the pool.

- fn_to_pie(chunk, ptr):     Same as above, but for function pointers.

- sram_to_phys(chunk, addr): Translate a virtual address within a loaded PIE
                             to a physical address.

Loading a PIE involves three main steps. First a set of common functions to
cover built-ins emitted by gcc (memcpy, memmove, etc) is copied into the pool.
Then the actual PIE code and data is copied into the pool. Because the PIE
code is contained within an overlay with other PIEs, offsets to the common
functions are maintained. Finally, relocations are performed as necessary.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
2013-11-21 13:39:21 +08:00
..
acpi rk: revert 20f3d0b+v3.0.66 to v3.0 2013-11-08 21:34:05 +08:00
asm-generic PIE: Support embedding position independent executables 2013-11-21 13:39:21 +08:00
clocksource ARM: late Exynos multiplatform changes 2013-05-07 11:28:42 -07:00
crypto
drm rk: revert 20f3d0b+v3.0.66 to v3.0 2013-11-08 21:34:05 +08:00
dt-bindings
keys
linux PIE: Support embedding position independent executables 2013-11-21 13:39:21 +08:00
math-emu
media rk: temp revert rk change 2013-11-08 21:33:42 +08:00
memory
misc
net rk: revert 20f3d0b+v3.0.66 to v3.0 2013-11-08 21:34:05 +08:00
pcmcia
ras
rdma
rxrpc
scsi Merge branch 'postmerge' into for-linus 2013-05-10 07:54:01 -07:00
sound rk: revert 20f3d0b+v3.0.66 to v3.0 2013-11-08 21:34:05 +08:00
target rk: revert 20f3d0b+v3.0.66 to v3.0 2013-11-08 21:34:05 +08:00
trace Merge remote-tracking branch 'origin/upstream/linux-linaro-lsk-v3.10-android+android-common-3.10' into develop-3.10 2013-11-11 14:38:40 +08:00
uapi Merge remote-tracking branch 'origin/upstream/linux-linaro-lsk-v3.10-android' into linux-linaro-lsk-v3.10-android+android-common-3.10 2013-11-21 13:26:29 +08:00
video rk: revert 20f3d0b+v3.0.66 to v3.0 2013-11-08 21:34:05 +08:00
xen rk: revert 20f3d0b+v3.0.66 to v3.0 2013-11-08 21:34:05 +08:00
Kbuild UAPI: remove empty Kbuild files 2013-04-30 17:04:09 -07:00