GCC with patches for OS216
Revision | 6600738d96c8e862c0c8272b302f01e4fab4dca2 (tree) |
---|---|
Time | 2020-05-22 02:45:54 |
Author | Giuliano Belinassi <giuliano.belinassi@usp....> |
Commiter | Giuliano Belinassi |
Implement remaining cases
There was two cases which required additional attention:
Here we fix both of these cases, and also initilizes the additional-asm
file in a more reliable place.
Bootstrap is working here.
gcc/ChangeLog
2020-05-20 Giuliano Belinassi <giuliano.belinassi@usp.br>
* gcc.c (get_file_by_lines): Accept a path to file instead of FILE
object
(identify_asm_file): Better object identification heuristic.
(append_split_outputs): Return if temporary asm file was not
created, and also implement -o case.
(fsplit_arg): Remove .s extension from temporary file.
* toplev.c (init_additional_asm_names_file): Close and flush file.
(do_compile): init_additional_asm_names_file here instead of.
(land_dependent_init): Here.
@@ -1,3 +1,15 @@ | ||
1 | +2020-05-20 Giuliano Belinassi <giuliano.belinassi@usp.br> | |
2 | + | |
3 | + * gcc.c (get_file_by_lines): Accept a path to file instead of FILE | |
4 | + object | |
5 | + (identify_asm_file): Better object identification heuristic. | |
6 | + (append_split_outputs): Return if temporary asm file was not | |
7 | + created, and also implement -o case. | |
8 | + (fsplit_arg): Remove .s extension from temporary file. | |
9 | + * toplev.c (init_additional_asm_names_file): Close and flush file. | |
10 | + (do_compile): init_additional_asm_names_file here instead of. | |
11 | + (land_dependent_init): Here. | |
12 | + | |
1 | 13 | 2020-05-18 Giuliano Belinassi <giuliano.belinassi@usp.br> |
2 | 14 | |
3 | 15 | * gcc.c (append_split_outputs): Truncate temp_obj vector for the |
@@ -3149,8 +3149,6 @@ static bool is_assembler (const char *arg) | ||
3149 | 3149 | return false; |
3150 | 3150 | } |
3151 | 3151 | |
3152 | - | |
3153 | - | |
3154 | 3152 | /* Get argv[] array length. */ |
3155 | 3153 | |
3156 | 3154 | static int get_number_of_args (const char *argv[]) |
@@ -3168,11 +3166,18 @@ static const char *fsplit_arg (extra_arg_storer *); | ||
3168 | 3166 | /* Accumulate each line in lines vec. */ |
3169 | 3167 | |
3170 | 3168 | void |
3171 | -get_file_by_lines (extra_arg_storer *storer, vec<char *> *lines, FILE* file) | |
3169 | +get_file_by_lines (extra_arg_storer *storer, vec<char *> *lines, const char *name) | |
3172 | 3170 | { |
3173 | - int buf_size = 32, len = 0; | |
3171 | + int buf_size = 64, len = 0; | |
3174 | 3172 | char *buf = XNEWVEC (char, buf_size); |
3175 | 3173 | |
3174 | + | |
3175 | + FILE *file = fopen (name, "r"); | |
3176 | + | |
3177 | + if (!file) | |
3178 | + fatal_error (input_location, | |
3179 | + "Temporary file containing additional assember files not found"); | |
3180 | + | |
3176 | 3181 | while (1) |
3177 | 3182 | { |
3178 | 3183 | if (!fgets (buf + len, buf_size, file)) |
@@ -3195,6 +3200,14 @@ get_file_by_lines (extra_arg_storer *storer, vec<char *> *lines, FILE* file) | ||
3195 | 3200 | buf = XRESIZEVEC (char, buf, buf_size * 2); |
3196 | 3201 | } |
3197 | 3202 | } |
3203 | + | |
3204 | + if (lines->length () == 0) | |
3205 | + { | |
3206 | + fprintf (stderr, "File name: %s\n", name); | |
3207 | + internal_error ("Empty file"); | |
3208 | + } | |
3209 | + | |
3210 | + fclose (file); | |
3198 | 3211 | } |
3199 | 3212 | |
3200 | 3213 | static void identify_asm_file (int argc, const char *argv[], |
@@ -3203,7 +3216,6 @@ static void identify_asm_file (int argc, const char *argv[], | ||
3203 | 3216 | int i; |
3204 | 3217 | |
3205 | 3218 | static const char *asm_extension[] = {"s", "S"}; |
3206 | - static const char *obj_extension[] = {"o", "O"}; | |
3207 | 3219 | |
3208 | 3220 | bool infile_found = false; |
3209 | 3221 | bool outfile_found = false; |
@@ -3229,13 +3241,11 @@ static void identify_asm_file (int argc, const char *argv[], | ||
3229 | 3241 | } |
3230 | 3242 | |
3231 | 3243 | if (!outfile_found) |
3232 | - for (j = 0; j < ARRAY_SIZE (asm_extension); ++j) | |
3233 | - if (!strcmp (ext, obj_extension[j])) | |
3234 | - { | |
3235 | - outfile_found = true; | |
3236 | - *outfile_pos = i; | |
3237 | - break; | |
3238 | - } | |
3244 | + if (!strcmp (ext, "-o")) | |
3245 | + { | |
3246 | + outfile_found = true; | |
3247 | + *outfile_pos = i+1; | |
3248 | + } | |
3239 | 3249 | |
3240 | 3250 | if (infile_found && outfile_found) |
3241 | 3251 | return; |
@@ -3277,7 +3287,7 @@ static vec<const char *> temp_object_files; | ||
3277 | 3287 | |
3278 | 3288 | static const char *get_path_to_ld (void) |
3279 | 3289 | { |
3280 | - const char *ret = find_a_file (&exec_prefixes, "ld", X_OK, false); | |
3290 | + const char *ret = find_a_file (&exec_prefixes, LINKER_NAME, X_OK, false); | |
3281 | 3291 | if (!ret) |
3282 | 3292 | ret = "ld"; |
3283 | 3293 |
@@ -3318,8 +3328,6 @@ static void append_split_outputs (extra_arg_storer *storer, | ||
3318 | 3328 | { |
3319 | 3329 | vec<char *> additional_asm_files; |
3320 | 3330 | |
3321 | - FILE *temp_asm_file; | |
3322 | - | |
3323 | 3331 | struct command orig; |
3324 | 3332 | const char **orig_argv; |
3325 | 3333 | int orig_argc; |
@@ -3329,6 +3337,15 @@ static void append_split_outputs (extra_arg_storer *storer, | ||
3329 | 3337 | int outfile_pos = -1; |
3330 | 3338 | |
3331 | 3339 | static const char *path_to_ld = NULL; |
3340 | + | |
3341 | + if (!current_infile->temp_additional_asm) | |
3342 | + { | |
3343 | + /* Return because we did not create a additional-asm file for this | |
3344 | + input. */ | |
3345 | + | |
3346 | + return; | |
3347 | + } | |
3348 | + | |
3332 | 3349 | if (!path_to_ld) |
3333 | 3350 | path_to_ld = get_path_to_ld (); |
3334 | 3351 |
@@ -3338,14 +3355,9 @@ static void append_split_outputs (extra_arg_storer *storer, | ||
3338 | 3355 | fatal_error (input_location, |
3339 | 3356 | "Auto parallelism is unsupported when piping commands"); |
3340 | 3357 | |
3341 | - temp_asm_file = fopen (current_infile->temp_additional_asm, "r"); | |
3342 | 3358 | |
3343 | - if (!temp_asm_file) | |
3344 | - fatal_error (input_location, | |
3345 | - "Temporary file containing additional asm files not found"); | |
3346 | - | |
3347 | - get_file_by_lines (storer, &additional_asm_files, temp_asm_file); | |
3348 | - fclose (temp_asm_file); | |
3359 | + get_file_by_lines (storer, &additional_asm_files, | |
3360 | + current_infile->temp_additional_asm); | |
3349 | 3361 | |
3350 | 3362 | /* Get original command. */ |
3351 | 3363 | orig = commands[0]; |
@@ -3383,13 +3395,13 @@ static void append_split_outputs (extra_arg_storer *storer, | ||
3383 | 3395 | temp_object_files.safe_push (temp_obj); |
3384 | 3396 | } |
3385 | 3397 | |
3386 | - if (have_c && !have_o) | |
3398 | + if (have_c) | |
3387 | 3399 | { |
3388 | 3400 | unsigned int num_temp_objs = temp_object_files.length (); |
3389 | 3401 | const char **argv = storer->create_new (num_temp_objs + 5); |
3390 | 3402 | unsigned int j; |
3391 | 3403 | |
3392 | - argv[0] = "ld"; | |
3404 | + argv[0] = path_to_ld; | |
3393 | 3405 | argv[1] = "-o"; |
3394 | 3406 | argv[2] = orig_obj_file; |
3395 | 3407 | argv[3] = "-r"; |
@@ -3401,7 +3413,8 @@ static void append_split_outputs (extra_arg_storer *storer, | ||
3401 | 3413 | additional_ld->prog = path_to_ld; |
3402 | 3414 | additional_ld->argv = argv; |
3403 | 3415 | |
3404 | - temp_object_files.truncate (0); | |
3416 | + if (!have_o) | |
3417 | + temp_object_files.truncate (0); | |
3405 | 3418 | } |
3406 | 3419 | |
3407 | 3420 | additional_asm_files.release (); |
@@ -3979,7 +3992,7 @@ static char *debug_check_temp_file[2]; | ||
3979 | 3992 | |
3980 | 3993 | static const char *fsplit_arg (extra_arg_storer *storer) |
3981 | 3994 | { |
3982 | - const char *tempname = make_temp_file ("additional-asm.s"); | |
3995 | + const char *tempname = make_temp_file ("additional-asm"); | |
3983 | 3996 | const char arg[] = "-fsplit-outputs="; |
3984 | 3997 | char *final; |
3985 | 3998 |
@@ -6570,7 +6583,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) | ||
6570 | 6583 | "%{foo=*:bar%*}%{foo=*:one%*two}" |
6571 | 6584 | |
6572 | 6585 | matches -foo=hello then it will produce: |
6573 | - | |
6586 | + | |
6574 | 6587 | barhello onehellotwo |
6575 | 6588 | */ |
6576 | 6589 | if (*p == 0 || *p == '}') |
@@ -8836,11 +8849,31 @@ driver::maybe_run_linker (const char *argv0) const | ||
8836 | 8849 | int linker_was_run = 0; |
8837 | 8850 | int num_linker_inputs; |
8838 | 8851 | |
8839 | - /* Determine if there are any linker input files. */ | |
8840 | - num_linker_inputs = 0; | |
8841 | - for (i = 0; (int) i < n_infiles; i++) | |
8842 | - if (explicit_link_files[i] || outfiles[i] != NULL) | |
8843 | - num_linker_inputs++; | |
8852 | + /* Set outfiles to be the temporary object vector. */ | |
8853 | + const char **outfiles_holder = outfiles; | |
8854 | + int n_infiles_holder = n_infiles; | |
8855 | + bool outfiles_switched = false; | |
8856 | + if (temp_object_files.length () > 0) | |
8857 | + { | |
8858 | + /* Insert explicit link files into the temp object vector. */ | |
8859 | + | |
8860 | + for (i = 0; (int) i < n_infiles; i++) | |
8861 | + if (explicit_link_files[i] && outfiles[i] != NULL) | |
8862 | + temp_object_files.safe_push (outfiles[i]); | |
8863 | + | |
8864 | + num_linker_inputs = n_infiles = temp_object_files.length (); | |
8865 | + temp_object_files.safe_push (NULL); /* the NULL sentinel. */ | |
8866 | + outfiles = temp_object_files.address (); | |
8867 | + } | |
8868 | + else /* Fall back to the old method. */ | |
8869 | + { | |
8870 | + | |
8871 | + /* Determine if there are any linker input files. */ | |
8872 | + num_linker_inputs = 0; | |
8873 | + for (i = 0; (int) i < n_infiles; i++) | |
8874 | + if (explicit_link_files[i] || outfiles[i] != NULL) | |
8875 | + num_linker_inputs++; | |
8876 | + } | |
8844 | 8877 | |
8845 | 8878 | /* Run ld to link all the compiler output files. */ |
8846 | 8879 |
@@ -8911,14 +8944,23 @@ driver::maybe_run_linker (const char *argv0) const | ||
8911 | 8944 | } |
8912 | 8945 | |
8913 | 8946 | /* If options said don't run linker, |
8914 | - complain about input files to be given to the linker. */ | |
8947 | + complain about input files to be given to the linker. | |
8948 | + When fsplit-arg is active, the linker will run and this if | |
8949 | + will not be triggered. */ | |
8915 | 8950 | |
8916 | - if (! linker_was_run && !seen_error ()) | |
8951 | + if (!outfiles_switched && !linker_was_run && !seen_error ()) | |
8917 | 8952 | for (i = 0; (int) i < n_infiles; i++) |
8918 | 8953 | if (explicit_link_files[i] |
8919 | 8954 | && !(infiles[i].language && infiles[i].language[0] == '*')) |
8920 | 8955 | warning (0, "%s: linker input file unused because linking not done", |
8921 | 8956 | outfiles[i]); |
8957 | + | |
8958 | + if (outfiles_switched) | |
8959 | + { | |
8960 | + /* Undo our changes. */ | |
8961 | + outfiles = outfiles_holder; | |
8962 | + n_infiles = n_infiles_holder; | |
8963 | + } | |
8922 | 8964 | } |
8923 | 8965 | |
8924 | 8966 | /* The end of "main". */ |
@@ -10735,6 +10777,7 @@ driver::finalize () | ||
10735 | 10777 | linker_options.truncate (0); |
10736 | 10778 | assembler_options.truncate (0); |
10737 | 10779 | preprocessor_options.truncate (0); |
10780 | + temp_object_files.truncate (0); | |
10738 | 10781 | |
10739 | 10782 | path_prefix_reset (&exec_prefixes); |
10740 | 10783 | path_prefix_reset (&startfile_prefixes); |
@@ -916,6 +916,8 @@ init_additional_asm_names_file (int n, const char *names[]) | ||
916 | 916 | for (i = 0; i < n; ++i) |
917 | 917 | fprintf(additional_asm_filenames, "%s\n", names[i]); |
918 | 918 | |
919 | + fflush (additional_asm_filenames); | |
920 | + fclose (additional_asm_filenames); | |
919 | 921 | } |
920 | 922 | |
921 | 923 | /* A helper function; used as the reallocator function for cpp's line |
@@ -1993,7 +1995,6 @@ lang_dependent_init (const char *name) | ||
1993 | 1995 | if (!flag_wpa) |
1994 | 1996 | { |
1995 | 1997 | init_asm_output (name); |
1996 | - init_additional_asm_names_file (1, &asm_file_name); | |
1997 | 1998 | |
1998 | 1999 | /* If stack usage information is desired, open the output file. */ |
1999 | 2000 | if (flag_stack_usage && !flag_generate_lto) |
@@ -2275,8 +2276,14 @@ do_compile () | ||
2275 | 2276 | if (!no_backend) |
2276 | 2277 | backend_init (); |
2277 | 2278 | |
2279 | + int init = lang_dependent_init (main_input_filename); | |
2280 | + | |
2281 | + /* This creates a file which we will dump any additional asm file we | |
2282 | + may need. */ | |
2283 | + init_additional_asm_names_file (1, &asm_file_name); | |
2284 | + | |
2278 | 2285 | /* Language-dependent initialization. Returns true on success. */ |
2279 | - if (lang_dependent_init (main_input_filename)) | |
2286 | + if (init) | |
2280 | 2287 | { |
2281 | 2288 | /* Initialize yet another pass. */ |
2282 | 2289 |