I am building GCC (and binutils) with --with-sysroot and I build glibc in
that sysroot too.  I want to test GCC using the glibc libraries I just
built, but by default GCC uses the dynamic linker that is in /lib and that
is loading the "normal" libraries from /lib or /lib64 at runtime and not
the ones from my sysroot.  To address this I ran the GCC testsuite with:

make check 
RUNTESTFLAGS="CFLAGS_FOR_TARGET='-Wl,--dynamic-linker=/mylocation/lib/ld-linux-aarch64.so.1
 -Wl,-rpath=/mylocation/lib64'"

But when I do this, I noticed that a number of pch tests fail.  What I found
is that when I run the pch testsuite, it executes:

/home/sellcey/tot/obj/gcc/gcc/xgcc -B/home/sellcey/tot/obj/gcc/gcc/ 
./common-1.h -fno-diagnostics-show-caret -fdiagnostics-color=never -O0 -g 
-Wl,--dynamic-linker=/mylocation/lib/ld-linux-aarch64.so.1 
-Wl,-rpath=/mylocation/lib64 -o common-1.h.gch

And this causes the linker to run and try to create an executable instead of 
creating a pre-compiled header.  If I run the same command without the
-Wl flags then GCC creates the pre-compiled header that I need for testing.

I tracked this down to driver::maybe_run_linker where it sees the linker
flags and increments num_linker_inputs, this causes the routine to call
the linker.  I would like to have this function ignore linker options
and only count linker input files.  This way the linker is only called
when there is an actual file to link.

I tested this with the GCC testsuite and got no regressions, OK to checkin?


2017-11-14  Steve Ellcey  <sell...@cavium.com>

        * gcc.c (driver::maybe_run_linker): Ignore linker options
        when checking for linker inputs.


diff --git a/gcc/gcc.c b/gcc/gcc.c
index 43e6d59..61c7561 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -8289,11 +8289,14 @@ driver::maybe_run_linker (const char *argv0) const
   int linker_was_run = 0;
   int num_linker_inputs;
 
-  /* Determine if there are any linker input files.  */
+  /* Determine if there are any linker input files, but ignore
+     linker options.  If we have options but no input files we
+     do not want to call the linker.  */
   num_linker_inputs = 0;
   for (i = 0; (int) i < n_infiles; i++)
-    if (explicit_link_files[i] || outfiles[i] != NULL)
-      num_linker_inputs++;
+    if ((explicit_link_files[i] || outfiles[i] != NULL)
+        && (outfiles[i] == NULL || outfiles[i][0] != '-'))
+        num_linker_inputs++;
 
   /* Run ld to link all the compiler output files.  */
 

Reply via email to