From fe5bfa6704179f8db7d1ae0b485439e9896df8eb Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Wed, 28 Apr 2021 18:46:47 +0200 Subject: offload-defaulted: Config option to silently ignore uninstalled offload compilers If configured with --enable-offload-defaulted, configured but not installed offload compilers and libgomp plugins are silently ignored. Useful for distribution compilers where those are in separate optional packages. 2021-04-28 Jakub Jelinek Tobias Burnus ChangeLog: * configure.ac (--enable-offload-defaulted): New. * configure: Regenerate. gcc/ChangeLog: * configure.ac (OFFLOAD_DEFAULTED): AC_DEFINE if offload-defaulted. * gcc.c (process_command): New variable. (driver::maybe_putenv_OFFLOAD_TARGETS): If OFFLOAD_DEFAULTED, set it if -foffload is defaulted. * lto-wrapper.c (OFFLOAD_TARGET_DEFAULT_ENV): Define. (compile_offload_image): If OFFLOAD_DEFAULTED and OFFLOAD_TARGET_DEFAULT is in the environment, don't fail if corresponding mkoffload can't be found. (compile_images_for_offload_targets): Likewise. Free and clear offload_names if no valid offload is found. * config.in: Regenerate. * configure: Regenerate. libgomp/ChangeLog: * configure.ac (OFFLOAD_DEFAULTED): AC_DEFINE if offload-defaulted. * target.c (gomp_load_plugin_for_device): If set and if a plugin can't be dlopened, silently assume it has no devices. * Makefile.in: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. --- gcc/gcc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index 7837553..bd561ac 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -319,6 +319,12 @@ static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE; static char *offload_targets = NULL; +#if OFFLOAD_DEFAULTED +/* Set to true if -foffload has not been used and offload_targets + is set to the configured in default. */ +static bool offload_targets_default; +#endif + /* Nonzero if cross-compiling. When -b is used, the value comes from the `specs' file. */ @@ -4828,7 +4834,12 @@ process_command (unsigned int decoded_options_count, /* If the user didn't specify any, default to all configured offload targets. */ if (ENABLE_OFFLOADING && offload_targets == NULL) - handle_foffload_option (OFFLOAD_TARGETS); + { + handle_foffload_option (OFFLOAD_TARGETS); +#if OFFLOAD_DEFAULTED + offload_targets_default = true; +#endif + } if (output_file && strcmp (output_file, "-") != 0 @@ -8484,6 +8495,10 @@ driver::maybe_putenv_OFFLOAD_TARGETS () const obstack_grow (&collect_obstack, offload_targets, strlen (offload_targets) + 1); xputenv (XOBFINISH (&collect_obstack, char *)); +#if OFFLOAD_DEFAULTED + if (offload_targets_default) + xputenv ("OFFLOAD_TARGET_DEFAULT=1"); +#endif } free (offload_targets); -- cgit v1.1 From 6ba3079dce89d9b63bf5dbd5e320ea2bf96f196b Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 17 Mar 2021 16:36:44 +0100 Subject: Come up with startswith function. gcc/ada/ChangeLog: * gcc-interface/utils.c (def_builtin_1): Use startswith function instead of strncmp. gcc/analyzer/ChangeLog: * sm-file.cc (is_file_using_fn_p): Use startswith function instead of strncmp. gcc/ChangeLog: * builtins.c (is_builtin_name): Use startswith function instead of strncmp. * collect2.c (main): Likewise. (has_lto_section): Likewise. (scan_libraries): Likewise. * coverage.c (coverage_checksum_string): Likewise. (coverage_init): Likewise. * dwarf2out.c (is_cxx): Likewise. (gen_compile_unit_die): Likewise. * gcc-ar.c (main): Likewise. * gcc.c (init_spec): Likewise. (read_specs): Likewise. (execute): Likewise. (check_live_switch): Likewise. * genattrtab.c (write_attr_case): Likewise. (IS_ATTR_GROUP): Likewise. * gencfn-macros.c (main): Likewise. * gengtype.c (type_for_name): Likewise. (gen_rtx_next): Likewise. (get_file_langdir): Likewise. (write_local): Likewise. * genmatch.c (get_operator): Likewise. (get_operand_type): Likewise. (expr::gen_transform): Likewise. * genoutput.c (validate_optab_operands): Likewise. * incpath.c (add_sysroot_to_chain): Likewise. * langhooks.c (lang_GNU_C): Likewise. (lang_GNU_CXX): Likewise. (lang_GNU_Fortran): Likewise. (lang_GNU_OBJC): Likewise. * lto-wrapper.c (run_gcc): Likewise. * omp-general.c (omp_max_simt_vf): Likewise. * omp-low.c (omp_runtime_api_call): Likewise. * opts-common.c (parse_options_from_collect_gcc_options): Likewise. * read-rtl-function.c (function_reader::read_rtx_operand_r): Likewise. * real.c (real_from_string): Likewise. * selftest.c (assert_str_startswith): Likewise. * timevar.c (timer::validate_phases): Likewise. * tree.c (get_file_function_name): Likewise. * ubsan.c (ubsan_use_new_style_p): Likewise. * varasm.c (default_function_rodata_section): Likewise. (incorporeal_function_p): Likewise. (default_section_type_flags): Likewise. * system.h (startswith): Define startswith. gcc/c-family/ChangeLog: * c-ada-spec.c (print_destructor): Use startswith function instead of strncmp. (dump_ada_declaration): Likewise. * c-common.c (disable_builtin_function): Likewise. (def_builtin_1): Likewise. * c-format.c (check_tokens): Likewise. (check_plain): Likewise. (convert_format_name_to_system_name): Likewise. gcc/c/ChangeLog: * c-aux-info.c (affix_data_type): Use startswith function instead of strncmp. * c-typeck.c (build_function_call_vec): Likewise. * gimple-parser.c (c_parser_gimple_parse_bb_spec): Likewise. gcc/cp/ChangeLog: * decl.c (duplicate_decls): Use startswith function instead of strncmp. (cxx_builtin_function): Likewise. (omp_declare_variant_finalize_one): Likewise. (grokfndecl): Likewise. * error.c (dump_decl_name): Likewise. * mangle.c (find_decomp_unqualified_name): Likewise. (write_guarded_var_name): Likewise. (decl_tls_wrapper_p): Likewise. * parser.c (cp_parser_simple_type_specifier): Likewise. (cp_parser_tx_qualifier_opt): Likewise. * pt.c (template_parm_object_p): Likewise. (dguide_name_p): Likewise. gcc/d/ChangeLog: * d-builtins.cc (do_build_builtin_fn): Use startswith function instead of strncmp. * dmd/dinterpret.c (evaluateIfBuiltin): Likewise. * dmd/dmangle.c: Likewise. * dmd/hdrgen.c: Likewise. * dmd/identifier.c (Identifier::toHChars2): Likewise. gcc/fortran/ChangeLog: * decl.c (variable_decl): Use startswith function instead of strncmp. (gfc_match_end): Likewise. * gfortran.h (gfc_str_startswith): Likewise. * module.c (load_omp_udrs): Likewise. (read_module): Likewise. * options.c (gfc_handle_runtime_check_option): Likewise. * primary.c (match_arg_list_function): Likewise. * trans-decl.c (gfc_get_symbol_decl): Likewise. * trans-expr.c (gfc_conv_procedure_call): Likewise. * trans-intrinsic.c (gfc_conv_ieee_arithmetic_function): Likewise. gcc/go/ChangeLog: * gofrontend/runtime.cc (Runtime::name_to_code): Use startswith function instead of strncmp. gcc/objc/ChangeLog: * objc-act.c (objc_string_ref_type_p): Use startswith function instead of strncmp. * objc-encoding.c (encode_type): Likewise. * objc-next-runtime-abi-02.c (has_load_impl): Likewise. --- gcc/gcc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index bd561ac..4c1a659 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -1906,7 +1906,7 @@ init_spec (void) when given the proper command line arguments. */ while (*p) { - if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0) + if (in_sep && *p == '-' && startswith (p, "-lgcc")) { init_gcc_specs (&obstack, "-lgcc_s" @@ -1929,7 +1929,7 @@ init_spec (void) p += 5; in_sep = 0; } - else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0) + else if (in_sep && *p == 'l' && startswith (p, "libgcc.a%s")) { /* Ug. We don't know shared library extensions. Hope that systems that use this form don't do shared libraries. */ @@ -2384,7 +2384,7 @@ read_specs (const char *filename, bool main_p, bool user_p) /* Skip '\n'. */ p++; - if (!strncmp (p1, "%include", sizeof ("%include") - 1) + if (startswith (p1, "%include") && (p1[sizeof "%include" - 1] == ' ' || p1[sizeof "%include" - 1] == '\t')) { @@ -2405,7 +2405,7 @@ read_specs (const char *filename, bool main_p, bool user_p) read_specs (new_filename ? new_filename : p1, false, user_p); continue; } - else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1) + else if (startswith (p1, "%include_noerr") && (p1[sizeof "%include_noerr" - 1] == ' ' || p1[sizeof "%include_noerr" - 1] == '\t')) { @@ -2429,7 +2429,7 @@ read_specs (const char *filename, bool main_p, bool user_p) fnotice (stderr, "could not find specs file %s\n", p1); continue; } - else if (!strncmp (p1, "%rename", sizeof "%rename" - 1) + else if (startswith (p1, "%rename") && (p1[sizeof "%rename" - 1] == ' ' || p1[sizeof "%rename" - 1] == '\t')) { @@ -3502,7 +3502,7 @@ execute (void) && WEXITSTATUS (status) == ICE_EXIT_CODE && i == 0 && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR)) - && ! strncmp (p + 1, "cc1", 3)) + && startswith (p + 1, "cc1")) try_generate_repro (commands[0].argv); if (WEXITSTATUS (status) > greatest_status) greatest_status = WEXITSTATUS (status); @@ -7335,7 +7335,7 @@ check_live_switch (int switchnum, int prefix_length) break; case 'W': case 'f': case 'm': case 'g': - if (! strncmp (name + 1, "no-", 3)) + if (startswith (name + 1, "no-")) { /* We have Xno-YYY, search for XYYY. */ for (i = switchnum + 1; i < n_switches; i++) -- cgit v1.1 From 3f207ab314c071c6060c7c9a429fcf29fd87b594 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Fri, 11 Jun 2021 23:49:22 -0400 Subject: use range based for loops to iterate over vec<> This changes users of FOR_EACH_VEC_ELT to use range based for loops, where the index variables are otherwise unused. As such the index variables are all deleted, producing shorter and simpler code. Signed-off-by: Trevor Saunders gcc/analyzer/ChangeLog: * call-string.cc (call_string::call_string): Use range based for to iterate over vec<>. (call_string::to_json): Likewise. (call_string::hash): Likewise. (call_string::calc_recursion_depth): Likewise. * checker-path.cc (checker_path::fixup_locations): Likewise. * constraint-manager.cc (equiv_class::equiv_class): Likewise. (equiv_class::to_json): Likewise. (equiv_class::hash): Likewise. (constraint_manager::to_json): Likewise. * engine.cc (impl_region_model_context::on_svalue_leak): Likewise. (on_liveness_change): Likewise. (impl_region_model_context::on_unknown_change): Likewise. * program-state.cc (sm_state_map::set_state): Likewise. * region-model.cc (test_canonicalization_4): Likewise. gcc/ChangeLog: * attribs.c (find_attribute_namespace): Iterate over vec<> with range based for. * auto-profile.c (afdo_find_equiv_class): Likewise. * gcc.c (do_specs_vec): Likewise. (do_spec_1): Likewise. (driver::set_up_specs): Likewise. * gimple-loop-jam.c (any_access_function_variant_p): Likewise. * gimple-ssa-store-merging.c (compatible_load_p): Likewise. (imm_store_chain_info::try_coalesce_bswap): Likewise. (imm_store_chain_info::coalesce_immediate_stores): Likewise. (get_location_for_stmts): Likewise. * graphite-poly.c (print_iteration_domains): Likewise. (free_poly_bb): Likewise. (remove_gbbs_in_scop): Likewise. (free_scop): Likewise. (dump_gbb_cases): Likewise. (dump_gbb_conditions): Likewise. (print_pdrs): Likewise. (print_scop): Likewise. * ifcvt.c (cond_move_process_if_block): Likewise. * lower-subreg.c (decompose_multiword_subregs): Likewise. * regcprop.c (pass_cprop_hardreg::execute): Likewise. * sanopt.c (sanitize_rewrite_addressable_params): Likewise. * sel-sched-dump.c (dump_insn_vector): Likewise. * store-motion.c (store_ops_ok): Likewise. (store_killed_in_insn): Likewise. * timevar.c (timer::named_items::print): Likewise. * tree-cfgcleanup.c (cleanup_control_flow_pre): Likewise. (cleanup_tree_cfg_noloop): Likewise. * tree-data-ref.c (dump_data_references): Likewise. (print_dir_vectors): Likewise. (print_dist_vectors): Likewise. (dump_data_dependence_relations): Likewise. (dump_dist_dir_vectors): Likewise. (dump_ddrs): Likewise. (create_runtime_alias_checks): Likewise. (free_subscripts): Likewise. (save_dist_v): Likewise. (save_dir_v): Likewise. (invariant_access_functions): Likewise. (same_access_functions): Likewise. (access_functions_are_affine_or_constant_p): Likewise. (find_data_references_in_stmt): Likewise. (graphite_find_data_references_in_stmt): Likewise. (free_dependence_relations): Likewise. (free_data_refs): Likewise. * tree-inline.c (copy_debug_stmts): Likewise. * tree-into-ssa.c (dump_currdefs): Likewise. (rewrite_update_phi_arguments): Likewise. * tree-ssa-propagate.c (clean_up_loop_closed_phi): Likewise. * tree-vect-data-refs.c (vect_analyze_possibly_independent_ddr): Likewise. (vect_slp_analyze_node_dependences): Likewise. (vect_slp_analyze_instance_dependence): Likewise. (vect_record_base_alignments): Likewise. (vect_get_peeling_costs_all_drs): Likewise. (vect_peeling_supportable): Likewise. * tree-vectorizer.c (vec_info::~vec_info): Likewise. (vec_info::free_stmt_vec_infos): Likewise. gcc/cp/ChangeLog: * constexpr.c (cxx_eval_call_expression): Iterate over vec<> with range based for. (cxx_eval_store_expression): Likewise. (cxx_eval_loop_expr): Likewise. * decl.c (wrapup_namespace_globals): Likewise. (cp_finish_decl): Likewise. (cxx_simulate_enum_decl): Likewise. * parser.c (cp_parser_postfix_expression): Likewise. --- gcc/gcc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index 4c1a659..af28640 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -5838,10 +5838,7 @@ compile_input_file_p (struct infile *infile) static void do_specs_vec (vec vec) { - unsigned ix; - char *opt; - - FOR_EACH_VEC_ELT (vec, ix, opt) + for (char *opt : vec) { do_spec_1 (opt, 1, NULL); /* Make each accumulated option a separate argument. */ @@ -6436,8 +6433,6 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) { const char *p1 = p; char *string; - char *opt; - unsigned ix; /* Skip past the option value and make a copy. */ if (*p != '{') @@ -6448,7 +6443,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) string = save_string (p1 + 1, p - p1 - 2); /* See if we already recorded this option. */ - FOR_EACH_VEC_ELT (linker_options, ix, opt) + for (const char *opt : linker_options) if (! strcmp (string, opt)) { free (string); @@ -8316,9 +8311,7 @@ driver::set_up_specs () const && do_spec_2 (startfile_prefix_spec, NULL) == 0 && do_spec_1 (" ", 0, NULL) == 0) { - const char *arg; - int ndx; - FOR_EACH_VEC_ELT (argbuf, ndx, arg) + for (const char *arg : argbuf) add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1); } -- cgit v1.1 From 33c4e466243f2d0459d9a4d0cadc1b38a3741f3e Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Tue, 29 Jun 2021 15:58:21 +0200 Subject: Add 'default' to -foffload=; document that flag [PR67300] As -foffload={options,targets,targets=options} is very convoluted, it has been split into -foffload=targets (supporting the old syntax for backward compatibilty) and -foffload-options={options,target=options}. Only the new syntax is documented. Additionally, -foffload=default is supported, which can reset the devices after -foffload=disable / -foffload=targets to the default, if needed. gcc/ChangeLog: PR other/67300 * common.opt (-foffload=): Update description. (-foffload-options=): New. * doc/invoke.texi (C Language Options): Document -foffload and -foffload-options. * gcc.c (check_offload_target_name): New, split off from handle_foffload_option. (check_foffload_target_names): New. (handle_foffload_option): Handle -foffload=default. (driver_handle_option): Update for -foffload-options. * lto-opts.c (lto_write_options): Use -foffload-options instead of -foffload. * lto-wrapper.c (merge_and_complain, append_offload_options): Likewise. * opts.c (common_handle_option): Likewise. libgomp/ChangeLog: PR other/67300 * testsuite/libgomp.c-c++-common/reduction-16.c: Replace -foffload=nvptx-none= by -foffload-options=nvptx-none= to avoid disabling other offload targets. * testsuite/libgomp.c-c++-common/reduction-5.c: Likewise. * testsuite/libgomp.c-c++-common/reduction-6.c: Likewise. * testsuite/libgomp.c/target-44.c: Likewise. --- gcc/gcc.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 99 insertions(+), 22 deletions(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index af28640..df9b219 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -3977,6 +3977,84 @@ driver_wrong_lang_callback (const struct cl_decoded_option *decoded, static const char *spec_lang = 0; static int last_language_n_infiles; + +/* Check that GCC is configured to support the offload target. */ + +static bool +check_offload_target_name (const char *target, ptrdiff_t len) +{ + const char *n, *c = OFFLOAD_TARGETS; + while (c) + { + n = strchr (c, ','); + if (n == NULL) + n = strchr (c, '\0'); + if (len == n - c && strncmp (target, c, n - c) == 0) + break; + c = *n ? n + 1 : NULL; + } + if (!c) + { + char *s; + auto_vec candidates; + char *cand = (char *) alloca (strlen (OFFLOAD_TARGETS) + 1); + c = OFFLOAD_TARGETS; + while (c) + { + n = strchr (c, ','); + if (n == NULL) + n = strchr (c, '\0'); + strncpy (cand, c, n - c); + cand[n - c] = '\0'; + candidates.safe_push (cand); + c = *n ? n + 1 : NULL; + } + error ("GCC is not configured to support %q.*s as offload target", + len, target); + const char *hint = candidates_list_and_hint (target, s, candidates); + if (hint) + inform (UNKNOWN_LOCATION, + "valid offload targets are: %s; did you mean %qs?", s, hint); + else + inform (UNKNOWN_LOCATION, "valid offload targets are: %s", s); + XDELETEVEC (s); + return false; + } + return true; +} + +/* Sanity check for -foffload-options. */ + +static void +check_foffload_target_names (const char *arg) +{ + const char *cur, *next, *end; + /* If option argument starts with '-' then no target is specified and we + do not need to parse it. */ + if (arg[0] == '-') + return; + end = strchr (arg, '='); + if (end == NULL) + { + error ("%<=%>options missing after %<-foffload-options=%>target"); + return; + } + + cur = arg; + while (cur < end) + { + next = strchr (cur, ','); + if (next == NULL) + next = end; + next = (next > end) ? end : next; + + /* Retain non-supported targets after printing an error as those will not + be processed; each enabled target only processes its triplet. */ + check_offload_target_name (cur, next - cur); + cur = next + 1; + } +} + /* Parse -foffload option argument. */ static void @@ -4006,34 +4084,25 @@ handle_foffload_option (const char *arg) memcpy (target, cur, next - cur); target[next - cur] = '\0'; - /* If 'disable' is passed to the option, stop parsing the option and clean - the list of offload targets. */ - if (strcmp (target, "disable") == 0) + /* Reset offloading list and continue. */ + if (strcmp (target, "default") == 0) { free (offload_targets); - offload_targets = xstrdup (""); - break; + offload_targets = NULL; + goto next_item; } - /* Check that GCC is configured to support the offload target. */ - c = OFFLOAD_TARGETS; - while (c) + /* If 'disable' is passed to the option, clean the list of + offload targets and return, even if more targets follow. + Likewise if GCC is not configured to support that offload target. */ + if (strcmp (target, "disable") == 0 + || !check_offload_target_name (target, next - cur)) { - n = strchr (c, ','); - if (n == NULL) - n = strchr (c, '\0'); - - if (next - cur == n - c && strncmp (target, c, n - c) == 0) - break; - - c = *n ? n + 1 : NULL; + free (offload_targets); + offload_targets = xstrdup (""); + return; } - if (!c) - fatal_error (input_location, - "GCC is not configured to support %s as offload target", - target); - if (!offload_targets) { offload_targets = target; @@ -4067,7 +4136,7 @@ handle_foffload_option (const char *arg) memcpy (offload_targets + offload_targets_len, target, next - cur + 1); } } - +next_item: cur = next + 1; XDELETEVEC (target); } @@ -4499,8 +4568,16 @@ driver_handle_option (struct gcc_options *opts, flag_wpa = ""; break; + case OPT_foffload_options_: + check_foffload_target_names (arg); + break; + case OPT_foffload_: handle_foffload_option (arg); + if (arg[0] == '-' || NULL != strchr (arg, '=')) + save_switch (concat ("-foffload-options=", arg, NULL), + 0, NULL, validated, true); + do_save = false; break; default: -- cgit v1.1 From af9987e817f54806a18e45c5615b9a95b690e537 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Tue, 29 Jun 2021 16:35:42 +0200 Subject: gcc.c: Silence warning in check_offload_target_name gcc/ChangeLog: * gcc.c (check_offload_target_name): Cast len argument to %q.*s to 'int'; avoid -Wstringop-truncation warning. --- gcc/gcc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index df9b219..9baa7d6 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -4004,13 +4004,15 @@ check_offload_target_name (const char *target, ptrdiff_t len) n = strchr (c, ','); if (n == NULL) n = strchr (c, '\0'); + if (n - c == 0) + break; strncpy (cand, c, n - c); cand[n - c] = '\0'; candidates.safe_push (cand); c = *n ? n + 1 : NULL; } error ("GCC is not configured to support %q.*s as offload target", - len, target); + (int) len, target); const char *hint = candidates_list_and_hint (target, s, candidates); if (hint) inform (UNKNOWN_LOCATION, -- cgit v1.1 From a3ce7d75dd9c0308b8565669f31127436cb2ba9f Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Wed, 30 Jun 2021 13:17:54 +0200 Subject: gcc.c's check_offload_target_name: Fixes to inform hints gcc/ChangeLog: * gcc.c (close_at_file, execute): Replace alloca by XALLOCAVEC. (check_offload_target_name): Fix splitting OFFLOAD_TARGETS into a candidate list; better inform no offload target is configured and fix hint extraction when passed target is not '\0' at [len]. * common.opt (foffload): Add tailing '.'. (foffload-options): Likewise; fix flag name in the help string. --- gcc/gcc.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index 9baa7d6..f802148 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -2242,7 +2242,7 @@ close_at_file (void) if (n_args == 0) return; - char **argv = (char **) alloca (sizeof (char *) * (n_args + 1)); + char **argv = XALLOCAVEC (char *, n_args + 1); char *temp_file = make_at_file (); char *at_argument = concat ("@", temp_file, NULL); FILE *f = fopen (temp_file, "w"); @@ -3251,7 +3251,7 @@ execute (void) n_commands++; /* Get storage for each command. */ - commands = (struct command *) alloca (n_commands * sizeof (struct command)); + commands = XALLOCAVEC (struct command, n_commands); /* Split argbuf into its separate piped processes, and record info about each one. @@ -3430,13 +3430,13 @@ execute (void) struct pex_time *times = NULL; int ret_code = 0; - statuses = (int *) alloca (n_commands * sizeof (int)); + statuses = XALLOCAVEC (int, n_commands); if (!pex_get_status (pex, n_commands, statuses)) fatal_error (input_location, "failed to get exit status: %m"); if (report_times || report_times_to_file) { - times = (struct pex_time *) alloca (n_commands * sizeof (struct pex_time)); + times = XALLOCAVEC (struct pex_time, n_commands); if (!pex_get_times (pex, n_commands, times)) fatal_error (input_location, "failed to get process times: %m"); } @@ -3997,24 +3997,22 @@ check_offload_target_name (const char *target, ptrdiff_t len) { char *s; auto_vec candidates; - char *cand = (char *) alloca (strlen (OFFLOAD_TARGETS) + 1); - c = OFFLOAD_TARGETS; - while (c) - { - n = strchr (c, ','); - if (n == NULL) - n = strchr (c, '\0'); - if (n - c == 0) - break; - strncpy (cand, c, n - c); - cand[n - c] = '\0'; - candidates.safe_push (cand); - c = *n ? n + 1 : NULL; - } - error ("GCC is not configured to support %q.*s as offload target", - (int) len, target); - const char *hint = candidates_list_and_hint (target, s, candidates); - if (hint) + size_t olen = strlen (OFFLOAD_TARGETS) + 1; + char *cand = XALLOCAVEC (char, olen); + memcpy (cand, OFFLOAD_TARGETS, olen); + for (c = strtok (cand, ","); c; c = strtok (NULL, ",")) + candidates.safe_push (c); + + char *target2 = XALLOCAVEC (char, len + 1); + memcpy (target2, target, len); + target2[len] = '\0'; + + error ("GCC is not configured to support %qs as offload target", target2); + + const char *hint = candidates_list_and_hint (target2, s, candidates); + if (candidates.is_empty ()) + inform (UNKNOWN_LOCATION, "no offloading targets configured"); + else if (hint) inform (UNKNOWN_LOCATION, "valid offload targets are: %s; did you mean %qs?", s, hint); else -- cgit v1.1 From 63fe82d80dee997b25ca60fa7d1ed07e97930976 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Wed, 30 Jun 2021 14:49:48 +0200 Subject: gcc.c: Add -foffload= to display_help gcc/ChangeLog: * common.opt (foffload): Remove help as Driver only. * gcc.c (display_help): Add -foffload. --- gcc/gcc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index f802148..c8dbff6 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -3752,6 +3752,7 @@ display_help (void) fputs (_(" -dumpspecs Display all of the built in spec strings.\n"), stdout); fputs (_(" -dumpversion Display the version of the compiler.\n"), stdout); fputs (_(" -dumpmachine Display the compiler's target processor.\n"), stdout); + fputs (_(" -foffload= Specify offloading targets.\n"), stdout); fputs (_(" -print-search-dirs Display the directories in the compiler's search path.\n"), stdout); fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library.\n"), stdout); fputs (_(" -print-file-name= Display the full path to library .\n"), stdout); -- cgit v1.1 From 3b5e8ee4f1ecc6d407f391695f65960bcbd63cff Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Sun, 13 Dec 2020 17:21:16 +0000 Subject: Darwin, configury : Allow for specification and detection of dsymutil. In order to enable DWARF versions > 2 we need a sufficiently modern version of dsymutil (in addition to the assembler / linker). This allows the user to configure a different path from the installed one. In addition, there are several sources of dsymutil so we differentiate these in order to be get accurate version information. Signed-off-by: Iain Sandoe gcc/ChangeLog: * configure.ac: Handle --with-dsymutil in the same way as we do for the assembler and linker. (DEFAULT_DSYMUTIL): New. Extract the type and version for the dsymutil configured or found by the default searches. * config.in: Regenerated. * configure: Regenerated. * collect2.c (do_dsymutil): Handle locating dsymutil in the same way as for the assembler and linker. * config/darwin.h (DSYMUTIL): Delete. * gcc.c: Report a configured dsymutil correctly. * exec-tool.in: Allow for dsymutil. ChangeLog: * Makefile.def: Add dsymutil defs. * Makefile.in: Regenerated. * Makefile.tpl: Add dsymutil to flags. * configure: Regenerated. * configure.ac: Add dsymutil to target and build recipes. --- gcc/gcc.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index c8dbff6..36a88fc 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -3062,6 +3062,11 @@ find_a_file (const struct path_prefix *pprefix, const char *name, int mode, return xstrdup (DEFAULT_LINKER); #endif +#ifdef DEFAULT_DSYMUTIL + if (! strcmp (name, "dsymutil") && access (DEFAULT_DSYMUTIL, mode) == 0) + return xstrdup (DEFAULT_DSYMUTIL); +#endif + /* Determine the filename to execute (special case for absolute paths). */ if (IS_ABSOLUTE_PATH (name)) -- cgit v1.1 From e37e175e7dc3376244eb7705269ada6755616831 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 9 Jul 2021 12:08:52 +0200 Subject: Fix build failure on Windows with older binutils This is the build failure on Windows with binutils for which GNU as accepts the --gdwarf-5 switch but GNU ld generates broken binaries with DWARF 5. We already have the HAVE_LD_BROKEN_PE_DWARF5 kludge to disable DWARF 5 in this case but it only tames the DWARF version in the compiler, so the driver still passes --gdwarf-5 when invoked on an assembly file with -g. gcc/ PR target/101377 * gcc.c (ASM_DEBUG_DWARF_OPTION): Set again to --gdwarf2 in the case where HAVE_AS_WORKING_DWARF_N_FLAG is not defined and HAVE_LD_BROKEN_PE_DWARF5 is defined. --- gcc/gcc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index 36a88fc..f086dd4 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -916,7 +916,7 @@ proper position among the other output files. */ than in ASM_DEBUG_SPEC, so that it applies to both .s and .c etc. compilations. */ # define ASM_DEBUG_DWARF_OPTION "" -# elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) +# elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && !defined(HAVE_LD_BROKEN_PE_DWARF5) # define ASM_DEBUG_DWARF_OPTION "%{%:dwarf-version-gt(4):--gdwarf-5;" \ "%:dwarf-version-gt(3):--gdwarf-4;" \ "%:dwarf-version-gt(2):--gdwarf-3;" \ -- cgit v1.1 From 9b8b37d1b6301855213b8d4860feaeb74d464c6b Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 12 Jul 2021 10:59:06 +0200 Subject: offloading: fix -foffload hinting PR sanitizer/101425 gcc/ChangeLog: * gcc.c (check_offload_target_name): Call candidates_list_and_hint only if we have a candidate. --- gcc/gcc.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index f086dd4..12b3440 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -4001,7 +4001,6 @@ check_offload_target_name (const char *target, ptrdiff_t len) } if (!c) { - char *s; auto_vec candidates; size_t olen = strlen (OFFLOAD_TARGETS) + 1; char *cand = XALLOCAVEC (char, olen); @@ -4015,15 +4014,19 @@ check_offload_target_name (const char *target, ptrdiff_t len) error ("GCC is not configured to support %qs as offload target", target2); - const char *hint = candidates_list_and_hint (target2, s, candidates); if (candidates.is_empty ()) inform (UNKNOWN_LOCATION, "no offloading targets configured"); - else if (hint) - inform (UNKNOWN_LOCATION, - "valid offload targets are: %s; did you mean %qs?", s, hint); else - inform (UNKNOWN_LOCATION, "valid offload targets are: %s", s); - XDELETEVEC (s); + { + char *s; + const char *hint = candidates_list_and_hint (target2, s, candidates); + if (hint) + inform (UNKNOWN_LOCATION, + "valid offload targets are: %s; did you mean %qs?", s, hint); + else + inform (UNKNOWN_LOCATION, "valid offload targets are: %s", s); + XDELETEVEC (s); + } return false; } return true; -- cgit v1.1 From 4f3b383cf8825197e714a4a21852eca071f8e67e Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 9 Jul 2021 11:13:11 +0200 Subject: driver/101383 - handle -gtoggle in driver The driver amends assembler options with for example --gdwarf-5 when debugging is enabled but the check for that does not consider the effect of -gtoggle which is not handled in the common option machinery. The following alters debug_info_level according to -gtoggle mimicing what process_options later does in the compiler. This in particular avoids changing of the cc1-checksum with every bootstrap (debug) cycle as we compute that from stage2 where we use -g -gtoggle but with --gdwarf-5 and no debug info from the compiler the assembler will fill the line table with the temporary assembler file names. 2021-07-09 Richard Biener PR driver/101383 * gcc.c (process_command): Process -gtoggle like process_options would after parsing options. --- gcc/gcc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gcc/gcc.c') diff --git a/gcc/gcc.c b/gcc/gcc.c index 12b3440..3e98bc7 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -4927,6 +4927,16 @@ process_command (unsigned int decoded_options_count, #endif } + /* Handle -gtoggle as it would later in toplev.c:process_options to + make the debug-level-gt spec function work as expected. */ + if (flag_gtoggle) + { + if (debug_info_level == DINFO_LEVEL_NONE) + debug_info_level = DINFO_LEVEL_NORMAL; + else + debug_info_level = DINFO_LEVEL_NONE; + } + if (output_file && strcmp (output_file, "-") != 0 && strcmp (output_file, HOST_BIT_BUCKET) != 0) -- cgit v1.1