This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Conditional MD_STARTFILE_PREFIXes
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Conditional MD_STARTFILE_PREFIXes
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Tue, 25 Jan 2000 12:28:07 +0100
Hi!
Current sparc BI_ARCH compiler has problems because when compiling
64bit target, it has wrong startfile_prefixes (it includes /usr/lib and /lib
but does not include /usr/lib64 nor /lib64 on Linux, so it finds wrong
files). Although link_spec includes -Y P,/usr/lib64, that's a path used as a
default, but gcc passes -L/usr/lib (and the same even before that as
-L/usr/lib/gcc-lib/sparc64-redhat-linux/2.96/../../..).
Solaris has the same problem (the non-BI_ARCH compiler there even defines
MD_STARTFILE_PREFIX "/usr/lib/sparcv9" but the BI_ARCH compiler cannot
because its wrong if you're compiling with -m32).
So, after some investigation of the gcc driver, I wrote following patch
which solves this (and IMHO might be potentially useful for Irix6 and other
systems). Basically, MD_STARTFILE_PREFIX may include some limited subsect of
the spec %-sequences, so that e.g.:
#define MD_STARTFILE_PREFIX "%{!m32:/usr/lib64/}"
will cause /usr/lib64 to be added as startfile prefix iff -m32 was not given
on the command line.
I've added a simple_spec routine which passes a simple spec string and
returns the result as a string (I think it might be useful for other things
as well, am just investigating some other uses for it).
2000-01-25 Jakub Jelinek <jakub@redhat.com>
* gcc.c (simple_spec): New function.
(main): Use it for MD_STARTFILE_PREFIX and MD_STARTFILE_PREFIX_1.
* config/sparc/linux64.h (MD_STARTFILE_PREFIX,
MD_STARTFILE_PREFIX_1): Define to /usr/lib64/:/lib64/ if compiling
for 64bit target.
(STARTFILE_SPEC, ENDFILE_SPEC, LINK_ARCH_SPEC): Simplify.
(link_default, LINK_DEFAULT_SPEC): Remove.
* config/sparc/sol2-sld-64.h (MD_STARTFILE_PREFIX): Define even
for SPARC_BI_ARCH compiler.
--- gcc/config/sparc/linux64.h.jj Tue Dec 14 17:12:10 1999
+++ gcc/config/sparc/linux64.h Tue Jan 25 11:51:30 2000
@@ -1,5 +1,5 @@
/* Definitions for 64-bit SPARC running Linux-based GNU systems with ELF.
- Copyright 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
Contributed by David S. Miller (davem@caip.rutgers.edu)
This file is part of GNU CC.
@@ -32,7 +32,6 @@ Boston, MA 02111-1307, USA. */
#include <sparc/sysv4.h>
#undef MD_EXEC_PREFIX
-#undef MD_STARTFILE_PREFIX
#if TARGET_CPU_DEFAULT == TARGET_CPU_v9 || TARGET_CPU_DEFAULT == TARGET_CPU_ultrasparc
/* A 64 bit v9 compiler with stack-bias,
@@ -56,6 +55,29 @@ Boston, MA 02111-1307, USA. */
#undef ASM_CPU_DEFAULT_SPEC
#define ASM_CPU_DEFAULT_SPEC "-Av9a"
+/* Provide MD_STARTFILE_PREFIX{,_1}. Need to include /usr/lib64/:/lib64/
+ if compiling for 64bit target. */
+
+#undef MD_STARTFILE_PREFIX
+#undef MD_STARTFILE_PREFIX_1
+
+#ifdef SPARC_BI_ARCH
+
+#if DEFAULT_ARCH32_P
+#define MD_STARTFILE_PREFIX "%{m64:/usr/lib64/}"
+#define MD_STARTFILE_PREFIX_1 "%{m64:/lib64/}"
+#else
+#define MD_STARTFILE_PREFIX "%{!m32:/usr/lib64/}"
+#define MD_STARTFILE_PREFIX_1 "%{!m32:/lib64/}"
+#endif
+
+#else
+
+#define MD_STARTFILE_PREFIX "/usr/lib64/"
+#define MD_STARTFILE_PREFIX_1 "/lib64/"
+
+#endif
+
/* Provide a STARTFILE_SPEC appropriate for GNU/Linux. Here we add
the GNU/Linux magical crtbegin.o file (see crtstuff.c) which
provides part of the support for getting C++ file-scope static
@@ -77,14 +99,12 @@ Boston, MA 02111-1307, USA. */
#if DEFAULT_ARCH32_P
#define STARTFILE_SPEC "\
-%{m32:" STARTFILE_SPEC32 "} \
-%{m64:" STARTFILE_SPEC64 "} \
-%{!m32:%{!m64:" STARTFILE_SPEC32 "}}"
+%{!m64:" STARTFILE_SPEC32 "} \
+%{m64:" STARTFILE_SPEC64 "}"
#else
#define STARTFILE_SPEC "\
%{m32:" STARTFILE_SPEC32 "} \
-%{m64:" STARTFILE_SPEC64 "} \
-%{!m32:%{!m64:" STARTFILE_SPEC64 "}}"
+%{!m32:" STARTFILE_SPEC64 "}"
#endif
#else
@@ -111,14 +131,12 @@ Boston, MA 02111-1307, USA. */
#if DEFAULT_ARCH32_P
#define ENDFILE_SPEC "\
-%{m32:" ENDFILE_SPEC32 "} \
-%{m64:" ENDFILE_SPEC64 "} \
-%{!m32:%{!m64:" ENDFILE_SPEC32 "}}"
+%{!m64:" ENDFILE_SPEC32 "} \
+%{m64:" ENDFILE_SPEC64 "}"
#else
#define ENDFILE_SPEC "\
%{m32:" ENDFILE_SPEC32 "} \
-%{m64:" ENDFILE_SPEC64 "} \
-%{!m32:%{!m64:" ENDFILE_SPEC64 "}}"
+%{!m32:" ENDFILE_SPEC64 "}"
#endif
#else
@@ -184,9 +202,8 @@ Boston, MA 02111-1307, USA. */
#define SUBTARGET_EXTRA_SPECS \
{ "link_arch32", LINK_ARCH32_SPEC }, \
{ "link_arch64", LINK_ARCH64_SPEC }, \
- { "link_arch_default", LINK_ARCH_DEFAULT_SPEC }, \
{ "link_arch", LINK_ARCH_SPEC },
-
+
#define LINK_ARCH32_SPEC "-m elf32_sparc -Y P,/usr/lib %{shared:-shared} \
%{!shared: \
%{!ibcs: \
@@ -205,14 +222,15 @@ Boston, MA 02111-1307, USA. */
%{static:-static}}} \
"
+#if DEFAULT_ARCH32_P
+#define LINK_ARCH_SPEC "\
+%{!m64:%(link_arch32)} \
+%{m64:%(link_arch64)}"
+#else
#define LINK_ARCH_SPEC "\
%{m32:%(link_arch32)} \
-%{m64:%(link_arch64)} \
-%{!m32:%{!m64:%(link_arch_default)}} \
-"
-
-#define LINK_ARCH_DEFAULT_SPEC \
-(DEFAULT_ARCH32_P ? LINK_ARCH32_SPEC : LINK_ARCH64_SPEC)
+%{!m32:%(link_arch64)}"
+#endif
#undef LINK_SPEC
#define LINK_SPEC "\
--- gcc/config/sparc/sol2-sld-64.h.jj Tue Jan 18 22:37:28 2000
+++ gcc/config/sparc/sol2-sld-64.h Tue Jan 25 11:01:08 2000
@@ -266,10 +266,13 @@
"
#endif
+#undef MD_STARTFILE_PREFIX
#if DEFAULT_ARCH32_P
#define MULTILIB_DEFAULTS { "m32" }
+#define MD_STARTFILE_PREFIX "%{m64:/usr/lib/sparcv9/}"
#else
#define MULTILIB_DEFAULTS { "m64" }
+#define MD_STARTFILE_PREFIX "%{!m32:/usr/lib/sparcv9/}"
#endif
#else /* !SPARC_BI_ARCH */
--- gcc/gcc.c.jj Tue Jan 18 22:32:56 2000
+++ gcc/gcc.c Tue Jan 25 11:56:01 2000
@@ -3693,6 +3693,36 @@ do_spec (spec)
return value;
}
+/* Process the spec SPEC and return the processed spec as a string
+ if successfull, NULL otherwise.
+ The SPEC should use only a limited subset of %-sequences (switch
+ presence testing) and should not use spaces, tabs, new-lines nor
+ pipe characters. */
+
+char *
+simple_spec (spec)
+ const char *spec;
+{
+ int value;
+
+ clear_args ();
+ arg_going = 0;
+ delete_this_arg = 0;
+ this_is_output_file = 0;
+ this_is_library_file = 0;
+ input_from_pipe = 0;
+
+ value = do_spec_1 (spec, 0, NULL_PTR);
+
+ if (value == 0)
+ {
+ obstack_1grow (&obstack, 0);
+ return obstack_finish (&obstack);
+ }
+
+ return NULL;
+}
+
/* Process the sub-spec SPEC as a portion of a larger spec.
This is like processing a whole spec except that we do
not initialize at the beginning and we do not supply a
@@ -5178,19 +5208,31 @@ main (argc, argv)
/* If not cross-compiling, look for startfiles in the standard places. */
if (*cross_compile == '0')
{
+ char *prefix;
+
#ifdef MD_EXEC_PREFIX
add_prefix (&exec_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
add_prefix (&startfile_prefixes, md_exec_prefix, "GCC", 0, 0, NULL_PTR);
#endif
#ifdef MD_STARTFILE_PREFIX
- add_prefix (&startfile_prefixes, md_startfile_prefix, "GCC",
- 0, 0, NULL_PTR);
+ prefix = simple_spec(md_startfile_prefix);
+ if (prefix != NULL)
+ {
+ if (*prefix != '\0')
+ add_prefix (&startfile_prefixes, prefix, "GCC",
+ 0, 0, NULL_PTR);
+ }
#endif
#ifdef MD_STARTFILE_PREFIX_1
- add_prefix (&startfile_prefixes, md_startfile_prefix_1, "GCC",
- 0, 0, NULL_PTR);
+ prefix = simple_spec(md_startfile_prefix_1);
+ if (prefix != NULL)
+ {
+ if (*prefix != '\0')
+ add_prefix (&startfile_prefixes, prefix, "GCC",
+ 0, 0, NULL_PTR);
+ }
#endif
/* If standard_startfile_prefix is relative, base it on
@@ -5214,10 +5256,9 @@ main (argc, argv)
concat (gcc_exec_prefix, machine_suffix,
standard_startfile_prefix, NULL_PTR),
NULL_PTR, 0, 0, NULL_PTR);
- add_prefix (&startfile_prefixes,
- concat (standard_exec_prefix,
- machine_suffix,
- standard_startfile_prefix, NULL_PTR),
+ prefix = concat (standard_exec_prefix, machine_suffix,
+ standard_startfile_prefix, NULL_PTR);
+ add_prefix (&startfile_prefixes, prefix,
NULL_PTR, 0, 0, NULL_PTR);
}
Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.41 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________