[v1] LoongArch: Define the macro ASM_PREFERRED_EH_DATA_FORMAT by checking the assembler's support for eh_frame encoding.
Commit Message
The ASM_PREFERRED_EH_DATA_FORMAT macro before and after modification is as follows:
#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
- (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_absptr)
+ (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4)
Use the following tests to describe the effect of modifying this macro on the generated
assembly code:
#include <iostream>
#include <exception>
using namespace std;
int main()
{
try {
throw 1;
}
catch (int i)
{
cout << i << endl;
}
}
The main comparisons related to the eh_frame section are as follows:
OLD NEW
.LFB1997 = . | .LFB1780 = .
.cfi_startproc | .cfi_startproc
.cfi_personality 0x80,DW.ref.__gxx_personality_v0 | .cfi_personality 0x9b,DW.ref.__gxx_personality_v0
.cfi_lsda 0,.LLSDA1997 | .cfi_lsda 0x1b,.LLSDA1780
If the assembly file generated by the new gcc is compiled with the binutils of version 2.38, the
following error will be reported:
test.s:74: Error: invalid or unsupported encoding in .cfi_personality
test.s:75: Error: invalid or unsupported encoding in .cfi_lsda
So I think I should judge whether binutils supports this encoding when gcc is configured, and then choose how to define
macro ASM_PREFERRED_EH_DATA_FORMAT.
------------
.eh_frame DW_EH_PE_pcrel encoding format is not supported by gas <= 2.39.
Check if the assembler support DW_EH_PE_PCREL encoding and define .eh_frame
encoding type.
gcc/ChangeLog:
* config.in: Regenerate.
* config/loongarch/loongarch.h (ASM_PREFERRED_EH_DATA_FORMAT):
Select the value of the macro definition according to whether
HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT is defined.
* configure: Regenerate.
* configure.ac: Reinstate HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT test.
---
gcc/config.in | 8 +++++++-
gcc/config/loongarch/loongarch.h | 5 +++++
gcc/configure | 35 ++++++++++++++++++++++++++++++++
gcc/configure.ac | 9 ++++++++
4 files changed, 56 insertions(+), 1 deletion(-)
Comments
On Fri, 2022-07-29 at 10:43 +0800, Lulu Cheng wrote:
> .eh_frame DW_EH_PE_pcrel encoding format is not supported by gas <= 2.39.
> Check if the assembler support DW_EH_PE_PCREL encoding and define .eh_frame
> encoding type.
>
> gcc/ChangeLog:
>
> * config.in: Regenerate.
> * config/loongarch/loongarch.h (ASM_PREFERRED_EH_DATA_FORMAT):
> Select the value of the macro definition according to whether
> HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT is defined.
> * configure: Regenerate.
> * configure.ac: Reinstate HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT test.
To me it looks a little strange to list regenerated config.in &
configure before configure.ac. But maybe I'm wrong here if a
lexicographical order is preferred...
/* snip */
> + gcc_GAS_CHECK_FEATURE([eh_frame pcrel encoding support],
> + gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support,,
> + [.LFB1780 = .
> + .cfi_startproc
> + .cfi_personality 0x9b,DW.ref.__gxx_personality_v0
> + .cfi_lsda 0x1b,.LLSDA1780
> + .cfi_endproc],,
I think the conftest content can be simplified to:
.cfi_startproc
.cfi_personality 0x9b,a
.cfi_lsda 0x1b,b
.cfi_endproc
> + [AC_DEFINE(HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT, 1,
> + [Define if your assembler supports eh_frame pcrel encoding.])])
> ;;
> s390*-*-*)
> gcc_GAS_CHECK_FEATURE([.gnu_attribute support],
在 2022/7/29 上午11:18, Xi Ruoyao 写道:
> On Fri, 2022-07-29 at 10:43 +0800, Lulu Cheng wrote:
>
>> .eh_frame DW_EH_PE_pcrel encoding format is not supported by gas <= 2.39.
>> Check if the assembler support DW_EH_PE_PCREL encoding and define .eh_frame
>> encoding type.
>>
>> gcc/ChangeLog:
>>
>> * config.in: Regenerate.
>> * config/loongarch/loongarch.h (ASM_PREFERRED_EH_DATA_FORMAT):
>> Select the value of the macro definition according to whether
>> HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT is defined.
>> * configure: Regenerate.
>> * configure.ac: Reinstate HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT test.
> To me it looks a little strange to list regenerated config.in &
> configure before configure.ac. But maybe I'm wrong here if a
> lexicographical order is preferred...
This information is generated by me through the git gcc-commit-mklog
command, then I didn't move the sequence.
>
> /* snip */
>
>> + gcc_GAS_CHECK_FEATURE([eh_frame pcrel encoding support],
>> + gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support,,
>> + [.LFB1780 = .
>> + .cfi_startproc
>> + .cfi_personality 0x9b,DW.ref.__gxx_personality_v0
>> + .cfi_lsda 0x1b,.LLSDA1780
>> + .cfi_endproc],,
> I think the conftest content can be simplified to:
>
> .cfi_startproc
> .cfi_personality 0x9b,a
> .cfi_lsda 0x1b,b
> .cfi_endproc
>
This one looks more concise, I'll change it
On Fri, 2022-07-29 at 11:51 +0800, Lulu Cheng wrote:
> > > gcc/ChangeLog:
> > >
> > > * config.in: Regenerate.
> > > * config/loongarch/loongarch.h (ASM_PREFERRED_EH_DATA_FORMAT):
> > > Select the value of the macro definition according to whether
> > > HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT is defined.
> > > * configure: Regenerate.
> > > * configure.ac: Reinstate HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT test.
> > To me it looks a little strange to list regenerated config.in &
> > configure before configure.ac. But maybe I'm wrong here if a
> > lexicographical order is preferred...
> This information is generated by me through the git gcc-commit-mklog command,
> then I didn't move the sequence.
I have no objection then.
@@ -404,13 +404,19 @@
#endif
+/* Define if your assembler supports eh_frame pcrel encoding. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT
+#endif
+
+
/* Define if your assembler supports the R_PPC64_ENTRY relocation. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_ENTRY_MARKERS
#endif
-/* Define if your assembler supports explicit relocations. */
+/* Define if your assembler supports explicit relocation. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_EXPLICIT_RELOCS
#endif
@@ -1127,8 +1127,13 @@ struct GTY (()) machine_function
};
#endif
+#ifdef HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT
+#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
+ (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4)
+#else
#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
(((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_absptr)
+#endif
/* Do emit .note.GNU-stack by default. */
#ifndef NEED_INDICATE_EXEC_STACK
@@ -28836,6 +28836,41 @@ if test $gcc_cv_as_loongarch_explicit_relocs = yes; then
$as_echo "#define HAVE_AS_EXPLICIT_RELOCS 1" >>confdefs.h
+fi
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for eh_frame pcrel encoding support" >&5
+$as_echo_n "checking assembler for eh_frame pcrel encoding support... " >&6; }
+if ${gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support=no
+ if test x$gcc_cv_as != x; then
+ $as_echo '.LFB1780 = .
+ .cfi_startproc
+ .cfi_personality 0x9b,DW.ref.__gxx_personality_v0
+ .cfi_lsda 0x1b,.LLSDA1780
+ .cfi_endproc' > conftest.s
+ if { ac_try='$gcc_cv_as $gcc_cv_as_flags -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_eh_frame_pcrel_encoding_support=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_eh_frame_pcrel_encoding_support" >&5
+$as_echo "$gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support" >&6; }
+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
;;
@@ -5302,6 +5302,15 @@ x:
[a:pcalau12i $t0,%pc_hi20(a)],,
[AC_DEFINE(HAVE_AS_EXPLICIT_RELOCS, 1,
[Define if your assembler supports explicit relocation.])])
+ gcc_GAS_CHECK_FEATURE([eh_frame pcrel encoding support],
+ gcc_cv_as_loongarch_eh_frame_pcrel_encoding_support,,
+ [.LFB1780 = .
+ .cfi_startproc
+ .cfi_personality 0x9b,DW.ref.__gxx_personality_v0
+ .cfi_lsda 0x1b,.LLSDA1780
+ .cfi_endproc],,
+ [AC_DEFINE(HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT, 1,
+ [Define if your assembler supports eh_frame pcrel encoding.])])
;;
s390*-*-*)
gcc_GAS_CHECK_FEATURE([.gnu_attribute support],