public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: LuluCheng <chenglulu@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8350] LoongArch: Check whether binutils supports the relax function. If supported, explicit relocs are tur Date: Thu, 22 Feb 2024 03:25:02 +0000 (GMT) [thread overview] Message-ID: <20240222032503.58B693858D39@sourceware.org> (raw) https://gcc.gnu.org/g:504bb03e69bcd561421a1cbb3050c40b0f19bc22 commit r13-8350-g504bb03e69bcd561421a1cbb3050c40b0f19bc22 Author: Lulu Cheng <chenglulu@loongson.cn> Date: Fri Sep 15 10:22:49 2023 +0800 LoongArch: Check whether binutils supports the relax function. If supported, explicit relocs are turned off by default. gcc/ChangeLog: * config.in: Regenerate. * config/loongarch/genopts/loongarch.opt.in: Add compilation option mrelax. And set the initial value of explicit-relocs according to the detection status. * config/loongarch/gnu-user.h: When compiling with -mno-relax, pass the --no-relax option to the linker. * config/loongarch/loongarch-opts.h (HAVE_AS_MRELAX_OPTION): Define macro. * config/loongarch/loongarch.opt: Regenerate. * configure: Regenerate. * configure.ac: Add detection of support for binutils relax function. (cherry picked from commit 9bab65a77049edcc7afc59532173206ee816e726) Diff: --- gcc/config.in | 6 ++++++ gcc/config/loongarch/genopts/loongarch.opt.in | 7 +++++- gcc/config/loongarch/gnu-user.h | 3 ++- gcc/config/loongarch/loongarch-opts.h | 4 ++++ gcc/config/loongarch/loongarch.opt | 7 +++++- gcc/configure | 31 +++++++++++++++++++++++++++ gcc/configure.ac | 4 ++++ 7 files changed, 59 insertions(+), 3 deletions(-) diff --git a/gcc/config.in b/gcc/config.in index ef35af16f2f1..36a74dd59748 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -636,6 +636,12 @@ #endif +/* Define if your assembler supports -mrelax option. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_MRELAX_OPTION +#endif + + /* Define if your assembler supports .mspabi_attribute. */ #ifndef USED_FOR_TARGET #undef HAVE_AS_MSPABI_ATTRIBUTE diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in index 4b9b4ac273e9..e7c32e61a509 100644 --- a/gcc/config/loongarch/genopts/loongarch.opt.in +++ b/gcc/config/loongarch/genopts/loongarch.opt.in @@ -155,7 +155,7 @@ Target Joined RejectNegative UInteger Var(loongarch_max_inline_memcpy_size) Init -mmax-inline-memcpy-size=SIZE Set the max size of memcpy to inline, default is 1024. mexplicit-relocs -Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) +Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS & !HAVE_AS_MRELAX_OPTION) Use %reloc() assembly operators. ; The code model option names for -mcmodel. @@ -188,3 +188,8 @@ Specify the code model. mdirect-extern-access Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0) Avoid using the GOT to access external symbols. + +mrelax +Target Var(loongarch_mrelax) Init(HAVE_AS_MRELAX_OPTION) +Take advantage of linker relaxations to reduce the number of instructions +required to materialize symbol addresses. diff --git a/gcc/config/loongarch/gnu-user.h b/gcc/config/loongarch/gnu-user.h index 5f1bd60ada3b..e9f4bcef1d47 100644 --- a/gcc/config/loongarch/gnu-user.h +++ b/gcc/config/loongarch/gnu-user.h @@ -48,7 +48,8 @@ along with GCC; see the file COPYING3. If not see "%{!shared: %{static} " \ "%{!static: %{!static-pie: %{rdynamic:-export-dynamic} " \ "-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} " \ - "%{static-pie: -static -pie --no-dynamic-linker -z text}}" + "%{static-pie: -static -pie --no-dynamic-linker -z text}}" \ + "%{mno-relax: --no-relax}" /* Similar to standard Linux, but adding -ffast-math support. */ diff --git a/gcc/config/loongarch/loongarch-opts.h b/gcc/config/loongarch/loongarch-opts.h index b1ff54426e42..7ea02f4978cc 100644 --- a/gcc/config/loongarch/loongarch-opts.h +++ b/gcc/config/loongarch/loongarch-opts.h @@ -92,4 +92,8 @@ loongarch_config_target (struct loongarch_target *target, #define HAVE_AS_EXPLICIT_RELOCS 0 #endif +#ifndef HAVE_AS_MRELAX_OPTION +#define HAVE_AS_MRELAX_OPTION 0 +#endif + #endif /* LOONGARCH_OPTS_H */ diff --git a/gcc/config/loongarch/loongarch.opt b/gcc/config/loongarch/loongarch.opt index 68018ade73f0..e37ed9015de5 100644 --- a/gcc/config/loongarch/loongarch.opt +++ b/gcc/config/loongarch/loongarch.opt @@ -162,7 +162,7 @@ Target Joined RejectNegative UInteger Var(loongarch_max_inline_memcpy_size) Init -mmax-inline-memcpy-size=SIZE Set the max size of memcpy to inline, default is 1024. mexplicit-relocs -Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS) +Target Var(TARGET_EXPLICIT_RELOCS) Init(HAVE_AS_EXPLICIT_RELOCS & !HAVE_AS_MRELAX_OPTION) Use %reloc() assembly operators. ; The code model option names for -mcmodel. @@ -195,3 +195,8 @@ Specify the code model. mdirect-extern-access Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0) Avoid using the GOT to access external symbols. + +mrelax +Target Var(loongarch_mrelax) Init(HAVE_AS_MRELAX_OPTION) +Take advantage of linker relaxations to reduce the number of instructions +required to materialize symbol addresses. diff --git a/gcc/configure b/gcc/configure index dec2eca1a453..760bea9d4a0a 100755 --- a/gcc/configure +++ b/gcc/configure @@ -29075,6 +29075,37 @@ if test $gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support = yes; then $as_echo "#define HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT 1" >>confdefs.h +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for -mrelax option" >&5 +$as_echo_n "checking assembler for -mrelax option... " >&6; } +if ${gcc_cv_as_loongarch_relax+:} false; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_loongarch_relax=no + if test x$gcc_cv_as != x; then + $as_echo '.text' > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -mrelax -o conftest.o conftest.s >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + gcc_cv_as_loongarch_relax=yes + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_loongarch_relax" >&5 +$as_echo "$gcc_cv_as_loongarch_relax" >&6; } +if test $gcc_cv_as_loongarch_relax = yes; then + +$as_echo "#define HAVE_AS_MRELAX_OPTION 1" >>confdefs.h + fi ;; diff --git a/gcc/configure.ac b/gcc/configure.ac index c0d067ec2716..4f3c4ebb5a5f 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -5366,6 +5366,10 @@ x: .cfi_endproc],, [AC_DEFINE(HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT, 1, [Define if your assembler supports eh_frame pcrel encoding.])]) + gcc_GAS_CHECK_FEATURE([-mrelax option], gcc_cv_as_loongarch_relax, + [-mrelax], [.text],, + [AC_DEFINE(HAVE_AS_MRELAX_OPTION, 1, + [Define if your assembler supports -mrelax option.])]) ;; s390*-*-*) gcc_GAS_CHECK_FEATURE([.gnu_attribute support],
reply other threads:[~2024-02-22 3:25 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240222032503.58B693858D39@sourceware.org \ --to=chenglulu@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).