]> granicus.if.org Git - clang/commitdiff
When using -pg targeting OS X 10.8, pass -no_new_main to the linker.
authorBob Wilson <bob.wilson@apple.com>
Tue, 3 Jul 2012 20:42:10 +0000 (20:42 +0000)
committerBob Wilson <bob.wilson@apple.com>
Tue, 3 Jul 2012 20:42:10 +0000 (20:42 +0000)
By default on OS X 10.8, we don't link with a crt1.o file and the linker
knows to use _main as the entry point.  But, when compiling with -pg, we
need to link with the gcrt1.o file, and the linker needs to be told to use
the "start" symbol as the entry point.  The -no_new_main linker option does
that last part.  <rdar://problem/11491405>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159683 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/darwin-ld.c

index c5a837f3d1e54384273499c5cad8b4ca2dc00967..601ea54c2958e48cca318a770fdd6d061f2fa56f 100644 (file)
@@ -4341,6 +4341,9 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
 
             // darwin_crt2 spec is empty.
           }
+          if (getDarwinToolChain().isTargetMacOS() &&
+              !getDarwinToolChain().isMacosxVersionLT(10, 8))
+            CmdArgs.push_back("-no_new_main");
         } else {
           if (Args.hasArg(options::OPT_static) ||
               Args.hasArg(options::OPT_object) ||
index 3206f654d5c0bd33b6b8b44097337d3bd897ec0e..4cda37f9b2e3e0050761f6d7dd14c8e7a551bf44 100644 (file)
 // RUN: %clang -target x86_64-apple-darwin12 -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_NO_CRT1 %s < %t.log
 // LINK_NO_CRT1-NOT: crt
+
+// RUN: %clang -target i386-apple-darwin12 -pg -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_PG %s < %t.log
+// LINK_PG: -lgcrt1.o
+// LINK_PG: -no_new_main