diff options
author | Alan Modra <amodra@gmail.com> | 2023-03-12 13:27:38 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-03-14 12:14:32 +1030 |
commit | adb9ac5f3984b4ad2d8be1550dc5683d6129e1a6 (patch) | |
tree | f0c3287356bda7212583c29ef9b1dedc5a4244a5 /gas/config/tc-tic54x.c | |
parent | a2aee680684ec8c79bbdc169d73fe5111e8e9a64 (diff) | |
download | fsf-binutils-gdb-adb9ac5f3984b4ad2d8be1550dc5683d6129e1a6.zip fsf-binutils-gdb-adb9ac5f3984b4ad2d8be1550dc5683d6129e1a6.tar.gz fsf-binutils-gdb-adb9ac5f3984b4ad2d8be1550dc5683d6129e1a6.tar.bz2 |
gas .include and .incbin
This fixes a bug in .include and .incbin where given an absolute path
the -I dirs would be searched for the path.
* read.c (include_dir_count, include_dir_maxlen): Make them size_t.
(search_and_open): New function.
(s_incbin, s_include): Use search_and_open.
(init_include_dir): New function.
(add_include_dir): Don't set initial "." dir here.
* read.h (include_dir_count, include_dir_maxlen): Update.
(init_include_dir, search_and_open): Declare.
* as.c (gas_early_init): Call init_include_dir.
* config/tc-rx.c (rx_include): Avoid warning by using size_t.
* config/tc-tic54x.c (tic54x_set_default_include): Simplify and
use notes for include path.
(tic54x_mlib): Use search_and_open.
Diffstat (limited to 'gas/config/tc-tic54x.c')
-rw-r--r-- | gas/config/tc-tic54x.c | 55 |
1 files changed, 11 insertions, 44 deletions
diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c index f687dfe..4dc1dbf 100644 --- a/gas/config/tc-tic54x.c +++ b/gas/config/tc-tic54x.c @@ -1909,35 +1909,22 @@ tic54x_clink (int ignored ATTRIBUTE_UNUSED) } /* Change the default include directory to be the current source file's - directory, instead of the current working directory. If DOT is non-zero, - set to "." instead. */ + directory. */ static void tic54x_set_default_include (void) { - char *dir, *tmp = NULL; - const char *curfile; unsigned lineno; - - curfile = as_where (&lineno); - dir = xstrdup (curfile); - tmp = strrchr (dir, '/'); + const char *curfile = as_where (&lineno); + const char *tmp = strrchr (curfile, '/'); if (tmp != NULL) { - int len; - - *tmp = '\0'; - len = strlen (dir); - if (include_dir_count == 0) - { - include_dirs = XNEWVEC (const char *, 1); - include_dir_count = 1; - } - include_dirs[0] = dir; + size_t len = tmp - curfile; if (len > include_dir_maxlen) include_dir_maxlen = len; + include_dirs[0] = notes_memdup (curfile, len, len + 1); } - else if (include_dirs != NULL) + else include_dirs[0] = "."; } @@ -2325,7 +2312,7 @@ tic54x_mlib (int ignore ATTRIBUTE_UNUSED) { char *filename; char *path; - int len, i; + int len; bfd *abfd, *mbfd; ILLEGAL_WITHIN_STRUCT (); @@ -2353,31 +2340,11 @@ tic54x_mlib (int ignore ATTRIBUTE_UNUSED) demand_empty_rest_of_line (); tic54x_set_default_include (); - path = XNEWVEC (char, (unsigned long) len + include_dir_maxlen + 5); - - for (i = 0; i < include_dir_count; i++) - { - FILE *try; - - strcpy (path, include_dirs[i]); - strcat (path, "/"); - strcat (path, filename); - if ((try = fopen (path, "r")) != NULL) - { - fclose (try); - break; - } - } - - if (i >= include_dir_count) - { - free (path); - path = filename; - } + path = notes_alloc (len + include_dir_maxlen + 2); + FILE *try = search_and_open (filename, path); + if (try) + fclose (try); - /* FIXME: if path is found, malloc'd storage is not freed. Of course, this - happens all over the place, and since the assembler doesn't usually keep - running for a very long time, it really doesn't matter. */ register_dependency (path); /* Expand all archive entries to temporary files and include them. */ |