• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GCC with patches for OS216


Commit MetaInfo

Revision6600738d96c8e862c0c8272b302f01e4fab4dca2 (tree)
Time2020-05-22 02:45:54
AuthorGiuliano Belinassi <giuliano.belinassi@usp....>
CommiterGiuliano Belinassi

Log Message

Implement remaining cases

There was two cases which required additional attention:

  • When -c and -o is provided.
  • When cc1* is called to compile an .S file.

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.

Change Summary

Incremental Difference

--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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+
113 2020-05-18 Giuliano Belinassi <giuliano.belinassi@usp.br>
214
315 * gcc.c (append_split_outputs): Truncate temp_obj vector for the
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3149,8 +3149,6 @@ static bool is_assembler (const char *arg)
31493149 return false;
31503150 }
31513151
3152-
3153-
31543152 /* Get argv[] array length. */
31553153
31563154 static int get_number_of_args (const char *argv[])
@@ -3168,11 +3166,18 @@ static const char *fsplit_arg (extra_arg_storer *);
31683166 /* Accumulate each line in lines vec. */
31693167
31703168 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)
31723170 {
3173- int buf_size = 32, len = 0;
3171+ int buf_size = 64, len = 0;
31743172 char *buf = XNEWVEC (char, buf_size);
31753173
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+
31763181 while (1)
31773182 {
31783183 if (!fgets (buf + len, buf_size, file))
@@ -3195,6 +3200,14 @@ get_file_by_lines (extra_arg_storer *storer, vec<char *> *lines, FILE* file)
31953200 buf = XRESIZEVEC (char, buf, buf_size * 2);
31963201 }
31973202 }
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);
31983211 }
31993212
32003213 static void identify_asm_file (int argc, const char *argv[],
@@ -3203,7 +3216,6 @@ static void identify_asm_file (int argc, const char *argv[],
32033216 int i;
32043217
32053218 static const char *asm_extension[] = {"s", "S"};
3206- static const char *obj_extension[] = {"o", "O"};
32073219
32083220 bool infile_found = false;
32093221 bool outfile_found = false;
@@ -3229,13 +3241,11 @@ static void identify_asm_file (int argc, const char *argv[],
32293241 }
32303242
32313243 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+ }
32393249
32403250 if (infile_found && outfile_found)
32413251 return;
@@ -3277,7 +3287,7 @@ static vec<const char *> temp_object_files;
32773287
32783288 static const char *get_path_to_ld (void)
32793289 {
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);
32813291 if (!ret)
32823292 ret = "ld";
32833293
@@ -3318,8 +3328,6 @@ static void append_split_outputs (extra_arg_storer *storer,
33183328 {
33193329 vec<char *> additional_asm_files;
33203330
3321- FILE *temp_asm_file;
3322-
33233331 struct command orig;
33243332 const char **orig_argv;
33253333 int orig_argc;
@@ -3329,6 +3337,15 @@ static void append_split_outputs (extra_arg_storer *storer,
33293337 int outfile_pos = -1;
33303338
33313339 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+
33323349 if (!path_to_ld)
33333350 path_to_ld = get_path_to_ld ();
33343351
@@ -3338,14 +3355,9 @@ static void append_split_outputs (extra_arg_storer *storer,
33383355 fatal_error (input_location,
33393356 "Auto parallelism is unsupported when piping commands");
33403357
3341- temp_asm_file = fopen (current_infile->temp_additional_asm, "r");
33423358
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);
33493361
33503362 /* Get original command. */
33513363 orig = commands[0];
@@ -3383,13 +3395,13 @@ static void append_split_outputs (extra_arg_storer *storer,
33833395 temp_object_files.safe_push (temp_obj);
33843396 }
33853397
3386- if (have_c && !have_o)
3398+ if (have_c)
33873399 {
33883400 unsigned int num_temp_objs = temp_object_files.length ();
33893401 const char **argv = storer->create_new (num_temp_objs + 5);
33903402 unsigned int j;
33913403
3392- argv[0] = "ld";
3404+ argv[0] = path_to_ld;
33933405 argv[1] = "-o";
33943406 argv[2] = orig_obj_file;
33953407 argv[3] = "-r";
@@ -3401,7 +3413,8 @@ static void append_split_outputs (extra_arg_storer *storer,
34013413 additional_ld->prog = path_to_ld;
34023414 additional_ld->argv = argv;
34033415
3404- temp_object_files.truncate (0);
3416+ if (!have_o)
3417+ temp_object_files.truncate (0);
34053418 }
34063419
34073420 additional_asm_files.release ();
@@ -3979,7 +3992,7 @@ static char *debug_check_temp_file[2];
39793992
39803993 static const char *fsplit_arg (extra_arg_storer *storer)
39813994 {
3982- const char *tempname = make_temp_file ("additional-asm.s");
3995+ const char *tempname = make_temp_file ("additional-asm");
39833996 const char arg[] = "-fsplit-outputs=";
39843997 char *final;
39853998
@@ -6570,7 +6583,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
65706583 "%{foo=*:bar%*}%{foo=*:one%*two}"
65716584
65726585 matches -foo=hello then it will produce:
6573-
6586+
65746587 barhello onehellotwo
65756588 */
65766589 if (*p == 0 || *p == '}')
@@ -8836,11 +8849,31 @@ driver::maybe_run_linker (const char *argv0) const
88368849 int linker_was_run = 0;
88378850 int num_linker_inputs;
88388851
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+ }
88448877
88458878 /* Run ld to link all the compiler output files. */
88468879
@@ -8911,14 +8944,23 @@ driver::maybe_run_linker (const char *argv0) const
89118944 }
89128945
89138946 /* 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. */
89158950
8916- if (! linker_was_run && !seen_error ())
8951+ if (!outfiles_switched && !linker_was_run && !seen_error ())
89178952 for (i = 0; (int) i < n_infiles; i++)
89188953 if (explicit_link_files[i]
89198954 && !(infiles[i].language && infiles[i].language[0] == '*'))
89208955 warning (0, "%s: linker input file unused because linking not done",
89218956 outfiles[i]);
8957+
8958+ if (outfiles_switched)
8959+ {
8960+ /* Undo our changes. */
8961+ outfiles = outfiles_holder;
8962+ n_infiles = n_infiles_holder;
8963+ }
89228964 }
89238965
89248966 /* The end of "main". */
@@ -10735,6 +10777,7 @@ driver::finalize ()
1073510777 linker_options.truncate (0);
1073610778 assembler_options.truncate (0);
1073710779 preprocessor_options.truncate (0);
10780+ temp_object_files.truncate (0);
1073810781
1073910782 path_prefix_reset (&exec_prefixes);
1074010783 path_prefix_reset (&startfile_prefixes);
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -916,6 +916,8 @@ init_additional_asm_names_file (int n, const char *names[])
916916 for (i = 0; i < n; ++i)
917917 fprintf(additional_asm_filenames, "%s\n", names[i]);
918918
919+ fflush (additional_asm_filenames);
920+ fclose (additional_asm_filenames);
919921 }
920922
921923 /* A helper function; used as the reallocator function for cpp's line
@@ -1993,7 +1995,6 @@ lang_dependent_init (const char *name)
19931995 if (!flag_wpa)
19941996 {
19951997 init_asm_output (name);
1996- init_additional_asm_names_file (1, &asm_file_name);
19971998
19981999 /* If stack usage information is desired, open the output file. */
19992000 if (flag_stack_usage && !flag_generate_lto)
@@ -2275,8 +2276,14 @@ do_compile ()
22752276 if (!no_backend)
22762277 backend_init ();
22772278
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+
22782285 /* Language-dependent initialization. Returns true on success. */
2279- if (lang_dependent_init (main_input_filename))
2286+ if (init)
22802287 {
22812288 /* Initialize yet another pass. */
22822289