[klibc] mips64: Compatibility with R6 compact branches
MIPS R6 introduced compact branch instructions, including BALC as a
replacement for JAL. Both BALC and JAL have a 26-bit offset field
that's shifted 2 bits left. However, in BALC this is treated as a
PC-relative signed offset (±128 MiB) rather than a segment-relative
unsigned offset (0-256 MiB).
The base address of the klibc shared library therefore needs to change
depending on whether the executable calls it with JAL or BALC.
gcc (but not Clang, currently) generates BALC instructions for
external function calls on R6 targets, which breaks shared library
builds of klibc for these targets. Add a config symbol to control
whether compact branches are used and to change the shared library
base address accordingly.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Ben Hutchings
9 months ago
79 | 79 |
* CONFIG_REGPARM (bool): Optimise function calls by passing the first
|
80 | 80 |
3 function parameters in registers.
|
81 | 81 |
|
|
82 |
For mips64 only:
|
|
83 |
|
|
84 |
* CONFIG_KLIBC_MIPS_USE_CB (bool): Use compact branch instructions.
|
|
85 |
This should be enabled when targetting MIPS R6 and must be disabled
|
|
86 |
for older MIPS ISAs.
|
|
87 |
|
82 | 88 |
Building without kernel source
|
83 | 89 |
------------------------------
|
84 | 90 |
|
12 | 12 |
|
13 | 13 |
# Extra linkflags when building the shared version of the library
|
14 | 14 |
# This address needs to be reachable using normal inter-module
|
15 | |
# calls, and work on the memory models for this architecture
|
16 | |
# 4862 MB - normal binaries start at 4608 MB. Non-PIC jumps usually
|
17 | |
# use the JAL instruction which requires a destination within the same
|
18 | |
# 256M aligned region. Since we can't put ourselves below the normal
|
19 | |
# load address, use the very top of the 256M region (minus 2MB)
|
|
15 |
# calls, and work on the memory models for this architecture.
|
|
16 |
# Normal binaries start at 0x120000000 (4608 MiB).
|
|
17 |
# * On R5 and earlier, non-PIC jumps usually use the JAL instruction
|
|
18 |
# which requires a destination within the same 256 MiB aligned
|
|
19 |
# region. Since we can't put ourselves below the normal load
|
|
20 |
# address, use the very top of the 256 MiB region (minus 2 MiB).
|
|
21 |
# * On R6, non-PIC jumps may use either the JAL instruction or the
|
|
22 |
# BALC instruction which requires a destination within ±128 MiB. Put
|
|
23 |
# ourselves just under 128 MiB above the executable base address.
|
|
24 |
ifneq ($(CONFIG_KLIBC_MIPS_USE_CB),y)
|
|
25 |
KLIBCARCHREQFLAGS += $(call cc-option,-mcompact-branches=never)
|
20 | 26 |
KLIBCSHAREDFLAGS = $(LD_IMAGE_BASE_OPT) 0x12FE00000
|
|
27 |
else
|
|
28 |
KLIBCARCHREQFLAGS += -mcompact-branches=optimal
|
|
29 |
KLIBCSHAREDFLAGS = $(LD_IMAGE_BASE_OPT) 0x127E00000
|
|
30 |
endif
|
21 | 31 |
|
22 | 32 |
# Kernel uses vDSO for signal return since 2.6.34
|
23 | 33 |
KLIBCEXECSTACK := n
|