Codebase list klibc / e25809b
[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
2 changed file(s) with 21 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
7979 * CONFIG_REGPARM (bool): Optimise function calls by passing the first
8080 3 function parameters in registers.
8181
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
8288 Building without kernel source
8389 ------------------------------
8490
1212
1313 # Extra linkflags when building the shared version of the library
1414 # 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)
2026 KLIBCSHAREDFLAGS = $(LD_IMAGE_BASE_OPT) 0x12FE00000
27 else
28 KLIBCARCHREQFLAGS += -mcompact-branches=optimal
29 KLIBCSHAREDFLAGS = $(LD_IMAGE_BASE_OPT) 0x127E00000
30 endif
2131
2232 # Kernel uses vDSO for signal return since 2.6.34
2333 KLIBCEXECSTACK := n