diff mbox

[Darwin,driver] Make our sysroot handling the same as clang's.

Message ID 825FAE2A-2E50-4EFC-9CE4-167A50F4830E@mentor.com
State New
Headers show

Commit Message

Iain Sandoe Sept. 12, 2015, 3:02 p.m. UTC
Hi,

At present, we have somewhat strange sysroot in that --sysroot causes -isysroot to be passed to cc1* ...
... but no -syslibroot for collect2/ld.
Conversely, -isysroot /XYZZY causes this to be passed as -isysroot to cc1* and -syslibroot to collect/ld.

AFAIU the options, it ought to be the other way around.

However (possibly to be 'compatible' with GCC) currently clang has the same behaviour for both -isysroot and --sysroot.

In preparation for other improvements, I want to use the --sysroot properly, so the following patch makes GCC's behaviour match that of clang (for the Darwin platform only).  TODO: is to start a joint conversation with the clang folks about retiring the -syslibroot from the "-isysroot" case ( but that ship might have sailed - this behaviour is already "in the wild" ).

checked out with x86_64-darwin12 and an i686-darwin9 X x86_64-darwin12 cross, where the built-in configured --with-sysroot= is correctly overridden by --sysroot= on the c/l.

Unfortunately, other than detecting the version of ld in use, there's no sensible configure mechanism to set HAVE_LD_SYSROOT, and it seems somewhat overkill to do that for something that's essentially a constant for the versions of ld that work with current GCC.

OK for trunk?
Iain

gcc/
	* config/darwin.h (TARGET_SYSTEM_ROOT): Remove this from here (use the mechanism ing gcc.c)
	driven by - (HAVE_LD_SYSROOT): New. (SYSROOT_SPEC): New. 
	(LINK_SYSROOT_SPEC): Revise to remove the default for target sysroot.
	(STANDARD_STARTFILE_PREFIX_1): New.
	(STANDARD_STARTFILE_PREFIX_2): New.
From 3d20de66ec2e7da5f371175253f01d0dd74dc8c0 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@codesourcery.com>
Date: Fri, 11 Sep 2015 23:39:35 +0100
Subject: [PATCH] [darwin] Make sysroot stuff the same as clang

---
 gcc/config/darwin.h | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Comments

Mike Stump Sept. 13, 2015, 8:32 p.m. UTC | #1
On Sep 12, 2015, at 8:02 AM, Iain Sandoe <Iain_Sandoe@mentor.com> wrote:
> OK for trunk?

So, does this work on 10.3?  ppc?  ppc64?  You modify darwin.h, and that file is used everywhere.

If it really works everywhere, Ok.

If it doesn’t, then it should be in a file that is used only on the systems that support it.  Ok, if you figure it is less than universal and needs to go some other place.
Iain Sandoe Sept. 13, 2015, 8:59 p.m. UTC | #2
Hi Mike,

On 13 Sep 2015, at 21:32, Mike Stump wrote:

> On Sep 12, 2015, at 8:02 AM, Iain Sandoe <Iain_Sandoe@mentor.com> wrote:
>> OK for trunk?

chose this comment carefully : " for something that's essentially a constant for the versions of ld that work with current GCC. "

> So, does this work on 10.3?

not on its own .. see below.

>  ppc?  ppc64?  You modify darwin.h, and that file is used everywhere.

yes - for ld64-85.2 xcode 3.1.4 - (10.5) 
(I believe it's supported by ld64-62.1 XC 2.5 on 10.4) - but that toolchain has some problems building modern GCC (strip etc).

> If it really works everywhere, Ok.

.. So it works everywhere that has a toolchain that can build current GCC.

10.3's (1.5) xcode has been incapable of building GCC since ~ transition to c++.

> If it doesn’t, then it should be in a file that is used only on the systems that support it.  Ok, if you figure it is less than universal and needs to go some other place.

** if there's any sensible thing that can be done for modern GCC with xc 1.5 or less (which i doubt).
I think that the place to over-ride would be in some rs6000/darwin7.h

====

The generic solution (actually, made already but not posted) is that I've made a forward-port of the ppc stuff to current ld64, and also fixed up some issues with cctools.. probably tedious to build that lot on 10.3 - but .. if you want c++11 support on 10.3 (or even to build cc1 using a c++ compiler), the native tools are not going to cut the mustard....

---

In the end, we're going to need to use a fixed set of "binutils" for Darwin it's too difficult to span the ages ...
(or drop support for older systems, which I'd rather not do).

WDYT? I can revise the patch if you think there's a Better Way to do it.

Iain
Mike Stump Sept. 13, 2015, 10:43 p.m. UTC | #3
On Sep 13, 2015, at 1:59 PM, Iain Sandoe <Iain_Sandoe@mentor.com> wrote:
> chose this comment carefully : " for something that's essentially a constant for the versions of ld that work with current GCC. “

> WDYT? I can revise the patch if you think there's a Better Way to do it.

So, I tried to check around and see on what darwin was it new.  Geoff put the code to handle it (c100559) into darwin.h, so, darwin.h it is.  I was thinking it was newer than that, maybe not.  Ideally I was interested in, on what OS was it new?  Anyway, not a big point, because if someone wanted to use a very old OS, they could move the bits to the right location if they were in the wrong location.

Ok as is.
diff mbox

Patch

diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index bb4451a..7d093c9 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -207,12 +207,21 @@  extern GTY(()) int darwin_ms_struct;
 #undef  LINK_GCC_C_SEQUENCE_SPEC
 #define LINK_GCC_C_SEQUENCE_SPEC "%G %L"
 
-#ifdef TARGET_SYSTEM_ROOT
-#define LINK_SYSROOT_SPEC \
-  "%{isysroot*:-syslibroot %*;:-syslibroot " TARGET_SYSTEM_ROOT "}"
-#else
+/* ld64 supports a sysroot, it just has a different name and there's no easy
+   way to check for it at config time.  */
+#undef HAVE_LD_SYSROOT
+#define HAVE_LD_SYSROOT 1
+/* It seems the only (working) way to get a space after %R is to append a
+   dangling '/'.  */
+#define SYSROOT_SPEC "%{!isysroot*:-syslibroot %R/ }"
+
+/* Do the same as clang, for now, and insert the sysroot for ld when an
+   isysroot is specified.  */
 #define LINK_SYSROOT_SPEC "%{isysroot*:-syslibroot %*}"
-#endif
+
+/* Suppress the addition of extra prefix paths when a sysroot is in use.  */
+#define STANDARD_STARTFILE_PREFIX_1 ""
+#define STANDARD_STARTFILE_PREFIX_2 ""
 
 #define DARWIN_PIE_SPEC "%{fpie|pie|fPIE:}"