ABI defaults

Niels Möller nisse at lysator.liu.se
Wed Nov 17 15:11:57 CET 2010


Torbjorn Granlund <tg at gmplib.org> writes:

> It is not clear how to deterimine it, though.  Clearly, we have to run
> the compiler, and then check properties of it.

In nettle I do the following, trusting preprocessor values set by the
compiler.

  # Figure out ABI. Currently, configurable only by setting CFLAGS.
  ABI=standard

  case "$host_cpu" in
    [x86_64 | amd64])
      AC_TRY_COMPILE([
  #if defined(__x86_64__) || defined(__arch64__)
  #error 64-bit x86
  #endif
      ], [], [
        ABI=32
      ], [
        ABI=64
      ])
      ;;
    *sparc*)
      AC_TRY_COMPILE([
  #if defined(__sparcv9) || defined(__arch64__)
  #error 64-bit sparc
  #endif
      ], [], [
        ABI=32
      ], [
        ABI=64
      ])
      ;;
  esac

Currently handles only {sparc|x86_64}-{linux|bsd|solaris}, and at most two
ABIs, but I think it could be extended without getting too unwieldy (and
there's no strong need to have the detection support any platform which
we don't have some assembler files for).

And then I have the following libdir-hack:

  if test "x$ABI" != xstandard ; then
    AC_MSG_NOTICE([Compiler uses $ABI-bit ABI. To change, set CC.])
    if test "$libdir" = '${exec_prefix}/lib' ; then
      # Try setting a better default
      case "$host_cpu:$host_os:$ABI" in
        *:solaris*:32|*:sunos*:32)
        libdir='${exec_prefix}/lib'
        ;;
        *:solaris*:64|*:sunos*:64)
        libdir='${exec_prefix}/lib/64'
        ;;
        # According to the fhs, all architectures except IA64
        # puts 32-bit libraries in lib, and 64-bit in lib64.
        *:linux*:32)
        libdir='${exec_prefix}/lib'
        ;;
        *:linux*:64)
        libdir='${exec_prefix}/lib64'
        ;;
        # On freebsd, it seems 32-bit libraries are in lib32,
        # and 64-bit in lib. Don't know about "kfreebsd", does
        # it follow the Linux fhs conventions?
        *:freebsd*:32)
        libdir='${exec_prefix}/lib32'
        ;;
        *:freebsd*:64)
        libdir='${exec_prefix}/lib'
        ;;
        *)
          AC_MSG_WARN([Don't know where to install $ABI-bit libraries on this system.]); #'
  
      esac
      AC_MSG_NOTICE([Libraries to be installed in $libdir.])
    fi
  fi

> Checking the width of types is standard autoconf stuff, and it gives
> some information. 

Do you think it's too fragile to rely on preprocessor constants?

> I'd try writing this as a separate script, designed to be invoked from
> 'configure' and expecting parameters for plain type sizes.  These sizes
> are most easily figured out by configure:

Might need cpu type and operating system too? No matter if it's a
separate script or inlined in configure, I guess a

   case "$host_cpu:$host_os:$longlong_size:$long_size:$int_size"

should get you quite far.

Regards,
/Niels
-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list