]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: add model attribute
authorXi Ruoyao <xry111@xry111.site>
Fri, 29 Jul 2022 13:45:40 +0000 (21:45 +0800)
committerXi Ruoyao <xry111@xry111.site>
Thu, 25 Aug 2022 11:00:41 +0000 (19:00 +0800)
commit362749184c4fa67ea0b2135d4cae8f1a13208b9d
tree1bd015b41d3e2da7a4edf6a6e3c7303eecd2e145
parenta45b7b19e1364dd7b0066df49d458b05ba3c72d1
LoongArch: add model attribute

A linker script and/or a section attribute may locate some object
specially, so we need to handle the code model for such objects
differently than the -mcmodel setting. This happens when the Linux
kernel loads a module with per-CPU variables.

Add an attribute to override the code model for a specific variable.

gcc/ChangeLog:

* config/loongarch/loongarch-protos.h (loongarch_symbol_type):
Add SYMBOL_PCREL64 and change the description for SYMBOL_PCREL.
* config/loongarch/loongarch.cc (loongarch_attribute_table):
New attribute table.
(TARGET_ATTRIBUTE_TABLE): Define the target hook.
(loongarch_handle_model_attribute): New static function.
(loongarch_classify_symbol): Take TARGET_CMODEL_EXTREME and the
model attribute of SYMBOL_REF_DECL into account returning
SYMBOL_PCREL or SYMBOL_PCREL64.
(loongarch_use_anchors_for_symbol_p): New static function.
(TARGET_USE_ANCHORS_FOR_SYMBOL_P): Define the target hook.
(loongarch_symbol_extreme_p): New static function.
(loongarch_symbolic_constant_p): Handle SYMBOL_PCREL64.
(loongarch_symbol_insns): Likewise.
(loongarch_split_symbol_type): Likewise.
(loongarch_split_symbol): Check SYMBOL_PCREL64 instead of
TARGET_CMODEL_EXTREME for PC-relative addressing.
(loongarch_print_operand_reloc): Likewise.
* doc/extend.texi (Variable Attributes): Document new
LoongArch specific attribute.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/attr-model-test.c: New test.
* gcc.target/loongarch/attr-model-1.c: New test.
* gcc.target/loongarch/attr-model-2.c: New test.
* gcc.target/loongarch/attr-model-diag.c: New test.
gcc/config/loongarch/loongarch-protos.h
gcc/config/loongarch/loongarch.cc
gcc/doc/extend.texi
gcc/testsuite/gcc.target/loongarch/attr-model-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/attr-model-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/attr-model-diag.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/attr-model-test.c [new file with mode: 0644]