diff options
author | Xi Ruoyao <xry111@xry111.site> | 2022-09-01 18:38:14 +0800 |
---|---|---|
committer | Xi Ruoyao <xry111@xry111.site> | 2022-09-05 18:11:13 +0800 |
commit | 7742b797b3fd7acea28a0a0bff9bbb06e7c2d0ea (patch) | |
tree | fe622afbfde464c3de2fc07105e57bb159eb6ae4 /gcc/config | |
parent | 9c805ddf66a1cfc93e6cc65f768897da2bc303ed (diff) | |
download | gcc-7742b797b3fd7acea28a0a0bff9bbb06e7c2d0ea.zip gcc-7742b797b3fd7acea28a0a0bff9bbb06e7c2d0ea.tar.gz gcc-7742b797b3fd7acea28a0a0bff9bbb06e7c2d0ea.tar.bz2 |
LoongArch: add -mdirect-extern-access option
As a new target, LoongArch does not use copy relocation as it's
problematic in some circumstances. One bad consequence is we are
emitting GOT for all accesses to all extern objects with default
visibility. The use of GOT is not needed in statically linked
executables, OS kernels etc. The GOT entry just wastes space, and the
GOT access just slow down the execution in those environments.
Before -mexplicit-relocs, we used "-Wa,-mla-global-with-pcrel" to tell
the assembler not to use GOT for extern access. But with
-mexplicit-relocs, we have to opt the logic in GCC.
The name "-mdirect-extern-access" is learnt from x86 port.
gcc/ChangeLog:
* config/loongarch/genopts/loongarch.opt.in: Add
-mdirect-extern-access option.
* config/loongarch/loongarch.opt: Regenerate.
* config/loongarch/loongarch.cc
(loongarch_symbol_binds_local_p): Return true if
TARGET_DIRECT_EXTERN_ACCESS.
(loongarch_option_override_internal): Complain if
-mdirect-extern-access is used with -fPIC or -fpic.
* doc/invoke.texi: Document -mdirect-extern-access for
LoongArch.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/direct-extern-1.c: New test.
* gcc.target/loongarch/direct-extern-2.c: New test.
Diffstat (limited to 'gcc/config')
-rw-r--r-- | gcc/config/loongarch/genopts/loongarch.opt.in | 4 | ||||
-rw-r--r-- | gcc/config/loongarch/loongarch.cc | 6 | ||||
-rw-r--r-- | gcc/config/loongarch/loongarch.opt | 4 |
3 files changed, 14 insertions, 0 deletions
diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in index ebdd953..e106187 100644 --- a/gcc/config/loongarch/genopts/loongarch.opt.in +++ b/gcc/config/loongarch/genopts/loongarch.opt.in @@ -184,3 +184,7 @@ Enum(cmodel) String(@@STR_CMODEL_EXTREME@@) Value(CMODEL_EXTREME) mcmodel= Target RejectNegative Joined Enum(cmodel) Var(la_opt_cmodel) Init(CMODEL_NORMAL) Specify the code model. + +mdirect-extern-access +Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0) +Avoid using the GOT to access external symbols. diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 77e3a10..c9187bf 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -1610,6 +1610,9 @@ loongarch_weak_symbol_p (const_rtx x) bool loongarch_symbol_binds_local_p (const_rtx x) { + if (TARGET_DIRECT_EXTERN_ACCESS) + return true; + if (SYMBOL_REF_P (x)) return (SYMBOL_REF_DECL (x) ? targetm.binds_local_p (SYMBOL_REF_DECL (x)) @@ -6093,6 +6096,9 @@ loongarch_option_override_internal (struct gcc_options *opts) if (loongarch_branch_cost == 0) loongarch_branch_cost = loongarch_cost->branch_cost; + if (TARGET_DIRECT_EXTERN_ACCESS && flag_shlib) + error ("%qs cannot be used for compiling a shared library", + "-mdirect-extern-access"); switch (la_target.cmodel) { diff --git a/gcc/config/loongarch/loongarch.opt b/gcc/config/loongarch/loongarch.opt index 6395234..96c811c 100644 --- a/gcc/config/loongarch/loongarch.opt +++ b/gcc/config/loongarch/loongarch.opt @@ -191,3 +191,7 @@ Enum(cmodel) String(extreme) Value(CMODEL_EXTREME) mcmodel= Target RejectNegative Joined Enum(cmodel) Var(la_opt_cmodel) Init(CMODEL_NORMAL) Specify the code model. + +mdirect-extern-access +Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0) +Avoid using the GOT to access external symbols. |