diff options
author | Ulf Samuelsson <ulf@emagii.com> | 2023-02-14 10:13:28 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2023-02-14 10:13:28 +0000 |
commit | 0d79a2a8e2d91fc258ac795c19c13e3ab505a6c2 (patch) | |
tree | 6d366ae54f94ded995f08e3f2ea8ac47aa542de5 /ld/ldlang.c | |
parent | 12ef68305572ed139825be827b2bb1d1aef3ca25 (diff) | |
download | gdb-0d79a2a8e2d91fc258ac795c19c13e3ab505a6c2.zip gdb-0d79a2a8e2d91fc258ac795c19c13e3ab505a6c2.tar.gz gdb-0d79a2a8e2d91fc258ac795c19c13e3ab505a6c2.tar.bz2 |
ASCIZ Command for output section
Adds a new directive to the linker script syntax: ASCIZ.
This inserts a zero-terminated string into the output at the place where it is used.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r-- | ld/ldlang.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c index b5e0d02..b20455c 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -8361,6 +8361,89 @@ lang_add_data (int type, union etree_union *exp) new_stmt->type = type; } +void +lang_add_string (const char *s) +{ + bfd_vma len = strlen (s); + bfd_vma i; + bool escape = false; + + /* Add byte expressions until end of string. */ + for (i = 0 ; i < len; i++) + { + char c = *s++; + + if (escape) + { + switch (c) + { + default: + /* Ignore the escape. */ + break; + + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + /* We have an octal number. */ + { + unsigned int value = c - '0'; + + c = *s; + if ((c >= '0') && (c <= '7')) + { + value <<= 3; + value += (c - '0'); + i++; + s++; + + c = *s; + if ((c >= '0') && (c <= '7')) + { + value <<= 3; + value += (c - '0'); + i++; + s++; + } + } + + if (value > 0xff) + { + /* octal: \777 is treated as '\077' + '7' */ + value >>= 3; + i--; + s--; + } + + c = value; + } + break; + } + + lang_add_data (BYTE, exp_intop (c)); + escape = false; + } + else + { + if (c == '\\') + escape = true; + else + lang_add_data (BYTE, exp_intop (c)); + } + } + + /* Remeber to terminate the string. */ + lang_add_data (BYTE, exp_intop (0)); +} + /* Create a new reloc statement. RELOC is the BFD relocation type to generate. HOWTO is the corresponding howto structure (we could look this up, but the caller has already done so). SECTION is the |