summaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-03-09 11:53:52 +1030
committerAlan Modra <amodra@gmail.com>2023-03-10 21:22:16 +1030
commita4d5aec71e097837ee314eca612f71a3d85b6b3f (patch)
treed8a312e80b6695a55f015b38c6f842b3c4d6fa6a /ld/ldlang.c
parent75bd292bea53d6ce8de66f30d67c2edb4a558110 (diff)
downloadbinutils-gdb-a4d5aec71e097837ee314eca612f71a3d85b6b3f.tar.gz
Revert ld ASCII support
Revert "Prevent the ASCII linker script directive from generating huge amounts of padding if the size expression is not a constant." This reverts commit adbe951fc95943016325af08d677f18e8c177ac1. Revert "ld test asciz and ascii fails" This reverts the ascii.d part of commit 5f497256bee624f0fa470949aa41534093bc5b25. Revert "Add support for the ASCII directive inside linker scripts." This mostly reverts commit 9fe129a4105bb59398f73ce96938a94f19265b79 leaving the asciz.d and asciz.t changes in place.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c69
1 files changed, 16 insertions, 53 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 295de015da9..61de63809cd 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -8400,20 +8400,15 @@ lang_add_data (int type, union etree_union *exp)
new_stmt->type = type;
}
-/* Convert escape codes in S.
- Supports \n, \r, \t and \NNN octals.
- Returns a copy of S in a malloc'ed buffer. */
-
-static char *
-convert_string (const char * s)
+void
+lang_add_string (const char *s)
{
- size_t len = strlen (s);
- size_t i;
- bool escape = false;
- char * buffer = malloc (len + 1);
- char * b;
+ bfd_vma len = strlen (s);
+ bfd_vma i;
+ bool escape = false;
- for (i = 0, b = buffer; i < len; i++)
+ /* Add byte expressions until end of string. */
+ for (i = 0 ; i < len; i++)
{
char c = *s++;
@@ -8448,7 +8443,7 @@ convert_string (const char * s)
value += (c - '0');
i++;
s++;
-
+
c = *s;
if ((c >= '0') && (c <= '7'))
{
@@ -8466,58 +8461,26 @@ convert_string (const char * s)
i--;
s--;
}
-
+
c = value;
}
break;
}
+
+ lang_add_data (BYTE, exp_intop (c));
escape = false;
}
else
{
if (c == '\\')
- {
- escape = true;
- continue;
- }
+ escape = true;
+ else
+ lang_add_data (BYTE, exp_intop (c));
}
-
- * b ++ = c;
- }
-
- * b = 0;
- return buffer;
-}
-
-void
-lang_add_string (size_t size, const char *s)
-{
- size_t len;
- size_t i;
- char * string;
-
- string = convert_string (s);
- len = strlen (string);
-
- /* Check if it is ASCIZ command (len == 0) */
- if (size == 0)
- /* Make sure that we include the terminating nul byte. */
- size = len + 1;
- else if (len >= size)
- {
- len = size - 1;
-
- einfo (_("%P:%pS: warning: ASCII string does not fit in allocated space,"
- " truncated\n"), NULL);
}
- for (i = 0 ; i < len ; i++)
- lang_add_data (BYTE, exp_intop (string[i]));
-
- while (i++ < size)
- lang_add_data (BYTE, exp_intop ('\0'));
-
- free (string);
+ /* Remeber to terminate the string. */
+ lang_add_data (BYTE, exp_intop (0));
}
/* Create a new reloc statement. RELOC is the BFD relocation type to