https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84257

            Bug ID: 84257
           Summary: Extremely slow compilation from gcc source code under
                    macOS 10.13
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 191919 at gmail dot com
  Target Milestone: ---

In fact, this problem exists since very old version of gcc, but only in macOS
10.13 with SIP (System Integrity Protection) disabled.

I upgraded my Mac from 10.12.6 to 10.13.3 and recompiled gcc, the compilation
time is about 5 times longer. To be exactly, it is not the compilation which
was slowed down, but the configure step. Every single output, like 'checking
build system type... x86_64-apple-darwin17.4.0', takes more time than in
10.12.6. This check, 'checking compiler gcc -g  ... yes' takes about 7 seconds.
The entire compilation was unbearable SIX hours.

I ran a lot of checks and found that this only happens when compiling gcc.
Other autoconf based configure script, such as php and mysql, runs as fast as
before. And even inside gcc, if I run configure for gmp or isl in a separated
terminal session, it is still as fast as before.

Finally I found the problem is caused by the DYLD_LIBRARY_PATH environment
variable which during the configuration process is

/mv/objs/./gmp/.libs:/mv/objs/./prev-gmp/.libs:/mv/objs/./mpfr/src/.libs:/mv/objs/./prev-mpfr/src/.libs:/mv/objs/./mpc/src/.libs:/mv/objs/./prev-mpc/src/.libs:/mv/objs/./isl/.libs:/mv/objs/./prev-isl/.libs:/mv/objs/x86_64-apple-darwin17.3.0/libstdc++-v3/src/.libs:/mv/objs/x86_64-apple-darwin17.3.0/libsanitizer/.libs:/mv/objs/x86_64-apple-darwin17.3.0/libcilkrts/.libs:/mv/objs/x86_64-apple-darwin17.3.0/libssp/.libs:/mv/objs/x86_64-apple-darwin17.3.0/libgomp/.libs:/mv/objs/x86_64-apple-darwin17.3.0/libitm/.libs:/mv/objs/x86_64-apple-darwin17.3.0/libatomic/.libs:/mv/objs/./gcc:/mv/objs/./prev-gcc

(where /mv/objs is where I ran the configure script.)

The change of value of DYLD_LIBRARY_PATH was introduced by the root Makefile

...
        $(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed
's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
        $(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed
's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
...

then exported, in macOS 10.13.3 with SIP enabled, the DYLD_LIBRARY_PATH
environment variable will be automatically ignored, but my Mac has had SIP
disabled, so DYLD_LIBRARY_PATH got exported and every single step after that,
the mach-o loader will  be affected. In macOS 10.12.6, even with SIP disabled,
the compilation speed is not affected.

I commented out this line in the root Makefile:

RPATH_ENVVAR = DYLD_LIBRARY_PATH

(BTW, in ChangeLog, I know this was brought by this:

2005-03-25  Paolo Bonzini  <bonz...@gnu.org>

        * configure.in (RPATH_ENVVAR): Set to DYLD_LIBRARY_PATH on Darwin.
        * configure: Regenerate.
)

and recompiled gcc, this time, it took only *30 minutes* (vs. 6 hours).

I don't think setting RPATH_ENVVAR to DYLD_LIBRARY_PATH is necessary on modern
macOS versions, please check.

Reply via email to