Opened 16 years ago

Closed 15 years ago

#16634 closed defect (fixed)

__gnu_inline__ attribute directive and Apple's gcc

Reported by: jhr@… Owned by: MarcusCalhoun-Lopez (Marcus Calhoun-Lopez)
Priority: Normal Milestone:
Component: ports Version: 1.6.0
Keywords: gmp, inline Cc: raimue (Rainer Müller)
Port: gmp

Description

I am trying to build the MLton SML compiler (http://mlton.org), which uses the gmp library. When compiling the runtime system, linking is failing because of multiple definitions of some of the GMP symbols (such as ___gmpz_abs). I've done some digging, and it seems that the source of the problem is related to a recent change in gmp.h and a bad interaction with Apple's version of gcc. Specifically, the __gnu_inline__ attribute directive is causing problems (see http://www.mail-archive.com/bug-gnulib@gnu.org/msg09721.html for some discussion; a latter message in the thread proposes a patch).

Attachments (1)

patch-gmp-gnu-inline.diff (1.2 KB) - added by raimue (Rainer Müller) 16 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 16 years ago by raimue (Rainer Müller)

Cc: raimue@… added

The best would be to retrieve the patch from upstream directly if we want to apply it to the current version and do not just wait for the next release. But I was unable to locate a source repository.

I found the patch submission to upstream, but I don't know if further action was taken. Will attach the patch from there to this ticket.

Changed 16 years ago by raimue (Rainer Müller)

Attachment: patch-gmp-gnu-inline.diff added

comment:2 Changed 15 years ago by jhr@…

I just tried the most recent version of gmp from MacPorts (4.2.4) and the above patch does not work. The following patch fixes the problem for me (NEWgmp.h is the correct file).

* NEWgmp.h 2009-01-02 14:31:02.000000000 -0600 --- gmp.h 2009-01-01 13:58:09.000000000 -0600 * * 421,433

GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 inline semantics, unless -fgnu89-inline is used. */

#ifdef GNUC

! #if GNUC > 4
(GNUC == 4 && GNUC_MINOR >= 2)

#define GMP_EXTERN_INLINE extern inline attribute ((gnu_inline))

! #define GMP_INLINE_PROTOTYPES 1 ! #elif !(defined APPLE && defined MACH && APPLE_CC >= 5465 && STDC_VERSION >= 199901L)

#define GMP_EXTERN_INLINE extern inline

  • #define GMP_INLINE_PROTOTYPES 1 #endif #endif

/* DEC C (eg. version 5.9) supports "static inline foo()", even in -std1

--- 421,432 ----

GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 inline semantics, unless -fgnu89-inline is used. */

#ifdef GNUC

! #if (defined GNUC_STDC_INLINE)
(GNUC == 4 && GNUC_MINOR == 2)

#define GMP_EXTERN_INLINE extern inline attribute ((gnu_inline))

! #else

#define GMP_EXTERN_INLINE extern inline #endif

+ #define GMP_INLINE_PROTOTYPES 1

#endif

/* DEC C (eg. version 5.9) supports "static inline foo()", even in -std1

comment:3 Changed 15 years ago by jhr@…

Let's try that again with correct formatting:

*** NEWgmp.h	2009-01-02 14:31:02.000000000 -0600
--- gmp.h	2009-01-01 13:58:09.000000000 -0600
***************
*** 421,433 ****
      GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
      inline semantics, unless -fgnu89-inline is used.  */
  #ifdef __GNUC__
! #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
  #define __GMP_EXTERN_INLINE extern __inline__ __attribute__ ((__gnu_inline__))
! #define __GMP_INLINE_PROTOTYPES  1
! #elif !(defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && __STDC_VERSION__ >= 199901L)
  #define __GMP_EXTERN_INLINE      extern __inline__
- #define __GMP_INLINE_PROTOTYPES  1
  #endif
  #endif
  
  /* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1
--- 421,432 ----
      GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
      inline semantics, unless -fgnu89-inline is used.  */
  #ifdef __GNUC__
! #if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2)
  #define __GMP_EXTERN_INLINE extern __inline__ __attribute__ ((__gnu_inline__))
! #else
  #define __GMP_EXTERN_INLINE      extern __inline__
  #endif
+ #define __GMP_INLINE_PROTOTYPES  1
  #endif
  
  /* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1

comment:4 Changed 15 years ago by (none)

Milestone: Port Bugs

Milestone Port Bugs deleted

comment:5 Changed 15 years ago by raimue (Rainer Müller)

Owner: changed from macports-tickets@… to mcalhoun@…

comment:6 Changed 15 years ago by MarcusCalhoun-Lopez (Marcus Calhoun-Lopez)

Resolution: fixed
Status: newclosed

Just to summarize the situation:

  • The C99 and GNU extension "extern inline" are different.
  • gmp.h requires GNU extension behavior.
  • When in C99 mode is set with -std, gmp.h tries to force GNU extension inline behavior using "__attribute__ ((__gnu_inline__))".

Problems:

  • In C99 mode, there does not seem to be a way to force the Apple GCC 4.0 to use GNU inline behavior.
  • In some older Apple GCC versions, __GNUC_STDC_INLINE__ was not defined even in C99 mode.

Possible Solutions:

  • Turn off inlining when using Apple GCC version 4.0 in C99 mode.
  • Patch gmp.h to work with C99 inline behavior.

The first options is the easiest and was incorporated in r50566.

Note: See TracTickets for help on using tickets.