This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: cpp include directory search order warning (mark 2)
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- To: nathan at codesourcery dot com (Nathan Sidwell)
- Cc: zack at codesourcery dot com, gcc-patches at gcc dot gnu dot org
- Date: Fri, 9 Aug 2002 17:56:56 -0400 (EDT)
- Subject: PATCH: cpp include directory search order warning (mark 2)
> 3) Zack's (yet to be written) patch will give you a search order
> (that might be) different to what you asked for, but does fulfil the
> spirit, in that the directory will be searched.
Here is a crack at implementing Zack's suggestion. I didn't implement
any warnings because, if the patch is correct, a -I option will never
reorder the system include chain or cause a system include directory to
be ignored.
I have also enclosed a revised version of the text for install.texi
which I think is somewhat clearer and incorporates previous suggestions.
The current version of that patch has survived bootstrap on hppa-linux
and hppa64-hp-hpux11.00. Regression testing is in progress. I didn't
see any regressions in previous versions. I have manually observed
the effect of adding a system directory with -I to the include chain.
I have checked various alternatives at the quote-bracket boundary.
I have sucessfully built a number of packages which add GCC "system
include" directories to CPPFLAGS under hppa2.0w-hp-hpux11.00
with a previous of the patch. This version does a simpler and more
efficient removal of non-system directories from the quote chain
after it is merged.
Are we getting any closer to a solution?
Dave
--
J. David Anglin dave.anglin@nrc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
2002-08-09 John David Anglin <dave@hiauly1.hia.nrc.ca>
* cppinit.c (remove_dup_dir): Add head_ptr argument to handle removal
at head.
(remove_dup_nonsys_dirs): New function.
(remove_dup_dirs): Change argument head to head_ptr. Remove warnings.
(merge_include_chains): Remove non-system include directories from
quote and bracket include chains when they duplicate equivalent system
directories.
* doc/install.texi (--with-local-prefix): Further document usage of
this option.
Index: cppinit.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.251
diff -u -3 -p -r1.251 cppinit.c
--- cppinit.c 9 Aug 2002 06:19:08 -0000 1.251
+++ cppinit.c 9 Aug 2002 20:39:46 -0000
@@ -95,9 +95,13 @@ static void mark_named_operators PARAMS
static void append_include_chain PARAMS ((cpp_reader *,
char *, int, int));
static struct search_path * remove_dup_dir PARAMS ((cpp_reader *,
+ struct search_path *,
+ struct search_path **));
+static struct search_path * remove_dup_nonsys_dirs PARAMS ((cpp_reader *,
+ struct search_path **,
struct search_path *));
static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
- struct search_path *));
+ struct search_path **));
static void merge_include_chains PARAMS ((cpp_reader *));
static bool push_include PARAMS ((cpp_reader *,
struct pending_option *));
@@ -260,55 +264,86 @@ append_include_chain (pfile, dir, path,
}
/* Handle a duplicated include path. PREV is the link in the chain
- before the duplicate. The duplicate is removed from the chain and
- freed. Returns PREV. */
+ before the duplicate, or NULL if the duplicate is at the head of
+ the chain. The duplicate is removed from the chain and freed.
+ Returns PREV. */
static struct search_path *
-remove_dup_dir (pfile, prev)
+remove_dup_dir (pfile, prev, head_ptr)
cpp_reader *pfile;
struct search_path *prev;
+ struct search_path **head_ptr;
{
- struct search_path *cur = prev->next;
+ struct search_path *cur;
+
+ if (prev != NULL)
+ {
+ cur = prev->next;
+ prev->next = cur->next;
+ }
+ else
+ {
+ cur = *head_ptr;
+ *head_ptr = cur->next;
+ }
if (CPP_OPTION (pfile, verbose))
fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
- prev->next = cur->next;
free ((PTR) cur->name);
free (cur);
return prev;
}
+/* Remove duplicate non-system directories for which there is an equivalent
+ system directory latter in the chain. The range for removal is between
+ *HEAD_PTR and END. Returns the directory before END, or NULL if none.
+ This algorithm is quadratic in the number of -I switches, which is
+ acceptable since there aren't usually that many of them. */
+static struct search_path *
+remove_dup_nonsys_dirs (pfile, head_ptr, end)
+ cpp_reader *pfile;
+ struct search_path **head_ptr;
+ struct search_path *end;
+{
+ struct search_path *prev = NULL, *cur, *other;
+
+ for (cur = *head_ptr; cur != end; cur = cur ? cur->next : *head_ptr)
+ {
+ if (!cur->sysp)
+ {
+ for (other = cur->next; other; other = other->next)
+ if (INO_T_EQ (cur->ino, other->ino)
+ && cur->dev == other->dev
+ && other->sysp)
+ {
+ cur = remove_dup_dir (pfile, prev, head_ptr);
+ break;
+ }
+ }
+ prev = cur;
+ }
+
+ return prev;
+}
+
/* Remove duplicate directories from a chain. Returns the tail of the
chain, or NULL if the chain is empty. This algorithm is quadratic
in the number of -I switches, which is acceptable since there
aren't usually that many of them. */
static struct search_path *
-remove_dup_dirs (pfile, head)
+remove_dup_dirs (pfile, head_ptr)
cpp_reader *pfile;
- struct search_path *head;
+ struct search_path **head_ptr;
{
struct search_path *prev = NULL, *cur, *other;
- for (cur = head; cur; cur = cur->next)
+ for (cur = *head_ptr; cur; cur = cur->next)
{
- for (other = head; other != cur; other = other->next)
+ for (other = *head_ptr; other != cur; other = other->next)
if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
{
- if (cur->sysp && !other->sysp)
- {
- cpp_error (pfile, DL_WARNING,
- "changing search order for system directory \"%s\"",
- cur->name);
- if (strcmp (cur->name, other->name))
- cpp_error (pfile, DL_WARNING,
- " as it is the same as non-system directory \"%s\"",
- other->name);
- else
- cpp_error (pfile, DL_WARNING,
- " as it has already been specified as a non-system directory");
- }
- cur = remove_dup_dir (pfile, prev);
+ cur = remove_dup_dir (pfile, prev, head_ptr);
break;
}
prev = cur;
@@ -346,28 +381,33 @@ merge_include_chains (pfile)
else
brack = systm;
- /* This is a bit tricky. First we drop dupes from the quote-include
- list. Then we drop dupes from the bracket-include list.
- Finally, if qtail and brack are the same directory, we cut out
- brack and move brack up to point to qtail.
+ /* This is a bit tricky. First we drop non-system dupes of system
+ directories from the merged bracket-include list. Next we drop
+ dupes from the bracket and quote include lists. Then we drop
+ non-system dupes from the merged quote-include list. Finally,
+ if qtail and brack are the same directory, we cut out brack and
+ move brack up to point to qtail.
We can't just merge the lists and then uniquify them because
then we may lose directories from the <> search path that should
- be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
+ be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
-Ibar -I- -Ifoo -Iquux. */
- remove_dup_dirs (pfile, brack);
- qtail = remove_dup_dirs (pfile, quote);
+ remove_dup_nonsys_dirs (pfile, &brack, NULL);
+ remove_dup_dirs (pfile, &brack);
if (quote)
{
+ qtail = remove_dup_dirs (pfile, "e);
qtail->next = brack;
+ qtail = remove_dup_nonsys_dirs (pfile, "e, brack);
+
/* If brack == qtail, remove brack as it's simpler. */
- if (brack && INO_T_EQ (qtail->ino, brack->ino)
+ if (qtail && brack && INO_T_EQ (qtail->ino, brack->ino)
&& qtail->dev == brack->dev)
- brack = remove_dup_dir (pfile, qtail);
+ brack = remove_dup_dir (pfile, qtail, "e);
}
else
quote = brack;
Index: doc/install.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.131
diff -u -3 -p -r1.131 install.texi
--- doc/install.texi 8 Aug 2002 09:10:39 -0000 1.131
+++ doc/install.texi 9 Aug 2002 20:39:47 -0000
@@ -467,6 +467,43 @@ any in that directory---are not part of
programs---perhaps many others. (GCC installs its own header files in
another directory which is based on the @option{--prefix} value.)
+Both the local-prefix include directory and the GCC-prefix include
+directory are part of GCC's "system include" directories. Although these
+two directories are not fixed, they need to be searched in the proper
+order for the correct processing of the include_next directive. The
+local-prefix include directory is searched before the GCC-prefix
+include directory. Another characteristic of system include directories
+is that pedantic warnings are turned off for headers in these directories.
+
+Some autoconf macros add @option{-I @var{directory}} options to the
+compiler command line, to ensure that directories containing installed
+packages' headers are searched. When @var{directory} is one of GCC's
+system include directories, GCC will ignore the option so that system
+directories are continued to be processed in the correct order. This
+may result in a search order different from what was specified but the
+directory will still be searched.
+
+GCC automatically searches for ordinary libraries using
+@env{GCC_EXEC_PREFIX}. Thus, when the same installation prefix is
+used for both GCC and packages, GCC will automatically search for
+both headers and libraries. This provides a configuration that is
+easy to use. GCC behaves in a manner similar to that when it is
+installed as a system compiler in @file{/usr}.
+
+Sites that need to install multiple versions of GCC may not want to
+use the above simple configuration. It is possible to use the
+@option{--program-prefix}, @option{--program-suffix} and
+@option{--program-transform-name} options to install multiple versions
+into a single directory, but it may be simpler to use different prefixes
+and the @option{--with-local-prefix} option to specify the location of the
+site-specific files for each version. It will then be necessary for
+users to specify explicitly the location of local site libraries
+(e.g., with @env{LIBRARY_PATH}).
+
+The same value can be used for both @option{--with-local-prefix} and
+@option{--prefix} provided it is not @file{/usr}. This can be used
+to avoid the default search of @file{/usr/local/include}.
+
@strong{Do not} specify @file{/usr} as the @option{--with-local-prefix}!
The directory you use for @option{--with-local-prefix} @strong{must not}
contain any of the system's standard header files. If it did contain