Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apple's -fast flag and Gentoo
View unanswered posts
View posts from last 24 hours

 
This topic is locked: you cannot edit posts or make replies.    Gentoo Forums Forum Index Gentoo for Mac OS X (Portage for Mac OS X)
View previous topic :: View next topic  
Author Message
dete
n00b
n00b


Joined: 07 Dec 2004
Posts: 10

PostPosted: Thu Mar 17, 2005 3:15 am    Post subject: Apple's -fast flag and Gentoo Reply with quote

It seems to me that the ideal flag to be using in CFLAGS for Gentoo on OSX is Apple's -fast flag. Basically, this switch turns on a boatload of optimizations with the intention of produced the fastest code possible. There is, however, one problem: The -fast flag turns on -mdynamic-no-pic by default. This means that the code generated can't be used in a shared library. The fix for this is to combine -fast with -fPIC (a platform-independent GCC flag meaning "generate Position Independent Code). However, you ideally want to only use -fPIC when you really need it, since there can be as much as a 5% speed hit when it's on.

At first glance, it seems like this is an easy problem to solve since several common platforms (including x86 Linux!) require -fPIC for shared code, and therefore, most Makefiles have the logic to deal with building dynamic and static objects separately with different flag settings. However, my investigations show that the standard gnu config scripts special-case Mac OS X and do NOT use -fPIC for dynamic objects since, in the absence of the -fast flag, -fPIC is on by default. So, there are probably hundreds of packages which specifically avoid using -fPIC on OS X...

My first thought was just to create patches for each of these packages, but this gets out of hand VERY quickly, the aforementioned GNU config files are very hairy and hand creating each patch could be a WHOLE lot of work.

One thing has occurred to me, however. The basic structure of all of those config files is about the same; in fact, the lines that need to be changed are very nearly identical. It should be possible -- indeed easy -- to create a script that would be invoked during unpacking that would look for those lines in config* files and update them appropriately.

My first question: Which is preferable?
  1. Invoking such a script automatically whenever unpacking code (on OS X).
  2. Adding a new eclass which must be explicitly included/called from ebuilds which would benefit from the auto-patching.


APPENDIX

This is what the configure scripts look like now (taken from gettext):
Code:
    darwin* | rhapsody*)
      # PIC is the default on this platform
      # Common symbols not allowed in MH_DYLIB files
      lt_prog_compiler_pic='-fno-common'
      ;;

And this is how they need to look in order to work with -fast:
Code:
    darwin* | rhapsody*)
      # Common symbols not allowed in MH_DYLIB files
      lt_prog_compiler_pic='-fno-common -fPIC'
      ;;

Note that there are several lines like this in each configure file, and in many packages (gettext is one) there are multiple configure scripts. In fact, gettext alone has 44 instances where the change is required!
Back to top
View user's profile Send private message
watersb
Apprentice
Apprentice


Joined: 04 Sep 2002
Posts: 287
Location: where the hell is Tesuque, New Mexico?

PostPosted: Fri May 13, 2005 11:02 pm    Post subject: Reply with quote

Excellent post!

Just a comment: I've been using

Code:
CFLAGS="-fast -mcpu=7450 -fPIC -pipe"


for a long time... some basic things break, and when they fail to compile, they break in very odd ways (the compiler error message is NOT a readable, "Please don't use -fast", but instead is something in martian like ".__DATA linkage cruft").

As I'm typing this, gnupg failed to build because of -fast; use -O2 for that one!

[/code]
Back to top
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies.    Gentoo Forums Forum Index Gentoo for Mac OS X (Portage for Mac OS X) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum