public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Cheng Jin" <jincheng@ca.ibm.com>
To: libffi-discuss@sourceware.org
Subject: Compliation issues with x86/libffi
Date: Tue, 8 Jun 2021 11:45:51 -0400	[thread overview]
Message-ID: <OFDAB297F2.95260E91-ON002586EE.00543DE7-852586EE.0056989F@ibm.com> (raw)



Hi,

We are currently exploiting the latest version x86/libffi at
https://github.com/libffi/libffi/tree/master/src/x86 in our project but
there were a few compilation issues we detected on various platforms.


[1] Linux/64bit (compilation was based on the guideline at
https://github.com/libffi/libffi/blob/master/configure.host)

X86_64)
	if test x"$TARGET_X32" = xyes; then
		SOURCES="ffi64.c unix64.S"
	else
		SOURCES="ffi64.c unix64.S ffiw64.c win64.S"  <---------
	fi


The compilation passed on Ubuntu 19 with GCC 9 plus the GLIBC 2.31 but it
failed on Redhat6 with GCC 7.5 plus GLIBC 2.12 as follows:

gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ...-fPIC  -m64
-fstack-protector -I. ...    -Wno-unused-result -c -o closures.o closures.c
gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ...-fPIC -m64
-fstack-protector -I. ...   -c -o debug.o debug.c
gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ...-fPIC  -fstack-protector
-I. ...-c -o ffi64.o x86/ffi64.c
gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ...-fPIC -m64
-fstack-protector -I. ...-c -o ffiw64.o x86/ffiw64.c
gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ...-fPIC   -m64
-fstack-protector -I. ...-c -o java_raw_api.o java_raw_api.c
gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ...-fPIC   -m64
-fstack-protector -I. ...-c -o prep_cif.o prep_cif.c
gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ...-fPIC   -m64
-fstack-protector -I. ...-c -o raw_api.o raw_api.c
gcc -O3 -fno-strict-aliasing -fgnu89-inline -g ... -fPIC  -m64
-fstack-protector -I. ...-c -o types.o types.c
gcc -Xassembler -noexecstack -Xassembler -64 -Xassembler --gdwarf2
-Xassembler -I. -Xassembler -I../include ... -c -o unix64.o x86/unix64.S
gcc -Xassembler -noexecstack -Xassembler -64 -Xassembler --gdwarf2
-Xassembler -I. -Xassembler -I../include ... -c -o win64.o x86/win64.S
ar rcv ../lib/libffi.a closures.o debug.o ffi64.o ffiw64.o java_raw_api.o
prep_cif.o raw_api.o types.o unix64.o win64.o
a - closures.o
a - debug.o
a - ffi64.o
a - ffiw64.o
a - java_raw_api.o
a - prep_cif.o
a - raw_api.o
a - types.o
a - unix64.o
a - win64.o
...
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.5.0/../../../../x86_64-pc-linux-gnu/bin/ld: ../lib//libffi.a(unix64.o):
 relocation R_X86_64_PC32 against symbol `abort@@GLIBC_2.2.5' can not be
used when making a shared object; recompile with -fPIC <--------
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/7.5.0/../../../../x86_64-pc-linux-gnu/bin/ld:
 final link failed: Bad value


We'd like to know why failed on the lower version of gcc and whether there
is any chance to fix the issue without upgrading the gcc toolchain to the
latest version (e.g. gcc 9) given there is no specific requirement on the
gcc version in x86/libffi.


------------------------------------

[2] Windows/32bit (compilation with MSVC on x86_64 machines targeting for
32bit based on the guideline at
https://github.com/libffi/libffi/blob/master/configure.host)

X86 | X86_DARWIN | X86_FREEBSD | X86_WIN32)
	if test "$MSVC" = 1; then
		SOURCES="ffi.c sysv_intel.S"  <---------
	else
		SOURCES="ffi.c sysv.S"
	fi


Currently our project includes an older version of x86/libffi (ffi.c &
win32.S) which works fine on Windows/32bit but it failed to compile after
replacing with ffi.c and sysv_intel.S

ffi.lib(prep_cif.c.obj) : warning LNK4049: locally defined symbol
_ffi_type_sint32 imported
ffi.lib(prep_cif.c.obj) : warning LNK4049: locally defined symbol
_ffi_type_float imported
ffi.lib(ffi.c.obj) : error LNK2019: unresolved external symbol
@ffi_call_i386@8 referenced in function _ffi_raw_call
ffi.lib(sysv_intel.asm.obj) : error LNK2019: unresolved external symbol
_@ffi_closure_inner@8 referenced in function _ffi_closure_i386


We tried to add the following code in sysv_intel.S (the same code as in
sysv.S)
/* Handle win32 fastcall name mangling.  */
#ifdef X86_WIN32
# define ffi_call_i386		"@ffi_call_i386@8"
# define ffi_closure_inner	"@ffi_closure_inner@8"
#else
# define ffi_call_i386		C(ffi_call_i386)
# define ffi_closure_inner	C(ffi_closure_inner)
#endif

but still ended up with the misleading failures:
...\libffi\sysv_intel.asm(1124) specified size
 : error A2008:syntax error : @ffi_closure_inner@8
...\libffi\sysv_intel.asm(1139) specified size
 : error A2008:syntax error : @ffi_call_i386@8
...\libffi\sysv_intel.asm(1140) specified size
 : error A2008:syntax error : @ffi_call_i386@8
...\libffi\sysv_intel.asm(1246) specified size
 : error A2008:syntax error : @ffi_call_i386@8
...\libffi\sysv_intel.asm(1366) specified size


So we are not too sure whether there was something we might be unaware of
in terms of compilation options or something else we missed; otherwise, we
might need to switch back to the older version specific to Windows/32bit to
avoid such issue.

Thanks and Best Regards
Cheng Jin

                 reply	other threads:[~2021-06-08 15:45 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=OFDAB297F2.95260E91-ON002586EE.00543DE7-852586EE.0056989F@ibm.com \
    --to=jincheng@ca.ibm.com \
    --cc=libffi-discuss@sourceware.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: link
Be 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).