New Ticket     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Ticket #16634 (closed defect: fixed)

Opened 17 months ago

Last modified 9 months ago

__gnu_inline__ attribute directive and Apple's gcc

Reported by: jhr@… Owned by: mcalhoun@…
Priority: Normal Milestone:
Component: ports Version: 1.6.0
Keywords: gmp, inline Cc: raimue@…
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

patch-gmp-gnu-inline.diff Download (1.2 KB) - added by raimue@… 16 months ago.

Change History

Changed 16 months ago by raimue@…

  • 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 months ago by raimue@…

Changed 13 months 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

Changed 13 months 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

Changed 10 months ago by anonymous

  • milestone Port Bugs deleted

Milestone Port Bugs deleted

Changed 10 months ago by raimue@…

  • owner changed from macports-tickets@… to mcalhoun@…

Changed 9 months ago by mcalhoun@…

  • status changed from new to closed
  • resolution set to fixed

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.