diff --git a/0035-LoongArch-add-mdirect-extern-access-option.patch b/0035-LoongArch-add-mdirect-extern-access-option.patch new file mode 100644 index 0000000000000000000000000000000000000000..20c5714b542da6adc7b59db6ad94b4e423f50a75 --- /dev/null +++ b/0035-LoongArch-add-mdirect-extern-access-option.patch @@ -0,0 +1,158 @@ +From fb6e929e0bb21c9afcc0d3cc31ed17d386069ae8 Mon Sep 17 00:00:00 2001 +From: Li Xing +Date: Sat, 10 Sep 2022 01:40:28 +0000 +Subject: [PATCH 4/5] 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. + + From: Xi Ruoyao + +Change-Id: I8e524afce16bb93bcb30ef134714733f7b88b6f2 +--- + gcc/config/loongarch/genopts/loongarch.opt.in | 4 ++++ + gcc/config/loongarch/loongarch.c | 6 ++++++ + gcc/config/loongarch/loongarch.opt | 4 ++++ + gcc/doc/invoke.texi | 15 +++++++++++++++ + .../gcc.target/loongarch/direct-extern-1.c | 6 ++++++ + .../gcc.target/loongarch/direct-extern-2.c | 6 ++++++ + 6 files changed, 41 insertions(+) + create mode 100644 gcc/testsuite/gcc.target/loongarch/direct-extern-1.c + create mode 100644 gcc/testsuite/gcc.target/loongarch/direct-extern-2.c + +diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in +index ebdd9538d..e10618777 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.c b/gcc/config/loongarch/loongarch.c +index 7ff706ad2..24853ebca 100644 +--- a/gcc/config/loongarch/loongarch.c ++++ b/gcc/config/loongarch/loongarch.c +@@ -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)) +@@ -6090,6 +6093,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 639523421..96c811c85 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. +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index f1d573bd4..ce438011d 100644 +--- a/gcc/doc/invoke.texi ++++ b/gcc/doc/invoke.texi +@@ -950,6 +950,7 @@ Objective-C and Objective-C++ Dialects}. + -memcpy -mno-memcpy -mstrict-align @gol + -mmax-inline-memcpy-size=@var{n} @gol + -mexplicit-relocs -mno-explicit-relocs @gol ++-mdirect-extern-access -mno-direct-extern-access @gol + -mlra -mcmodel=@var{code-model}} + + @emph{M32R/D Options} +@@ -22307,6 +22308,20 @@ The text segment and data segment must be within 2GB addressing space. + This mode does not limit the size of the code segment and data segment. + The @option{-mcmodel=extreme} option is incompatible with @option{-fplt} and + @option{-mno-explicit-relocs}. ++ ++@item -mdirect-extern-access ++@itemx -mno-direct-extern-access ++@opindex mdirect-extern-access ++Do not use or use GOT to access external symbols. The default is ++@option{-mno-direct-extern-access}: GOT is used for external symbols with ++default visibility, but not used for other external symbols. ++ ++With @option{-mdirect-extern-access}, GOT is not used and all external ++symbols are PC-relatively addressed. It is @strong{only} suitable for ++environments where no dynamic link is performed, like firmwares, OS ++kernels, executables linked with @option{-static} or @option{-static-pie}. ++@option{-mdirect-extern-access} is not compatible with @option{-fPIC} or ++@option{-fpic}. + @end table + @end table + +diff --git a/gcc/testsuite/gcc.target/loongarch/direct-extern-1.c b/gcc/testsuite/gcc.target/loongarch/direct-extern-1.c +new file mode 100644 +index 000000000..85c6c1e8a +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/direct-extern-1.c +@@ -0,0 +1,6 @@ ++/* { dg-do compile } */ ++/* { dg-options "-mexplicit-relocs -mdirect-extern-access" } */ ++/* { dg-final { scan-assembler-not "got" } } */ ++ ++extern int x; ++int f() { return x; } +diff --git a/gcc/testsuite/gcc.target/loongarch/direct-extern-2.c b/gcc/testsuite/gcc.target/loongarch/direct-extern-2.c +new file mode 100644 +index 000000000..58d8bd68a +--- /dev/null ++++ b/gcc/testsuite/gcc.target/loongarch/direct-extern-2.c +@@ -0,0 +1,6 @@ ++/* { dg-do compile } */ ++/* { dg-options "-mno-explicit-relocs -mdirect-extern-access" } */ ++/* { dg-final { scan-assembler-not "la.global" } } */ ++ ++extern int x; ++int f() { return x; } +-- +2.31.1 + diff --git a/0036-LoongArch-Fix-pr106828-by-define-hook.patch b/0036-LoongArch-Fix-pr106828-by-define-hook.patch new file mode 100644 index 0000000000000000000000000000000000000000..1d8b2c4aa101c70f7d54f486f900d1bcea5e3e46 --- /dev/null +++ b/0036-LoongArch-Fix-pr106828-by-define-hook.patch @@ -0,0 +1,72 @@ +From d53c6974fec553cc8633312fca451aedde7495ef Mon Sep 17 00:00:00 2001 +From: Li Xing +Date: Sat, 10 Sep 2022 01:47:27 +0000 +Subject: [PATCH 5/5] LoongArch: Fix pr106828 by define hook + TARGET_ASAN_SHADOW_OFFSET in loongarch backend [PR106828]. + +gcc/ChangeLog: + + PR target/106828 + * config/loongarch/loongarch.cc (loongarch_asan_shadow_offset): New. + (TARGET_ASAN_SHADOW_OFFSET): New. + +gcc/testsuite/ChangeLog: + + PR target/106828 + * g++.target/loongarch/pr106828.C: New test. + +From: Lulu Cheng + +Signed-off-by: Li Xing +Change-Id: I11d1202d0a00ad670e15def77b66d45157f08fad +--- + gcc/config/loongarch/loongarch.c | 14 ++++++++++++++ + gcc/testsuite/g++.target/loongarch/pr106828.C | 4 ++++ + 2 files changed, 18 insertions(+) + create mode 100644 gcc/testsuite/g++.target/loongarch/pr106828.C + +diff --git a/gcc/config/loongarch/loongarch.c b/gcc/config/loongarch/loongarch.c +index 24853ebca..4ddcaa446 100644 +--- a/gcc/config/loongarch/loongarch.c ++++ b/gcc/config/loongarch/loongarch.c +@@ -6463,6 +6463,17 @@ loongarch_use_anchors_for_symbol_p (const_rtx symbol) + return default_use_anchors_for_symbol_p (symbol); + } + ++/* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */ ++ ++static unsigned HOST_WIDE_INT ++loongarch_asan_shadow_offset (void) ++{ ++ /* We only have libsanitizer support for LOONGARCH64 at present. ++ This value is taken from the file libsanitizer/asan/asan_mappint.h. */ ++ return TARGET_64BIT ? (HOST_WIDE_INT_1 << 46) : 0; ++} ++ ++ + /* Initialize the GCC target structure. */ + #undef TARGET_ASM_ALIGNED_HI_OP + #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t" +@@ -6657,6 +6668,9 @@ loongarch_use_anchors_for_symbol_p (const_rtx symbol) + #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P + #define TARGET_USE_ANCHORS_FOR_SYMBOL_P loongarch_use_anchors_for_symbol_p + ++#undef TARGET_ASAN_SHADOW_OFFSET ++#define TARGET_ASAN_SHADOW_OFFSET loongarch_asan_shadow_offset ++ + struct gcc_target targetm = TARGET_INITIALIZER; + + #include "gt-loongarch.h" +diff --git a/gcc/testsuite/g++.target/loongarch/pr106828.C b/gcc/testsuite/g++.target/loongarch/pr106828.C +new file mode 100644 +index 000000000..190c1db71 +--- /dev/null ++++ b/gcc/testsuite/g++.target/loongarch/pr106828.C +@@ -0,0 +1,4 @@ ++/* { dg-do-preprocess } */ ++/* { dg-options "-mabi=lp64d -fsanitize=address" } */ ++ ++/* Tests whether the compiler supports compile option '-fsanitize=address'. */ +-- +2.31.1 + diff --git a/gcc.spec b/gcc.spec index e5a4fbd42082937bcb5406e51b925ebb68b580e8..cbd76866929bba1eabccab0caba4763cd525e4eb 100644 --- a/gcc.spec +++ b/gcc.spec @@ -61,7 +61,7 @@ Summary: Various compilers (C, C++, Objective-C, ...) Name: gcc Version: %{gcc_version} -Release: 16 +Release: 18 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD URL: https://gcc.gnu.org @@ -150,6 +150,8 @@ Patch31: 0031-AutoBOLT-Enable-BOLT-linker-plugin-on-aarch64-3-3.patch Patch32: 0032-Autoprefetch-Prune-invaild-loops-containing-edges-wh.patch Patch33: 0033-lra-clear-lra_insn_recog_data-after-simplifying-a-me.patch patch34: 0034-Add-Loongarch-backend-support.patch +Patch35: 0035-LoongArch-add-mdirect-extern-access-option.patch +Patch36: 0036-LoongArch-Fix-pr106828-by-define-hook.patch %global gcc_target_platform %{_arch}-linux-gnu @@ -625,6 +627,8 @@ not stable, so plugins must be rebuilt any time GCC is updated. %patch32 -p1 %patch33 -p1 %patch34 -p1 +%patch35 -p1 +%patch36 -p1 %build @@ -2594,6 +2598,18 @@ end %doc rpm.doc/changelogs/libcc1/ChangeLog* %changelog +* Fri Sep 16 2022 lixing - 10.3.1-18 +- Type:requirements +- ID:NA +- SUG:NA +- DESC: LoongArch Fix pr106828 by define hook + +* Fri Sep 16 2022 lixing - 10.3.1-17 +- Type:requirements +- ID:NA +- SUG:NA +- DESC: Add LoongArch direct extern access support + * Thu Sep 1 2022 lixing - 10.3.1-16 - Type:requirements - ID:NA