diff mbox

[libffi] Use datarel encoding in libffi .eh_frame on Solaris 2/x86

Message ID yddoc9brkjo.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Nov. 26, 2010, 6:45 p.m. UTC
While trying to make the libgcc unwinder use dl_iterate_phdr on Solaris
11, I ran into a gld bug (PR ld/12253) that broke libffi unwind tests
and all libjava execution tests: while Solaris 2/x86 uses
DW_EH_PE_datarel encoding for .eh_frame in 32-bit PIC code,
src/x86/sysv.S uses DW_EH_PE_pcrel.  Due to the above bug, .eh_frame_hdr
isn't sorted correctly with gld before 2.22.  To work around this issue
for older gld versions, I'd like to use the following workaround to
avoid the issue, namely also use datarel encoding on Solaris 2/x86.

Bootstrapped on i386-pc-solaris2.11 with CVS gas and gld (before the
fix) and i386-pc-solaris2.10 with Sun as and ld.  It fixes all the
testsuite regressions with gld and works without issues with Sun ld.

Ok for mainline?

	Rainer


2010-01-18  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* src/x86/sysv.S (.eh_frame) [__PIC__ && __sun__ && __svr4__]: Use
	datarel encoding.
	(.LASFDE1) [__PIC__ && __sun__ && __svr4__]: Use @GOTOFF for FDE
	initial location.
	(.LASFDE2, LASFDE3): Likewise.

Comments

Richard Henderson Nov. 26, 2010, 7:15 p.m. UTC | #1
On 11/26/2010 10:45 AM, Rainer Orth wrote:
> 	* src/x86/sysv.S (.eh_frame) [__PIC__ && __sun__ && __svr4__]: Use
> 	datarel encoding.
> 	(.LASFDE1) [__PIC__ && __sun__ && __svr4__]: Use @GOTOFF for FDE
> 	initial location.
> 	(.LASFDE2, LASFDE3): Likewise.

This is getting complex enough that I think we should not 
replicate this logic 4 times.  Would you please pull this
out into a set of macros near the top of the file?  E.g.

#if defined __PIC__
# if defined __sun__ && defined __svr4__
#  define FDE_ENCODING		0x30	/* datarel */
#  define FDE_ENCODE(X)		X@GOTOFF
# else
#  define FDE_ENCODING		0x1b	/* pcrel sdata4 */
#  if defined HAVE_AS_X86_PCREL
#   define FDE_ENCODE(X)	X-.
#  else
#   define FDE_ENCODE(X)	X@rel
#  endif
# endif
#else
# define FDE_ENCODING		0	/* absolute */
# define FDE_ENCODE(X)		X
#endif

And, frankly, for gcc 4.7 we ought to consider requiring a
recent version of binutils and scrap all of this explicit
unwind info in favor of CFI directives.



r~
Rainer Orth Nov. 26, 2010, 7:19 p.m. UTC | #2
Richard Henderson <rth@redhat.com> writes:

> On 11/26/2010 10:45 AM, Rainer Orth wrote:
>> 	* src/x86/sysv.S (.eh_frame) [__PIC__ && __sun__ && __svr4__]: Use
>> 	datarel encoding.
>> 	(.LASFDE1) [__PIC__ && __sun__ && __svr4__]: Use @GOTOFF for FDE
>> 	initial location.
>> 	(.LASFDE2, LASFDE3): Likewise.
>
> This is getting complex enough that I think we should not 
> replicate this logic 4 times.  Would you please pull this
> out into a set of macros near the top of the file?  E.g.
>
> #if defined __PIC__
> # if defined __sun__ && defined __svr4__
> #  define FDE_ENCODING		0x30	/* datarel */
> #  define FDE_ENCODE(X)		X@GOTOFF
> # else
> #  define FDE_ENCODING		0x1b	/* pcrel sdata4 */
> #  if defined HAVE_AS_X86_PCREL
> #   define FDE_ENCODE(X)	X-.
> #  else
> #   define FDE_ENCODE(X)	X@rel
> #  endif
> # endif
> #else
> # define FDE_ENCODING		0	/* absolute */
> # define FDE_ENCODE(X)		X
> #endif

Sure, I'll give this a try.

> And, frankly, for gcc 4.7 we ought to consider requiring a
> recent version of binutils and scrap all of this explicit
> unwind info in favor of CFI directives.

We have to be very careful here: libffi is used by several other
projects and is supposed to be buildable with vendor compilers and
assemblers also.

	Rainer
diff mbox

Patch

diff -r 36d43c8e1be5 libffi/src/x86/sysv.S
--- a/libffi/src/x86/sysv.S	Sat Nov 20 22:10:07 2010 +0100
+++ b/libffi/src/x86/sysv.S	Sat Nov 20 22:10:57 2010 +0100
@@ -354,8 +354,15 @@ 
 	.byte	0x8	/* CIE RA Column */
 #ifdef __PIC__
 	.byte	0x1	/* .uleb128 0x1; Augmentation size */
+#ifdef __sun__ && __svr4__
+	/* 32-bit Solaris 2/x86 uses datarel encoding for PIC.  GNU ld
+	   doesn't correctly sort .eh_frame_hdr with mixed encodings, so
+	   match this.  */
+	.byte	0x30	/* FDE Encoding (datarel) */
+#else
 	.byte	0x1b	/* FDE Encoding (pcrel sdata4) */
 #endif
+#endif
 	.byte	0xc	/* DW_CFA_def_cfa */
 	.byte	0x4	/* .uleb128 0x4 */
 	.byte	0x4	/* .uleb128 0x4 */
@@ -367,10 +374,14 @@ 
 	.long	.LEFDE1-.LASFDE1	/* FDE Length */
 .LASFDE1:
 	.long	.LASFDE1-.Lframe1	/* FDE CIE offset */
-#if defined __PIC__ && defined HAVE_AS_X86_PCREL
-	.long	.LFB1-.	/* FDE initial location */
-#elif defined __PIC__
-	.long	.LFB1@rel
+#ifdef __PIC__
+#if defined __sun__ && defined __svr4__
+	.long	.LFB1@GOTOFF	/* FDE initial location */
+#elif defined HAVE_AS_X86_PCREL
+	.long	.LFB1-.		/* FDE initial location */
+#else
+	.long	.LFB1@rel	/* FDE initial location */
+#endif
 #else
 	.long	.LFB1
 #endif
@@ -394,10 +405,14 @@ 
 	.long	.LEFDE2-.LASFDE2	/* FDE Length */
 .LASFDE2:
 	.long	.LASFDE2-.Lframe1	/* FDE CIE offset */
-#if defined __PIC__ && defined HAVE_AS_X86_PCREL
-	.long	.LFB2-.	/* FDE initial location */
-#elif defined __PIC__
-	.long	.LFB2@rel
+#ifdef __PIC__
+#if defined __sun__ && defined __svr4__
+	.long	.LFB2@GOTOFF	/* FDE initial location */
+#elif defined HAVE_AS_X86_PCREL
+	.long	.LFB2-.		/* FDE initial location */
+#else
+	.long	.LFB2@rel	/* FDE initial location */
+#endif
 #else
 	.long	.LFB2
 #endif
@@ -430,10 +445,14 @@ 
 	.long	.LEFDE3-.LASFDE3	/* FDE Length */
 .LASFDE3:
 	.long	.LASFDE3-.Lframe1	/* FDE CIE offset */
-#if defined __PIC__ && defined HAVE_AS_X86_PCREL
-	.long	.LFB3-.	/* FDE initial location */
-#elif defined __PIC__
-	.long	.LFB3@rel
+#ifdef __PIC__
+#if defined __sun__ && defined __svr4__
+	.long	.LFB3@GOTOFF	/* FDE initial location */
+#elif defined HAVE_AS_X86_PCREL
+	.long	.LFB3-.		/* FDE initial location */
+#else
+	.long	.LFB3@rel	/* FDE initial location */
+#endif
 #else
 	.long	.LFB3
 #endif