linux/arch
WANG Xuerui 38b10b269d LoongArch: Tweak CFLAGS for Clang compatibility
Now the arch code is mostly ready for LLVM/Clang consumption, it is time
to re-organize the CFLAGS a little to actually enable the LLVM build.
Namely, all -G0 switches from CFLAGS are removed, and -mexplicit-relocs
and -mdirect-extern-access are now wrapped with cc-option (with the
related asm/percpu.h definition guarded against toolchain combos that
are known to not work).

A build with !RELOCATABLE && !MODULE is confirmed working within a QEMU
environment; support for the two features are currently blocked on
LLVM/Clang, and will come later.

Why -G0 can be removed:

In GCC, -G stands for "small data threshold", that instructs the
compiler to put data smaller than the specified threshold in a dedicated
"small data" section (called .sdata on LoongArch and several other
arches).

However, benefiting from this would require ABI cooperation, which is
not the case for LoongArch; and current GCC behave the same whether -G0
(equal to disabling this optimization) is given or not. So, remove -G0
from CFLAGS altogether for one less thing to care about. This also
benefits LLVM/Clang compatibility where the -G switch is not supported.

Why -mexplicit-relocs can now be conditionally applied without
regressions:

Originally -mexplicit-relocs is unconditionally added to CFLAGS in case
of CONFIG_AS_HAS_EXPLICIT_RELOCS, because not having it (i.e. old GCC +
new binutils) would not work: modules will have R_LARCH_ABS_* relocs
inside, but given the rarity of such toolchain combo in the wild, it may
not be worthwhile to support it, so support for such relocs in modules
were not added back when explicit relocs support was upstreamed, and
-mexplicit-relocs is unconditionally added to fail the build early.

Now that Clang compatibility is desired, given Clang is behaving like
-mexplicit-relocs from day one but without support for the CLI flag, we
must ensure the flag is not passed in case of Clang. However, explicit
compiler flavor checks can be more brittle than feature detection: in
this case what actually matters is support for __attribute__((model))
when building modules. Given neither older GCC nor current Clang support
this attribute, probing for the attribute support and #error'ing out
would allow proper UX without checking for Clang, and also automatically
work when Clang support for the attribute is to be added in the future.

Why -mdirect-extern-access is now conditionally applied:

This is actually a nice-to-have optimization that can reduce GOT
accesses, but not having it is harmless either. Because Clang does not
support the option currently, but might do so in the future, conditional
application via cc-option ensures compatibility with both current and
future Clang versions.

Suggested-by: Xi Ruoyao <xry111@xry111.site> # cc-option changes
Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2023-06-29 20:58:43 +08:00
..
alpha Locking changes in v6.4: 2023-05-05 12:56:55 -07:00
arc Locking changes in v6.4: 2023-05-05 12:56:55 -07:00
arm ARM: 2023-06-22 17:54:10 -07:00
arm64 ARM: SoC fixes for 6.4, part 3 2023-06-23 16:21:59 -07:00
csky arch/csky patches for 6.4 2023-05-04 12:25:05 -07:00
hexagon Locking changes in v6.4: 2023-05-05 12:56:55 -07:00
ia64 Locking changes in v6.4: 2023-05-05 12:56:55 -07:00
loongarch LoongArch: Tweak CFLAGS for Clang compatibility 2023-06-29 20:58:43 +08:00
m68k m68k: Move signal frame following exception on 68020/030 2023-05-22 13:51:20 +02:00
microblaze Kconfig: introduce HAS_IOPORT option and select it as necessary 2023-04-05 22:15:19 +02:00
mips mips: Move initrd_start check after initrd address sanitisation. 2023-05-23 11:01:38 +02:00
nios2 nios2: dts: Fix tse_mac "max-frame-size" property 2023-06-13 16:59:46 -05:00
openrisc Locking changes in v6.4: 2023-05-05 12:56:55 -07:00
parisc parisc: Delete redundant register definitions in <asm/assembly.h> 2023-06-17 06:48:11 +02:00
powerpc powerpc fixes for 6.4 #5 2023-06-22 17:49:40 -07:00
riscv 19 hotfixes. 14 are cc:stable and the remainder address issues which were 2023-06-12 16:14:34 -07:00
s390 s390 updates for 6.4-rc6 2023-06-09 09:29:51 -07:00
sh Locking changes in v6.4: 2023-05-05 12:56:55 -07:00
sparc Locking changes in v6.4: 2023-05-05 12:56:55 -07:00
um um: harddog: fix modular build 2023-05-10 00:21:30 +02:00
x86 - Drop the __weak attribute from a function prototype as it otherwise 2023-06-25 10:13:17 -07:00
xtensa Xtensa fixes for v6.4: 2023-05-23 15:21:34 -07:00
.gitignore
Kconfig lazy tlb: shoot lazies, non-refcounting lazy tlb mm reference handling scheme 2023-03-28 16:20:08 -07:00