Bug 26048

Summary: [4.2/4.3/4.4 Regression] libffi doesn't build on Solaris 10/x86 with native assembler
Product: gcc Reporter: Rainer Orth <ro>
Component: libffiAssignee: Rainer Orth <ro>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, jakub, pfelecan
Priority: P5 Keywords: build
Version: unknown   
Target Milestone: 4.2.5   
Host: i386-pc-solaris2.10 Target: i386-pc-solaris2.10
Build: i386-pc-solaris2.10 Known to work:
Known to fail: Last reconfirmed: 2008-12-19 14:08:36
Bug Depends on:    
Bug Blocks: 20730    

Description Rainer Orth 2006-01-31 19:23:20 UTC
When trying to bootstrap mainline on Solaris 10/x86 with the native
assembler, building libffi fails:

/vol/gcc/obj/gcc-4.2.0-20060126/10-gcc/./gcc/xgcc -B/vol/gcc/obj/gcc-4.2.0-20060126/10-gcc/./gcc/ -B/vol/gcc/share/i386-pc-solaris2.10/bin/ -B/vol/gcc/share/i386-pc-solaris2.10/lib/ -isystem /vol/gcc/share/i386-pc-solaris2.10/include -isystem /vol/gcc/share/i386-pc-solaris2.10/sys-include -I. -I/vol/gcc/src/gcc-dist/libffi/include -Iinclude -I/vol/gcc/src/gcc-dist/libffi/src -O2 -g -O2 -c /vol/gcc/src/gcc-dist/libffi/src/x86/sysv.S  -fPIC -DPIC -o src/x86/.libs/sysv.o
Assembler: 
	"/var/tmp//ccQLHd1V.s", line 138 : Syntax error
	"/var/tmp//ccQLHd1V.s", line 138 : Illegal character: <7e>
	"/var/tmp//ccQLHd1V.s", line 139 : Syntax error
	"/var/tmp//ccQLHd1V.s", line 139 : Illegal character: <7e>
	"/var/tmp//ccQLHd1V.s", line 146 : Syntax error
	"/var/tmp//ccQLHd1V.s", line 146 : Illegal character: <7e>
	"/var/tmp//ccQLHd1V.s", line 204 : Warning: Illegal subtraction - symbols from different sections: ".LFB1", ".DOT-3"
	"/var/tmp//ccQLHd1V.s", line 223 : Warning: Illegal subtraction - symbols from different sections: ".LFB2", ".DOT-4"
	"/var/tmp//ccQLHd1V.s", line 246 : Warning: Illegal subtraction - symbols from different sections: ".LFB3", ".DOT-5"
make[4]: *** [src/x86/sysv.lo] Error 1

The code in question (from running the command above with -save-temps) is

ffi_closure_raw_SYSV:
[...]
 movl ((10 + 3) & ~3)(%eax), %esi		line 138
 movl ((((10 + 3) & ~3) + 4) + 4)(%eax), %edx	line 139
[...]
 call *(((10 + 3) & ~3) + 4)(%eax)		line 146

 .long .LEFDE1-.LASFDE1
.LASFDE1:
 .long .LASFDE1-.Lframe1
 .long .LFB1-.					line 204

I had already noticed this on 20051006, but hadn't reported it yet since
the Solaris 10/x86 native as doesn't work due to still unfixed PR
target/23359.

The first part of the problem might perhaps be worked around by manual
calculations as in src/mips/ffitarget.h, but I don't know a good solution
for the second problem.

The bug was introduced by this patch:

2005-08-11  Jakub Jelinek  <jakub@redhat.com>

	* configure.ac (HAVE_HIDDEN_VISIBILITY_ATTRIBUTE): New test.
	(AH_BOTTOM): Add FFI_HIDDEN definition.
	* configure: Rebuilt.
	* fficonfig.h.in: Rebuilt.
	* src/powerpc/ffi.c (hidden): Remove.
	(ffi_closure_LINUX64, ffi_prep_args64, ffi_call_LINUX64,
	ffi_closure_helper_LINUX64): Use FFI_HIDDEN instead of hidden.
	* src/powerpc/linux64_closure.S (ffi_closure_LINUX64,
	.ffi_closure_LINUX64): Use FFI_HIDDEN instead of .hidden.
	* src/x86/ffi.c (ffi_closure_SYSV, ffi_closure_raw_SYSV): Remove,
	add FFI_HIDDEN to its prototype.
	(ffi_closure_SYSV_inner): New.
	* src/x86/sysv.S (ffi_closure_SYSV, ffi_closure_raw_SYSV): New.


This is a regression from at least 3.4 where it was possible to bootstrap
on Solaris 10/x86 with the native assembler.  I don't know for sure about
4.0, though.

Environment:
System: SunOS erebus 5.10 Generic_Patch i86pc i386 i86pc
Architecture: i86pc

	
host: i386-pc-solaris2.10
build: i386-pc-solaris2.10
target: i386-pc-solaris2.10
configured with: /vol/gcc/src/gcc-dist/configure --prefix=/vol/gcc --with-local-prefix=/vol/gcc --disable-nls --disable-multilib --with-gmp-dir=/vol/gnu/obj/gmp-4.1.3 --with-mpfr-dir=/vol/gnu/obj/gmp-4.1.3/mpfr --enable-languages=c,c++,fortran,java,objc,ada --disable-libmudflap

How-To-Repeat:
Bootstrap mainline as described above.
Comment 1 Rainer Orth 2006-02-01 01:09:28 UTC
Jakub, since your patch introduced this regressions, could you please have a look?

Thanks.
      Rainer
Comment 2 Mark Mitchell 2006-02-01 03:15:54 UTC
P2; this is something that should be fixed, but is not critical, since libffi is not used for our primary languages, and since using GNU binutils is a workaround.
Comment 3 Jakub Jelinek 2006-02-01 10:17:07 UTC
For the first problem, you can use something like:

+#if FFI_TRAMPOLINE_SIZE == 10
+/* Precalculated for crappy assemblers.  */
+#define RAW_CLOSURE_CIF_OFFSET 12
+#define RAW_CLOSURE_FUN_OFFSET 16
+#define RAW_CLOSURE_USER_DATA_OFFSET 20
+#else
 #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
 #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
 #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
+#endif
 #define CIF_FLAGS_OFFSET 20

(untested).  For the second, you should do whatever GCC emits in -fpic
.eh_frame on your platform. i386/sol2.h has:
/* Old versions of the Solaris assembler can not handle the difference of
   labels in different sections, so force DW_EH_PE_datarel.  */
#undef ASM_PREFERRED_EH_DATA_FORMAT
#define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)                       \
  (flag_pic ? ((GLOBAL ? DW_EH_PE_indirect : 0)                         \
               | (TARGET_64BIT ? DW_EH_PE_pcrel | DW_EH_PE_sdata4       \
                  : DW_EH_PE_datarel))                                  \
   : DW_EH_PE_absptr)
That means adding the some configury bits to detect that, set some macro
and #if defined __PIC__ && USE_EH_FRAME_DATAREL
datarel encoded stuff
#elif defined __PIC
pcrel encoded stuff
#else
absolute encoded stuff
#endif
Comment 4 Mark Mitchell 2006-02-24 00:26:52 UTC
This issue will not be resolved in GCC 4.1.0; retargeted at GCC 4.1.1.
Comment 5 Mark Mitchell 2006-05-25 02:33:50 UTC
Will not be fixed in 4.1.1; adjust target milestone to 4.1.2.
Comment 6 Mark Mitchell 2006-10-17 22:54:50 UTC
Solaris x86 is not a primary or secondary platform.
Comment 7 Joseph S. Myers 2008-07-04 20:18:27 UTC
Closing 4.1 branch.
Comment 8 Rainer Orth 2008-12-08 17:32:09 UTC
Subject: Re:  [4.2/4.3/4.4 Regression] libffi doesn't build on Solaris 10/x86 with native assembler

New patch here:

	http://gcc.gnu.org/ml/gcc-patches/2008-12/msg00481.html
Comment 9 Rainer Orth 2008-12-19 15:01:15 UTC
Subject: Bug 26048

Author: ro
Date: Fri Dec 19 14:59:42 2008
New Revision: 142835

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142835
Log:
	PR libffi/26048
	* configure.ac (HAVE_AS_X86_PCREL): New test.
	* configure: Regenerate.
	* fficonfig.h.in: Regenerate.
	* src/x86/sysv.S [!FFI_NO_RAW_API]: Precalculate
	RAW_CLOSURE_CIF_OFFSET, RAW_CLOSURE_FUN_OFFSET,
	RAW_CLOSURE_USER_DATA_OFFSET for the Solaris 10/x86 assembler.
	(.eh_frame): Only use SYMBOL-. iff HAVE_AS_X86_PCREL.
	* src/x86/unix64.S (.Lstore_table): Move to .text section.
	(.Lload_table): Likewise.
	(.eh_frame): Only use SYMBOL-. iff HAVE_AS_X86_PCREL.

Modified:
    trunk/libffi/ChangeLog
    trunk/libffi/configure
    trunk/libffi/configure.ac
    trunk/libffi/fficonfig.h.in
    trunk/libffi/src/x86/sysv.S
    trunk/libffi/src/x86/unix64.S

Comment 10 Rainer Orth 2008-12-19 15:01:20 UTC
Fixed for 4.4.0.
Comment 11 Rainer Orth 2010-04-28 21:03:32 UTC
*** Bug 20730 has been marked as a duplicate of this bug. ***