1 dnl sxe-linker.m4 -- Linker stuff, esp. dynamic linking
2 dnl needed for emodules for one
4 dnl that's a too fucking long thing, split it!
5 AC_DEFUN([SXE_SHLIB_STUFF],[
11 ld_dynamic_link_flags=
13 xealias=$ac_cv_build_alias
15 AC_MSG_CHECKING([how to build dynamic libraries for ${xehost}])
17 # Transform *-*-linux* to *-*-linux-gnu*, to support old configure scripts.
20 *-*-linux*) xehost=`echo $xehost | sed 's/^\(.*-.*-linux\)\(.*\)$/\1-gnu\2/'`
23 xehost_cpu=`echo $xehost | sed 's/^\([[^-]]*\)-\([[^-]]*\)-\(.*\)$/\1/'`
24 xehost_vendor=`echo $xehost | sed 's/^\([[^-]]*\)-\([[^-]]*\)-\(.*\)$/\2/'`
25 xehost_os=`echo $xehost | sed 's/^\([[^-]]*\)-\([[^-]]*\)-\(.*\)$/\3/'`
29 # AIX sometimes has problems with the GCC collect2 program. For some
30 # reason, if we set the COLLECT_NAMES environment variable, the problems
31 # vanish in a puff of smoke.
32 if test "${COLLECT_NAMES+set}" != set; then
39 # Now see if the compiler is really GCC.
40 if test "$GCC" = "yes"; then
43 AC_MSG_CHECKING([whether we are using GNU C])
48 ],XEGCC=yes, XEGCC=no)
49 AC_MSG_RESULT([${XEGCC}])
52 AC_MSG_CHECKING([how to produce PIC code])
56 if test "$XEGCC" = yes -o "$__ICC" = yes; then
60 aix[[3-9]]* | irix[[5-9]]* | osf[[3-9]])
61 # PIC is the default for these OSes.
64 *darwin*) dll_cflags='-dynamic'
68 # We can build DLLs from non-PIC.
71 # FIXME: we need at least 68020 code to build shared libraries, but
72 # adding the `-m68020' flag to GCC prevents building anything better,
74 dll_cflags='-m68020 -resident32 -malways-restore-a4'
81 # PORTME Check for PIC flags for the system compiler.
83 hpux9* | hpux1[[0-9]]*)
84 # Is there a better link_static_flag that works with the bundled CC?
91 # PIC (with -KPIC) is the default.
95 # We can build DLLs from non-PIC.
99 # All OSF/1 code is PIC.
104 # All AIX code is PIC.
109 dll_cflags='-belf -Kpic'
148 if test -n "$dll_cflags"; then
149 AC_MSG_RESULT([${dll_cflags}])
151 # Check to make sure the dll_cflags actually works.
152 AC_MSG_CHECKING([if PIC flag ${dll_cflags} really works])
153 save_CFLAGS="$CFLAGS"
154 CFLAGS="$CFLAGS $dll_cflags -DPIC"
155 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int x=0;]])],[
156 # On HP-UX, the stripped-down bundled CC doesn't accept +Z, but also
157 # reports no error. So, we need to grep stderr for (Bundled).
158 if grep '(Bundled)' config.log >/dev/null; then
164 fi], [AC_MSG_RESULT(no)
167 CFLAGS="$save_CFLAGS"
173 dnl Now comes the LD trickery. We do things differently to libtool here.
174 dnl I believe that libtool is incorrect in trying to drive the linker
175 dnl directly. This can cause considerable problems if the module you are
176 dnl compiling has C++ or other static initializers. If we use ld directly,
177 dnl we don't end up with the crt stuff being linked in, and we don't end up
178 dnl with any .init or .fini sections (or the moral equivalent thereof).
179 dnl gcc takes great care to do this properly when invoked in -shared
180 dnl mode, and we really do want this behavior. Perhaps the libtool folks
181 dnl are not aware that any SVR4 based dynamic loader will automatically
182 dnl execute code in the .init section before dlopen() returns. This is
183 dnl vital, as the module may have been compiled to rely on that behavior.
185 dnl So, having said all of that, we diverge from libtool significantly
186 dnl here. We want to try and use the C compiler as much as possible. Only
187 dnl if the C compiler itself cannot create shared libraries do we try to
190 dnl The other advantage to my scheme is that it removes the dependancy
191 dnl on a given compiler version remaining static with relation to the
192 dnl version of XEmacs. With the libtool way, it picks up the linker that
193 dnl gcc uses, which can be the internal collect2 that comes with gcc.
194 dnl If the user ever changes their compiler version, the paths will no
195 dnl longer be correct, and ellcc will break. This is clearly unacceptable.
196 dnl By using the compiler driver on the path, we don't have this problem.
197 dnl If that is not clear, consider that gcc -print-prog-name=ld can
198 dnl produce something along the lines of:
199 dnl /usr/local/lib/gcc-lib/OS-NAME/GCC-VERSION/ld
200 dnl If you ever change GCC versions, then that path no longer exists.
202 dnl So, we change the check order here. We first check to see if we are
203 dnl using GCC, and if so, we see if -shared works. If it does, great.
204 dnl If we are not using gcc, but the system C compiler can produce
205 dnl shared objects, we try that. Only if all of that fails do we revert
206 dnl back to the libtool ld trickery.
208 dnl We don't do ANY of this if we can't produce shared objects.
210 if test "$can_build_shared" = "yes"; then
214 AC_MSG_CHECKING([if C compiler can produce shared libraries])
215 if test "$XEGCC" = "yes" -o "$__ICC" = "yes"; then
219 xldf='-bundle -undefined suppress -flat_namespace'
229 xldf="-bE:ELLSONAME.exp -H512 -T512 -bhalt:4 -bM:SRE -bnoentry -lc"
230 xcldf="${wl}-bE:ELLSONAME.exp ${wl}-H512 ${wl}-T512 ${wl}-bhalt:4 ${wl}-bM:SRE ${wl}-bnoentry ${wl}-lc"
233 freebsd2* | netbsd* | openbsd*)
235 xcldf="${wl}-Bshareable"
244 xcldf="${wl}-b ${wl}+s"
247 irix[[5-9]]* | osf[[3-9]]*)
252 sco3.2v5* | unixware* | sysv5* | sysv4* | solaris2* | solaris7* | uts4*)
258 xcldf="${wl}-assert ${wl}pure-text ${wl}-Bstatic"
259 xldf="-assert pure-text -Bstatic"
262 fi # End if if we are using gcc
264 if test -n "$xcldf"; then
266 LDFLAGS="$xcldf $LDFLAGS"
269 dnl ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS '"$xe_cppflags $xe_ldflags"' conftest.$ac_ext '"$xe_libs"' 1>&AS_MESSAGE_LOG_FD'
270 AC_LINK_IFELSE([AC_LANG_SOURCE([[int x=0;]])],
271 [cc_produces_so=yes], [cc_produces_so=no])
273 dnl ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS '"$xe_cppflags $xe_ldflags"' conftest.$ac_ext '"$xe_libs"' 1>&AS_MESSAGE_LOG_FD'
278 AC_MSG_RESULT([${cc_produces_so}])
281 if test -z "$LTLD"; then
283 if test "$XEGCC" = yes; then
284 # Check if gcc -print-prog-name=ld gives a path.
285 AC_MSG_CHECKING([for ld used by GCC])
286 ac_prog=`($CC -print-prog-name=ld) 2>&5`
288 # Accept absolute paths.
290 if test -z "$LTLD"; then
292 # *gcc-lib*) LTLD="$CC"
301 # If it fails, then pretend we aren't using GCC.
305 # If it is relative, then search for the first ld in PATH.
310 AC_MSG_CHECKING([for GNU ld])
313 if test -z "$LTLD"; then
314 IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
315 for ac_dir in $PATH; do
316 test -z "$ac_dir" && ac_dir=.
317 if test -f "$ac_dir/$ac_prog"; then
318 LTLD="$ac_dir/$ac_prog"
319 # Check to see if the program is GNU ld. I'd rather use --version,
320 # but apparently some GNU ld's only accept -v.
321 # Break only if it was the GNU/non-GNU ld that we prefer.
322 if "$LTLD" -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null; then
332 if test -n "$LTLD"; then
333 AC_MSG_RESULT([${LTLD}])
338 if test -z "$LTLD" -a "$cc_produces_so" = no; then
339 AC_MSG_ERROR(no acceptable linker found in \$PATH)
345 dnl Order of the tests changed somewhat to prevent repetition
347 ld_dynamic_link_flags=
349 # Check to see if it really is or isn't GNU ld.
350 AC_MSG_CHECKING([if the linker is GNU ld])
351 # I'd rather use --version here, but apparently some GNU ld's only accept -v.
352 if $LTLD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
357 AC_MSG_RESULT([${xe_gnu_ld}])
361 # On these operating systems, we should treat GNU ld like the system ld.
362 gnu_ld_acts_native=yes
365 gnu_ld_acts_native=no
369 if test "$cc_produces_so" = "yes"; then
373 dnl On Darwin, we test with xcldf, but we use xldf
383 # OK - only NOW do we futz about with ld.
384 # See if the linker supports building shared libraries.
385 AC_MSG_CHECKING([whether the linker supports shared libraries])
390 if test "$xe_gnu_ld" = yes && test "$gnu_ld_acts_native" != yes; then
391 # See if GNU ld supports shared libraries.
392 if $LTLD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
394 dll_ldflags="-shared"
400 # PORTME fill in a description of your system's linker (not GNU ld)
411 # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
412 # support. Future versions do this automatically, but an explicit c++rt0.o
413 # doesn't break anything, and helps significantly (at the cost of a little
418 dll_post="/usr/lib/c++rt0.o"
421 # Unfortunately, older versions of FreeBSD 2 don't have this feature.
424 dll_ldflags="-Bshareable"
427 # FreeBSD 3, at last, uses gcc -shared to do shared libraries.
429 dll_ldflags="-shared"
443 # Tested with NetBSD 1.2 ld
458 # For both SCO and Solaris we MAY want to have LDFLAGS include -z text
459 sco3.2v5* | unixware* | sysv5* | sysv4* | solaris2* | solaris7*)
462 *gcc*) dll_ldflags="-shared"
471 if test "$XEGCC" = yes; then
495 AC_MSG_RESULT([${ld_shlibs}])
496 if test "$ld_shlibs" = "no"; then
499 fi # End of if cc_produces_so = no
502 dnl Last thing, check how to get a linked executable to have its symbols
503 dnl exported, so that the modules have access to them.
505 dnl XEmacs FIXME - we need to set ld_dynamic_link_flags properly for
506 dnl most of these systems, which was missing from libtool. I know they
507 dnl all have a way of doing this, but someone needs to look at this
508 dnl for each OS and make sure it is correct. Remember that the arguments
509 dnl are passed when temacs is linked, this is NOT for modules. The sole
510 dnl purpose of the argument is to get the internal XEmacs symbols exposed
511 dnl for modules to use. This means that the COMPILER (and NOT the linker)
512 dnl is most often used to create temacs, so arguments to the linker will
513 dnl usually need to be prefix with ${wl} or some other such thing.
516 if test "$xe_gnu_ld" = yes; then
517 if test "$ld_shlibs" = yes; then
518 ld_dynamic_link_flags="${wl}-export-dynamic"
522 if test -z "$ld_dynamic_link_flags"; then
525 ld_dynamic_link_flags=
529 ld_dynamic_link_flags=
533 ld_dynamic_link_flags=
537 ld_dynamic_link_flags=
541 ld_dynamic_link_flags=
545 ld_dynamic_link_flags="${wl}-E"
549 ld_dynamic_link_flags=
553 ld_dynamic_link_flags=
557 ld_dynamic_link_flags=
561 ld_dynamic_link_flags=
564 solaris2* | solaris7*)
565 ld_dynamic_link_flags=
568 sco3.2v5* | unixware* | sysv5* | sysv4*)
569 ld_dynamic_link_flags="${wl}-Bexport"
573 ld_dynamic_link_flags=
577 ld_dynamic_link_flags=
581 ld_dynamic_link_flags=
585 fi # End of if -z ld_dynamic_link_flags
586 fi # End of if test "$can_build_shared" = "yes"
590 AC_SUBST(dll_ldflags)
593 AC_SUBST(ld_dynamic_link_flags)
594 ])dnl SXE_SHLIB_STUFF
597 AC_DEFUN([SXE_CHECK_LD_ZFLAG], [dnl
598 pushdef([LD_ZFLAG], [$1])
599 pushdef([cv_zflag], [sxe_cv_ld__z_]translit(LD_ZFLAG,[-.=],[___]))
601 AC_CACHE_CHECK([whether linker supports -z ]LD_ZFLAG[],
602 []cv_zflag[], [_SXE_CHECK_LD_ZFLAG(LD_ZFLAG)])
606 ])dnl SXE_CHECK_LD_ZFLAG
608 AC_DEFUN([_SXE_CHECK_LD_ZFLAG], [dnl
609 ## arg1 is the flag to check for
610 pushdef([LD_ZFLAG], [$1])
611 pushdef([cv_zflag], [sxe_cv_ld__z_]translit(LD_ZFLAG,[-.=],[___]))
613 if test "$GCC" = "yes"; then
614 if test "($CC -Xlinker --help 2>&1 | \
615 grep \"-z []LD_ZFLAG[]\" > /dev/null 2>&1 ) "; then
620 elif test -n "$LD"; then
621 if test "($LD --help 2>&1 | \
622 grep \"-z []LD_ZFLAG[]\" > /dev/null 2>&1 )"; then
633 ])dnl _SXE_CHECK_LD_ZFLAG
635 AC_DEFUN([SXE_CHECK_LD_NOCOMBRELOC], [dnl
636 SXE_CHECK_LD_ZFLAG([nocombreloc])
637 ])dnl SXE_CHECK_LD_NOCOMBRELOC
640 AC_DEFUN([SXE_CHECK_LINKER_FLAGS], [dnl
642 SXE_CHECK_LD_ZFLAG([combreloc])
643 SXE_CHECK_LD_ZFLAG([nocombreloc])
645 SXE_CHECK_LD_ZFLAG([defs])
646 SXE_CHECK_LD_ZFLAG([muldefs])
648 SXE_CHECK_LD_ZFLAG([nodefaultlib])
650 SXE_CHECK_LD_ZFLAG([lazy])
651 SXE_CHECK_LD_ZFLAG([now])
652 ])dnl SXE_CHECK_LINKER_FLAGS
654 AC_DEFUN([SXE_PREPEND_LINKER_FLAG], [dnl
655 ## a convenience function to add such linker flags to variables
656 ## arg1 is the flag to add (must include -z if applicable)
657 ## arg2 is the variable whither to prepend
658 pushdef([FLAG], [$1])
659 pushdef([__FLAG], [-Wl,]patsubst([$1], [ ], [[,]]))
662 []VAR[]="[]__FLAG[] $[]VAR[]"
663 if test "$extra_verbose" = "yes"; then
664 echo " Prepending linker flag \"[]__FLAG[]\" to \$[]VAR[]"
670 ])dnl SXE_PREPEND_LINKER_FLAG
672 dnl sxe-linker.m4 ends here