aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/gcc.cc')
-rw-r--r--gcc/gcc.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 38155f8..08bdf28 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -47,6 +47,9 @@ compilation is specified by a string called a "spec". */
#include "opts-jobserver.h"
#include "common/common-target.h"
+#ifndef MATH_LIBRARY
+#define MATH_LIBRARY "m"
+#endif
/* Manage the manipulation of env vars.
@@ -4117,6 +4120,48 @@ next_item:
}
}
+/* Forward certain options to offloading compilation. */
+
+static void
+forward_offload_option (size_t opt_index, const char *arg, bool validated)
+{
+ switch (opt_index)
+ {
+ case OPT_l:
+ /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the
+ host's 'MATH_LIBRARY', for example), so that the 'mkoffload's can tell
+ this has been synthesized here, and translate/drop as necessary. */
+ /* Note that certain libraries ('-lc', '-lgcc', '-lgomp', for example)
+ are injected by default in offloading compilation, and therefore not
+ forwarded here. */
+ /* GCC libraries. */
+ if (/* '-lgfortran' */ strcmp (arg, "gfortran") == 0 )
+ save_switch (concat ("-foffload-options=-l_GCC_", arg, NULL),
+ 0, NULL, validated, true);
+ /* Other libraries. */
+ else
+ {
+ /* The case will need special consideration where on the host
+ '!need_math', but for offloading compilation still need
+ '-foffload-options=-l_GCC_m'. The problem is that we don't get
+ here anything like '-lm', because it's not synthesized in
+ 'gcc/fortran/gfortranspec.cc:lang_specific_driver', for example.
+ Generally synthesizing '-foffload-options=-l_GCC_m' etc. in the
+ language specific drivers is non-trivial, needs very careful
+ review of their options handling. However, this issue is not
+ actually relevant for the current set of supported host/offloading
+ configurations. */
+ int need_math = (MATH_LIBRARY[0] != '\0');
+ if (/* '-lm' */ (need_math && strcmp (arg, MATH_LIBRARY) == 0))
+ save_switch ("-foffload-options=-l_GCC_m",
+ 0, NULL, validated, true);
+ }
+ break;
+ default:
+ gcc_unreachable ();
+ }
+}
+
/* Handle a driver option; arguments and return value as for
handle_option. */
@@ -4375,6 +4420,17 @@ driver_handle_option (struct gcc_options *opts,
/* POSIX allows separation of -l and the lib arg; canonicalize
by concatenating -l with its arg */
add_infile (concat ("-l", arg, NULL), "*");
+
+ /* Forward to offloading compilation '-l[...]' flags for standard,
+ well-known libraries. */
+ /* Doing this processing here means that we don't get to see libraries
+ injected via specs, such as '-lquadmath' injected via
+ '[build]/[target]/libgfortran/libgfortran.spec'. However, this issue
+ is not actually relevant for the current set of host/offloading
+ configurations. */
+ if (ENABLE_OFFLOADING)
+ forward_offload_option (opt_index, arg, validated);
+
do_save = false;
break;