This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Relocated cpp must not search configured prefix.
- From: Carlos O'Donell <carlos at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Andrew Pinski <pinskia at physics dot uc dot edu>, Ian Lance Taylor <iant at google dot com>, Mark Mitchell <mark at codesourcery dot com>, Gabriel Dos Reis <gdr at integrable-solutions dot net>, Eric Weddington <eweddington at cso dot atmel dot com>, Danny Smith <dannysmith at clear dot net dot nz>
- Date: Fri, 13 Oct 2006 12:55:56 -0400
- Subject: [PATCH] Relocated cpp must not search configured prefix.
A relocated compiler should never search the configured prefix.
The configured prefix may be a network path, or contain other
conflicting tools.
CPP should not search for headers in the configured prefix. When
searching for headers, all instances of the configured prefix should be
replaced with the relocated prefix.
In the case when testing from the objdir, the previous patch:
http://gcc.gnu.org/ml/gcc/2006-10/msg00280.html
Will provide the correct value for GCC_EXEC_PREFIX.
This is the second of two patches required to fix pr17621.
This patch: http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00096.html
Is required before this patch can be applied, as the NONE in the
PREFIX_INCLUDE_DIR is not expected.
Tested on x86_64-unknown-linug-gnu, arm-none-eabi,
arm-none-linux-gnueabi.
Comments?
OK for stage1?
Cheers,
Carlos.
--
Carlos O'Donell
CodeSourcery
carlos@codesourcery.com
(650) 331-3385 x716
2006-10-13 Carlos O'Donell <carlos@codesourcery.com>
Mark Mitchell <mark@codesourcery.com>
* cppdefault.c: Define cpp_STANDARD_EXEC_PREFIX,
cpp_STANDARD_EXEC_PREFIX_len, and gcc_exec_prefix.
(cpp_relocated): New function.
* cppdefault.h: Declare cpp_STANARD_EXEC_PREFIx,
cpp_STANARD_EXEC_PREFIX_len, gcc_exec_prefix and cpp_relocated.
* Makefile.in (PREPROCESSOR_DEFINES): Add -DSTANDARD_EXEC_PREFIX
option.
* c-incpath.c (add_standard_paths): Call cpp_relocated. If relocated
replace configured prefix with gcc_exec_prefix.
Index: gcc/cppdefault.c
===================================================================
--- gcc/cppdefault.c (revision 117699)
+++ gcc/cppdefault.c (working copy)
@@ -96,3 +96,31 @@ const size_t cpp_GCC_INCLUDE_DIR_len = s
const char cpp_GCC_INCLUDE_DIR[] = "";
const size_t cpp_GCC_INCLUDE_DIR_len = 0;
#endif
+
+/* The configured standard exec prefix */
+const char cpp_STANDARD_EXEC_PREFIX[] = STANDARD_EXEC_PREFIX;
+const size_t cpp_STANDARD_EXEC_PREFIX_len = sizeof STANDARD_EXEC_PREFIX - 1;
+
+/* This value is set by cpp_relocated at runtime */
+const char *gcc_exec_prefix;
+
+/* Return true if the toolchain is relocated. */
+bool
+cpp_relocated (void)
+{
+ static int relocated = -1;
+
+ /* A relocated toolchain ignores standard include directories. */
+ if (relocated == -1)
+ {
+ /* Check if the toolchain was relocated? */
+ GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX");
+ if (gcc_exec_prefix)
+ relocated = 1;
+ else
+ relocated = 0;
+ }
+
+ return relocated;
+}
+
Index: gcc/cppdefault.h
===================================================================
--- gcc/cppdefault.h (revision 117699)
+++ gcc/cppdefault.h (working copy)
@@ -52,4 +52,11 @@ extern const struct default_include cpp_
extern const char cpp_GCC_INCLUDE_DIR[];
extern const size_t cpp_GCC_INCLUDE_DIR_len;
+extern const char cpp_STANDARD_EXEC_PREFIX[];
+extern const size_t cpp_STANDARD_EXEC_PREFIX_len;
+extern const char *gcc_exec_prefix;
+
+/* Return true if the toolchain is relocated. */
+bool cpp_relocated (void);
+
#endif /* ! GCC_CPPDEFAULT_H */
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in (revision 117699)
+++ gcc/Makefile.in (working copy)
@@ -3068,6 +3068,7 @@ PREPROCESSOR_DEFINES = \
-DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
-DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
-DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
+ -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
@TARGET_SYSTEM_ROOT_DEFINE@
cppdefault.o: cppdefault.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
Index: gcc/c-incpath.c
===================================================================
--- gcc/c-incpath.c (revision 117699)
+++ gcc/c-incpath.c (working copy)
@@ -127,6 +127,7 @@ add_standard_paths (const char *sysroot,
const char *imultilib, int cxx_stdinc)
{
const struct default_include *p;
+ int relocated = cpp_relocated();
size_t len;
if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0)
@@ -163,6 +164,17 @@ add_standard_paths (const char *sysroot,
/* Should this directory start with the sysroot? */
if (sysroot && p->add_sysroot)
str = concat (sysroot, p->fname, NULL);
+ else if (!p->add_sysroot && relocated)
+ {
+ /* If the compiler is relocated, and this is a configured
+ prefix relative path, then we use gcc_exec_prefix instead
+ of the configured prefix. */
+ gcc_assert (strncmp (p->fname, cpp_STANDARD_EXEC_PREFIX,
+ cpp_STANDARD_EXEC_PREFIX_len) == 0);
+ str = concat (gcc_exec_prefix, p->fname
+ + cpp_STANDARD_EXEC_PREFIX_len, NULL);
+ str = update_path (str, p->component);
+ }
else
str = update_path (p->fname, p->component);