zephyr/kernel
Nicolas Pitre f9461d1ac4 mmu: fix ARM64 compilation by removing z_mapped_size usage
The linker script defines `z_mapped_size` as follows:

```
	z_mapped_size = z_mapped_end - z_mapped_start;
```

This is done with the belief that precomputed values at link time will
make the code smaller and faster.

On Aarch64, symbol values are relocated and loaded relative to the PC
as those are normally meant to be memory addresses.

Now if you have e.g. `CONFIG_SRAM_BASE_ADDRESS=0x2000000000` then
`z_mapped_size` might still have a reasonable value, say 0x59334.
But, when interpreted as an address, that's very very far from the PC
whose value is in the neighborhood of 0x2000000000. That overflows the
4GB relocation range:

```
kernel/libkernel.a(mmu.c.obj): in function `z_mem_manage_init':
kernel/mmu.c:527:(.text.z_mem_manage_init+0x1c):
relocation truncated to fit: R_AARCH64_ADR_PREL_PG_HI21
```

The solution is to define `Z_KERNEL_VIRT_SIZE` in terms of
`z_mapped_end - z_mapped_start` at the source code level. Given this
is used within loops that already start with `z_mapped_start` anyway,
the compiler is smart enough to combine the two occurrences and
dispense with a size counter, making the code effectively
slightly better for all while avoiding the Aarch64 relocation
overflow:

```
   text    data     bss     dec     hex filename
   1216       8  294936  296160   484e0 mmu.c.obj.arm64.before
   1212       8  294936  296156   484dc mmu.c.obj.arm64.after
   1110       8    9244   10362    287a mmu.c.obj.x86-64.before
   1106       8    9244   10358    2876 mmu.c.obj.x86-64.after
```

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-02-05 17:19:56 -05:00
..
include mmu: fix ARM64 compilation by removing z_mapped_size usage 2021-02-05 17:19:56 -05:00
atomic_c.c kernel: Add k_heap synchronized memory allocator 2020-04-14 10:05:55 -07:00
banner.c kernel: init: move banner handling 2020-11-27 20:08:14 -05:00
cache_handlers.c cache: Expand the APIs for cache flushing 2021-01-19 14:31:02 -05:00
CMakeLists.txt kernel: add condition variables 2021-01-19 08:55:47 -05:00
compiler_stack_protect.c tests: coverage: exclude the CODE UNREACHABLE of code coverage 2021-01-15 12:42:00 -05:00
condvar.c kernel: add vrfy hooks to support userspace with condvar 2021-01-19 08:55:47 -05:00
device.c power: standarize PM Kconfigs and cleanup 2020-12-09 15:18:29 -05:00
errno.c kernel: support using thread local storage for errno 2020-10-24 10:52:00 -07:00
fatal.c debug: coredump: remove z_ prefix for stuff used outside subsys 2021-01-21 22:08:59 -05:00
futex.c kernel/timeout: Make timeout arguments an opaque type 2020-03-31 19:40:47 -04:00
idle.c power: Remove power management conditionals from code 2021-01-22 09:31:20 -05:00
init.c Revert "kernel: init: activate FPU for main thread" 2021-02-03 17:22:50 -05:00
Kconfig kernel: Decouple TICKS_PER_SEC from TICKLESS_CAPABLE 2021-02-04 12:34:23 -05:00
kheap.c kernel: add k_heap_aligned_alloc 2020-12-08 13:21:26 -05:00
mailbox.c kernel: Remove legacy mem_pool usage 2020-12-07 21:50:14 -05:00
mem_domain.c tests: coverage: exclude the CODE UNREACHABLE of code coverage 2021-01-15 12:42:00 -05:00
mem_slab.c kernel: mem_slab: Optimize mem_slab_free 2020-12-07 11:36:48 +01:00
mempool.c z_heap_aligned_alloc(): avoid memory wastage 2021-01-22 10:04:43 -05:00
mmu.c kernel: mmu: Fix trivial typos 2021-02-04 14:00:36 -05:00
msg_q.c doc: Clarify semantics of k_msgq_put 2020-09-23 13:21:07 -05:00
mutex.c kernel: Cleanup logger setup in kernel files 2020-11-27 09:56:34 -05:00
pipes.c kernel: Remove legacy mem_pool usage 2020-12-07 21:50:14 -05:00
poll.c kernel: poll: remove unreachable code 2021-01-18 11:02:59 -05:00
queue.c kernel/queue: fix queue append/get race 2020-10-28 17:01:41 +01:00
sched.c kernel: fix usage of KERNEL_COHERENCE macro 2021-02-03 10:42:04 -05:00
sem.c device: Const-ify all device driver instance pointers 2020-09-02 13:48:13 +02:00
smp.c tests: coverage: exclude the CODE UNREACHABLE of code coverage 2021-01-15 12:42:00 -05:00
stack.c kernel: stack: fix stack_push spinlock and return 2020-10-07 17:10:36 -04:00
system_work_q.c device: Const-ify all device driver instance pointers 2020-09-02 13:48:13 +02:00
thread_abort.c tests: coverage: exclude the CODE UNREACHABLE of code coverage 2021-01-15 12:42:00 -05:00
thread.c kernel: fix usage of KERNEL_COHERENCE macro 2021-02-03 10:42:04 -05:00
timeout.c kernel: fix usage of KERNEL_COHERENCE macro 2021-02-03 10:42:04 -05:00
timer.c kernel: const-qualify objects used to calculate delay values 2021-01-22 08:05:26 -06:00
userspace_handler.c userspace: update k_object API to support immutable objects 2020-09-02 13:48:13 +02:00
userspace.c kernel: userspace: aligned memory allocation for dynamic objects 2021-01-13 09:43:55 -08:00
version.c zephyr: replace zephyr integer types with C99 types 2020-06-08 08:23:57 -05:00
work_q.c kernel: Remove CONFIG_LEGACY_TIMEOUT_API 2021-01-14 21:33:16 -05:00
xip.c linker: arm: Add cortex_m itcm section 2021-01-15 14:51:20 +01:00