diff options
Diffstat (limited to 'gcc/cobol/gcobolspec.cc')
-rw-r--r-- | gcc/cobol/gcobolspec.cc | 206 |
1 files changed, 35 insertions, 171 deletions
diff --git a/gcc/cobol/gcobolspec.cc b/gcc/cobol/gcobolspec.cc index 5bd6853..70784d7 100644 --- a/gcc/cobol/gcobolspec.cc +++ b/gcc/cobol/gcobolspec.cc @@ -57,10 +57,6 @@ along with GCC; see the file COPYING3. If not see int lang_specific_extra_outfiles = 0; -#ifndef MATH_LIBRARY -#define MATH_LIBRARY "m" -#endif - #ifndef DL_LIBRARY #define DL_LIBRARY "dl" #endif @@ -73,16 +69,20 @@ int lang_specific_extra_outfiles = 0; #define COBOL_LIBRARY "gcobol" #endif +#define SPEC_FILE "libgcobol.spec" + /* The original argument list and related info is copied here. */ static const struct cl_decoded_option *original_options; /* The new argument list will be built here. */ static std::vector<cl_decoded_option>new_opt; +static bool need_libgcobol = true; + // #define NOISY 1 static void -append_arg(const struct cl_decoded_option arg) +append_arg(const cl_decoded_option& arg) { #ifdef NOISY static int counter = 1; @@ -116,8 +116,8 @@ add_arg_lib(const char *library, bool force_static ATTRIBUTE_UNUSED) { append_option (OPT_Wl_, LD_STATIC_OPTION, 1); } - append_option (OPT_l, library, 1); #endif + append_option (OPT_l, library, 1); #ifdef HAVE_LD_STATIC_DYNAMIC if( force_static ) { @@ -126,56 +126,6 @@ add_arg_lib(const char *library, bool force_static ATTRIBUTE_UNUSED) #endif } -static void -append_rdynamic() - { - // This is a bit ham-handed, but I was in a hurry. - struct cl_decoded_option decoded = {}; - decoded.opt_index = OPT_rdynamic; - decoded.orig_option_with_args_text = "-rdynamic"; - decoded.canonical_option[0] = "-rdynamic"; - decoded.canonical_option_num_elements = 1; - decoded.value = 1; - append_arg(decoded); - return; - } - -static void -append_rpath() - { -#ifdef EXEC_LIB - // Handing append_option() something on the stack Just Doesn't Work - if( strlen(EXEC_LIB) ) - { - static char ach[256]; - snprintf(ach, sizeof(ach), "-rpath=%s", EXEC_LIB); - append_option (OPT_Wl_, ach, 1); - } -#endif - return; - } - -static void -append_allow_multiple_definition() - { - append_option (OPT_Wl_, "--allow-multiple-definition", 1); - return; - } - -static void -append_fpic() - { - // This is a bit ham-handed, but I was in a hurry. - struct cl_decoded_option decoded = {}; - decoded.opt_index = OPT_rdynamic; - decoded.orig_option_with_args_text = "-fPIC"; - decoded.canonical_option[0] = "-fPIC"; - decoded.canonical_option_num_elements = 1; - decoded.value = 1; - append_arg(decoded); - return; - } - void lang_specific_driver (struct cl_decoded_option **in_decoded_options, unsigned int *in_decoded_options_count, @@ -203,20 +153,13 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, bool saw_OPT_c = false; bool saw_OPT_shared = false; - bool saw_OPT_pic = false; - bool saw_OPT_PIC = false; bool verbose = false; // These flags indicate whether we need various libraries - bool need_libgcobol = true; - bool need_libmath = (MATH_LIBRARY[0] != '\0'); bool need_libdl = (DL_LIBRARY[0] != '\0'); bool need_libstdc = (STDCPP_LIBRARY[0] != '\0'); - // bool need_libquadmath = (QUADMATH_LIBRARY[0] != '\0'); - bool need_rdynamic = true; - bool need_allow_multiple_definition = true; // Separate flags for a couple of static libraries bool static_libgcobol = false; @@ -250,9 +193,6 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, int index_libgcobol_a = 0; - // This is for the -Wl,-rpath=<EXEC_LIB> - bool need_rpath = true; - bool no_files_error = true; #ifdef NOISY @@ -310,47 +250,10 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, saw_OPT_shared = true; break; - case OPT_fpic: - saw_OPT_pic = true; - break; - - case OPT_fPIC: - saw_OPT_PIC = true; - break; - - case OPT_c: - // With this option, no libraries need be loaded + case OPT_c: + // Note -c specially. saw_OPT_c = true; - need_libgcobol = false; - need_libmath = false; - need_libdl = false; - need_libstdc = false; - // need_libquadmath = false; - need_rdynamic = false; - break; - - case OPT_rdynamic: - need_rdynamic = false; - break; - - case OPT_Wl_: - if( strstr(decoded_options[i].orig_option_with_args_text, - "--allow-multiple-definitions") ) - { - need_allow_multiple_definition = false; - } - if( strstr(decoded_options[i].orig_option_with_args_text, "-rpath") ) - { - // The caller is doing something with -rpath. Assume they know what - // they are doing - - // On second thought, always install our rpath. It goes at the end, - // so if the user specifies and rpath that they prefer, it'll get - // taken first. - need_rpath = true; - } - break; - + // FALLTHROUGH case OPT_nostdlib: case OPT_nodefaultlibs: case OPT_r: @@ -359,27 +262,18 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, case OPT_E: // With these options, no libraries need be loaded need_libgcobol = false; - need_libmath = false; need_libdl = false; need_libstdc = false; - // need_libquadmath = false; - need_rdynamic = false; break; case OPT_static_libgcobol: -#ifdef HAVE_LD_STATIC_DYNAMIC static_libgcobol = true; need_libgcobol = true; -#endif break; case OPT_l: n_infiles += 1; - if(strcmp(decoded_options[i].arg, MATH_LIBRARY) == 0) - { - need_libmath = false; - } - else if(strcmp(decoded_options[i].arg, DL_LIBRARY) == 0) + if(strcmp(decoded_options[i].arg, DL_LIBRARY) == 0) { need_libdl = false; } @@ -415,8 +309,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, case OPT_print_multi_os_directory: case OPT_print_multiarch: case OPT_print_sysroot_headers_suffix: - no_files_error = false; - break; + no_files_error = false; + break; case OPT_v: no_files_error = false; @@ -485,10 +379,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, if( n_infiles == 0 ) { need_libgcobol = false; - need_libmath = false; need_libdl = false; need_libstdc = false; - // need_libquadmath = false; } /* Second pass through arglist, transforming arguments as appropriate. */ @@ -528,15 +420,11 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, if( prior_main ) { - char ach[128]; - if( entry_point ) - { - strcpy(ach, entry_point); - } + const char *ach; + if (entry_point) + ach = entry_point; else - { - strcpy(ach, decoded_options[i].arg); - } + ach = decoded_options[i].arg; append_option(OPT_main_, ach, 1); prior_main = false; entry_point = NULL; @@ -576,7 +464,11 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, break; case OPT_static_libgcobol: - // Don't pass this one on to cobol1 +#if !defined (HAVE_LD_STATIC_DYNAMIC) + // Allow the target to use spec substitution. + append_arg(decoded_options[i]); +#endif + // Else don't pass this one on to cobol1 break; ////#ifdef __x86_64__ @@ -616,44 +508,17 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, if( need_libgcobol ) { -#ifdef EXEC_LIB - append_option(OPT_L, EXEC_LIB, 1); -#endif add_arg_lib(COBOL_LIBRARY, static_libgcobol); } - if( need_libmath ) - { - add_arg_lib(MATH_LIBRARY, static_in_general); - } - if( need_libdl ) + if( need_libdl ) { add_arg_lib(DL_LIBRARY, static_in_general); } - if( need_libstdc && static_in_general ) + if( need_libstdc ) { add_arg_lib(STDCPP_LIBRARY, static_in_general); } - if( saw_OPT_shared && !saw_OPT_pic && !saw_OPT_PIC ) - { - append_fpic(); - } - - if( need_rdynamic ) - { - append_rdynamic(); - } - - if( need_allow_multiple_definition && (n_infiles || n_outfiles) ) - { - append_allow_multiple_definition(); - } - - if( need_rpath && (n_infiles || n_outfiles) ) - { - append_rpath(); - } - if( prior_main ) { char ach[] = "\"-main\" without a source file"; @@ -676,13 +541,14 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, #endif if( verbose && new_options != original_options ) { - fprintf(stderr, _("Driving: (%ld)\n"), new_option_count); + fprintf(stderr, _("Driving: (" HOST_SIZE_T_PRINT_DEC ")\n"), + (fmt_size_t)new_option_count); for(size_t i=0; i<new_option_count; i++) { fprintf(stderr, - " [%2ld] %4ld %s\n", - i, - new_options[i].opt_index, + " [%2" GCC_PRISZ "d] %4" GCC_PRISZ "d %s\n", + (fmt_size_t)i, + (fmt_size_t)new_options[i].opt_index, new_options[i].orig_option_with_args_text); } fprintf (stderr, "\n"); @@ -692,14 +558,12 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, *in_decoded_options = new_options; } -/* - * Called before linking. - * Returns 0 on success and -1 on failure. - * Unused. - */ +/* Called before linking. Returns 0 on success and -1 on failure. */ int -lang_specific_pre_link( void ) - { - return 0; - } +lang_specific_pre_link (void) +{ + if (need_libgcobol) + do_spec ("%:include(libgcobol.spec)"); + return 0; +} |