This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RE: New keywords (string32) for GNU as ?
Hi Dave,
Dave Korn wrote:
> On 19 November 2006 14:23, Helge Deller wrote:
>> Would this kind of new keyword "in principle" be acceptable for GNU
>> as/binutils ?
> ....
> That said, I think your patch is well motivated and a reasonable
> solution to the problem. I haven't tested it yet but it looks sane.
Thanks a lot for your feedback.
Below is an updated patch against CVS HEAD, which should include all your
proposed changes, which include:
- added .string64 as well (beside .string8, .string16, .string32)
- cleaned up the coding style
- fixed the comments
- abort on coding error (if wrong bitsize was provided)
- fixed up all callers of the stringer() function to include the bit size
- added Changelog entries
- added a testcase (strings.s, strings.d)
Additionally, I did tested, compiled and ran a "make check" sucessfully on
Linux/i686/little-endian _and_ Linux/hppa/big-endian.
Could you please take a look at it again ?
As a side-note: If this patch would be ok, will someone (who?) take it up
and commit, or should I maybe ask for a cvs-commit rights and commit
myself ?
Helge
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gas/ChangeLog,v
retrieving revision 1.3060
diff -u -p -r1.3060 ChangeLog
--- ChangeLog 20 Nov 2006 01:28:43 -0000 1.3060
+++ ChangeLog 21 Nov 2006 22:59:32 -0000
@@ -1,3 +1,25 @@
+2006-11-21 Helge Deller <deller@gmx.de>
+
+ * read.c (potable): Add string8, string16, string32 and string64.
+ Add bit size for stringer function.
+ (stringer_append_char): New.
+ (stringer): Use stringer_append_char().
+ * config/obj-coff.c (obj_coff_ident): Add bit size for stringer function.
+ * config/obj-elf.c (obj_elf_ident): Likewise.
+ * config/tc-alpha.c (s_alpha_stringer): Likewise.
+ * config/tc-dlx.c (dlx_pseudo_table): Likewise.
+ * config/tc-hppa.c (pa_stringer): Likewise.
+ * config/tc-ia64.c (md_pseudo_table, pseudo_opcode): Likewise.
+ * config/tc-m68hc11.c (md_pseudo_table): Likewise.
+ * config/tc-mcore.c (md_pseudo_table): Likewise.
+ * config/tc-mips.c (mips_pseudo_table): Likewise.
+ * config/tc-spu.c (md_pseudo_table): Likewise.
+ * config/tc-s390.c (md_pseudo_table): Likewise. Replace '2' by '1'.
+ * doc/as.texinfo (ABORT): Fix identing.
+ (String): Document new string8, string16, string32, string64 functions.
+ * testsuite/gas/all/gas.exp: Include new test "strings"
+ * testsuite/gas/all/string.s, testsuite/gas/all/string.d: New.
+
2006-11-16 Mei ligang <ligang@sunnorth.com.cn>
* config/tc-score.c (score_relax_frag): If next frag contains 32 bit
branch
Index: read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.121
diff -u -p -r1.121 read.c
--- read.c 29 Aug 2006 15:19:43 -0000 1.121
+++ read.c 21 Nov 2006 22:59:33 -0000
@@ -266,8 +266,8 @@ static const pseudo_typeS potable[] = {
{"abort", s_abort, 0},
{"align", s_align_ptwo, 0},
{"altmacro", s_altmacro, 1},
- {"ascii", stringer, 0},
- {"asciz", stringer, 1},
+ {"ascii", stringer, 8+0},
+ {"asciz", stringer, 8+1},
{"balign", s_align_bytes, 0},
{"balignw", s_align_bytes, -2},
{"balignl", s_align_bytes, -4},
@@ -407,7 +407,11 @@ static const pseudo_typeS potable[] = {
{"stabd", s_stab, 'd'},
{"stabn", s_stab, 'n'},
{"stabs", s_stab, 's'},
- {"string", stringer, 1},
+ {"string", stringer, 8+1},
+ {"string8", stringer, 8+1},
+ {"string16", stringer, 16+1},
+ {"string32", stringer, 32+1},
+ {"string64", stringer, 64+1},
{"struct", s_struct, 0},
/* tag */
{"text", s_text, 0},
@@ -4654,6 +4658,36 @@ s_leb128 (int sign)
input_line_pointer--;
demand_empty_rest_of_line ();
}
+
+static void stringer_append_char( int c, int bitsize )
+{
+ if (!target_big_endian)
+ FRAG_APPEND_1_CHAR(c);
+ switch (bitsize) {
+ case 64:
+ FRAG_APPEND_1_CHAR(0);
+ FRAG_APPEND_1_CHAR(0);
+ FRAG_APPEND_1_CHAR(0);
+ FRAG_APPEND_1_CHAR(0);
+ /* Fall through */
+ case 32:
+ FRAG_APPEND_1_CHAR(0);
+ FRAG_APPEND_1_CHAR(0);
+ /* Fall through */
+ case 16:
+ FRAG_APPEND_1_CHAR(0);
+ /* Fall through */
+ case 8:
+ break;
+ default:
+ /* Called with invalid bitsize argument. */
+ abort();
+ break;
+ }
+ if (target_big_endian)
+ FRAG_APPEND_1_CHAR(c);
+}
+
/* We read 0 or more ',' separated, double-quoted strings.
Caller should have checked need_pass_2 is FALSE because we don't
@@ -4662,8 +4696,12 @@ s_leb128 (int sign)
void
stringer (/* Worker to do .ascii etc statements. */
/* Checks end-of-line. */
- register int append_zero /* 0: don't append '\0', else 1. */)
+ int bits_appendzero )
+ /* bits_appendzero: bit 0 = 0: don't append '\0', else 1. */
+ /* Upper bits in bits_appendzero define target char bitsize */
{
+ const int bitsize = bits_appendzero & ~7;
+ const int append_zero = bits_appendzero & 1;
register unsigned int c;
char *start;
@@ -4704,11 +4742,11 @@ stringer (/* Worker to do .ascii etc sta
start = input_line_pointer;
while (is_a_char (c = next_char_of_string ()))
{
- FRAG_APPEND_1_CHAR (c);
+ stringer_append_char (c, bitsize);
}
if (append_zero)
{
- FRAG_APPEND_1_CHAR (0);
+ stringer_append_char (0, bitsize);
}
know (input_line_pointer[-1] == '\"');
@@ -4736,7 +4774,7 @@ stringer (/* Worker to do .ascii etc sta
case '<':
input_line_pointer++;
c = get_single_number ();
- FRAG_APPEND_1_CHAR (c);
+ stringer_append_char (c, bitsize);
if (*input_line_pointer != '>')
{
as_bad (_("expected <nn>"));
Index: config/obj-coff.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-coff.c,v
retrieving revision 1.91
diff -u -p -r1.91 obj-coff.c
--- config/obj-coff.c 23 Apr 2006 22:12:43 -0000 1.91
+++ config/obj-coff.c 21 Nov 2006 22:59:33 -0000
@@ -497,7 +497,7 @@ obj_coff_ident (int ignore ATTRIBUTE_UNU
subseg_new (".comment", 0);
#endif
- stringer (1);
+ stringer (8+1);
subseg_set (current_seg, current_subseg);
}
Index: config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.98
diff -u -p -r1.98 obj-elf.c
--- config/obj-elf.c 10 Nov 2006 07:47:14 -0000 1.98
+++ config/obj-elf.c 21 Nov 2006 22:59:33 -0000
@@ -1613,7 +1613,7 @@ obj_elf_ident (int ignore ATTRIBUTE_UNUS
}
else
subseg_set (comment_section, 0);
- stringer (1);
+ stringer (8+1);
subseg_set (old_section, old_subsection);
}
Index: config/tc-alpha.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-alpha.c,v
retrieving revision 1.71
diff -u -p -r1.71 tc-alpha.c
--- config/tc-alpha.c 16 Nov 2005 01:49:48 -0000 1.71
+++ config/tc-alpha.c 21 Nov 2006 22:59:34 -0000
@@ -4527,7 +4527,7 @@ s_alpha_stringer (int terminate)
{
alpha_current_align = 0;
alpha_insn_label = NULL;
- stringer (terminate);
+ stringer (8+terminate);
}
/* Hook the normal space processing to reset known alignment. */
Index: config/tc-dlx.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-dlx.c,v
retrieving revision 1.15
diff -u -p -r1.15 tc-dlx.c
--- config/tc-dlx.c 7 Jun 2005 17:54:16 -0000 1.15
+++ config/tc-dlx.c 21 Nov 2006 22:59:34 -0000
@@ -1276,7 +1276,7 @@ const pseudo_typeS
dlx_pseudo_table[] =
{
/* Some additional ops that are used by gcc-dlx. */
- {"asciiz", stringer, 1},
+ {"asciiz", stringer, 8+1},
{"half", cons, 2},
{"dword", cons, 8},
{"word", cons, 4},
Index: config/tc-hppa.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-hppa.c,v
retrieving revision 1.133
diff -u -p -r1.133 tc-hppa.c
--- config/tc-hppa.c 30 Oct 2006 01:09:18 -0000 1.133
+++ config/tc-hppa.c 21 Nov 2006 22:59:35 -0000
@@ -8150,7 +8150,7 @@ pa_stringer (int append_zero)
}
}
}
- stringer (append_zero);
+ stringer (8+append_zero);
pa_undefine_label ();
}
Index: config/tc-ia64.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-ia64.c,v
retrieving revision 1.189
diff -u -p -r1.189 tc-ia64.c
--- config/tc-ia64.c 2 May 2006 13:34:25 -0000 1.189
+++ config/tc-ia64.c 21 Nov 2006 22:59:36 -0000
@@ -5530,8 +5530,8 @@ const pseudo_typeS md_pseudo_table[] =
{ "xreal8", dot_xfloat_cons, 'd' },
{ "xreal10", dot_xfloat_cons, 'x' },
{ "xreal16", dot_xfloat_cons, 'X' },
- { "xstring", dot_xstringer, 0 },
- { "xstringz", dot_xstringer, 1 },
+ { "xstring", dot_xstringer, 8+0 },
+ { "xstringz", dot_xstringer, 8+1 },
/* unaligned versions: */
{ "xdata2.ua", dot_xdata_ua, 2 },
@@ -5588,8 +5588,8 @@ pseudo_opcode[] =
{ "real8", stmt_float_cons, 'd' },
{ "real10", stmt_float_cons, 'x' },
{ "real16", stmt_float_cons, 'X' },
- { "string", stringer, 0 },
- { "stringz", stringer, 1 },
+ { "string", stringer, 8+0 },
+ { "stringz", stringer, 8+1 },
/* unaligned versions: */
{ "data2.ua", stmt_cons_ua, 2 },
Index: config/tc-m68hc11.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m68hc11.c,v
retrieving revision 1.50
diff -u -p -r1.50 tc-m68hc11.c
--- config/tc-m68hc11.c 23 Oct 2006 03:23:49 -0000 1.50
+++ config/tc-m68hc11.c 21 Nov 2006 22:59:36 -0000
@@ -263,7 +263,7 @@ const pseudo_typeS md_pseudo_table[] = {
/* The following pseudo-ops are supported for MRI compatibility. */
{"fcb", cons, 1},
{"fdb", cons, 2},
- {"fcc", stringer, 1},
+ {"fcc", stringer, 8+1},
{"rmb", s_space, 0},
/* Motorola ALIS. */
Index: config/tc-mcore.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mcore.c,v
retrieving revision 1.41
diff -u -p -r1.41 tc-mcore.c
--- config/tc-mcore.c 7 Jun 2006 11:27:57 -0000 1.41
+++ config/tc-mcore.c 21 Nov 2006 22:59:37 -0000
@@ -411,8 +411,8 @@ const pseudo_typeS md_pseudo_table[] =
occupy can be taken into account when deciding whether or not to
dump the current literal pool.
XXX - currently we do not cope with the .space and .dcb.d directives.
*/
- { "ascii", mcore_stringer, 0 },
- { "asciz", mcore_stringer, 1 },
+ { "ascii", mcore_stringer, 8+0 },
+ { "asciz", mcore_stringer, 8+1 },
{ "byte", mcore_cons, 1 },
{ "dc", mcore_cons, 2 },
{ "dc.b", mcore_cons, 1 },
@@ -430,7 +430,7 @@ const pseudo_typeS md_pseudo_table[] =
{ "quad", mcore_cons, 8 },
{ "short", mcore_cons, 2 },
{ "single", mcore_float_cons, 'f'},
- { "string", mcore_stringer, 1 },
+ { "string", mcore_stringer, 8+1 },
{ "word", mcore_cons, 2 },
{ "fill", mcore_fill, 0 },
Index: config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.361
diff -u -p -r1.361 tc-mips.c
--- config/tc-mips.c 9 Nov 2006 13:04:39 -0000 1.361
+++ config/tc-mips.c 21 Nov 2006 22:59:38 -0000
@@ -1096,7 +1096,7 @@ static const pseudo_typeS mips_pseudo_ta
/* Relatively generic pseudo-ops that happen to be used on MIPS
chips. */
- {"asciiz", stringer, 1},
+ {"asciiz", stringer, 8+1},
{"bss", s_change_sec, 'b'},
{"err", s_err, 0},
{"half", s_cons, 1},
Index: config/tc-s390.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-s390.c,v
retrieving revision 1.49
diff -u -p -r1.49 tc-s390.c
--- config/tc-s390.c 7 Jun 2006 11:27:58 -0000 1.49
+++ config/tc-s390.c 21 Nov 2006 22:59:39 -0000
@@ -95,7 +95,7 @@ const pseudo_typeS md_pseudo_table[] =
{ "long", s390_elf_cons, 4 },
{ "quad", s390_elf_cons, 8 },
{ "ltorg", s390_literals, 0 },
- { "string", stringer, 2 },
+ { "string", stringer, 8+1 },
{ NULL, NULL, 0 }
};
Index: config/tc-spu.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-spu.c,v
retrieving revision 1.2
diff -u -p -r1.2 tc-spu.c
--- config/tc-spu.c 29 Oct 2006 18:18:34 -0000 1.2
+++ config/tc-spu.c 21 Nov 2006 22:59:39 -0000
@@ -89,7 +89,7 @@ const pseudo_typeS md_pseudo_table[] =
{"global", s_globl, 0},
{"half", cons, 2},
{"bss", s_lcomm_bytes, 1},
- {"string", stringer, 1},
+ {"string", stringer, 8+1},
{"word", cons, 4},
/* Force set to be treated as an instruction. */
{"set", NULL, 0},
Index: doc/as.texinfo
===================================================================
RCS file: /cvs/src/src/gas/doc/as.texinfo,v
retrieving revision 1.155
diff -u -p -r1.155 as.texinfo
--- doc/as.texinfo 3 Nov 2006 07:29:37 -0000 1.155
+++ doc/as.texinfo 21 Nov 2006 22:59:40 -0000
@@ -3759,7 +3759,7 @@ Some machine configurations provide addi
@menu
* Abort:: @code{.abort}
@ifset COFF
-* ABORT (COFF):: @code{.ABORT}
+* ABORT (COFF):: @code{.ABORT}
@end ifset
* Align:: @code{.align @var{abs-expr} ,
@var{abs-expr}}
@@ -3890,7 +3890,7 @@ Some machine configurations provide addi
* Stab:: @code{.stabd, .stabn, .stabs}
@end ifset
-* String:: @code{.string "@var{str}"}
+* String:: @code{.string | .string8 | .string16 | .string32 | .string64
"@var{str}"}
* Struct:: @code{.struct @var{expression}}
@ifset ELF
* SubSection:: @code{.subsection}
@@ -5873,16 +5873,38 @@ All five fields are specified.
@c end have-stabs
@node String
-@section @code{.string} "@var{str}"
+@section @code{.string | .string8 | .string16 | .string32 | .string64
"@var{str}"}
@cindex string, copying to object file
+@cindex string8, copying to object file
+@cindex string16, copying to object file
+@cindex string32, copying to object file
+@cindex string64, copying to object file
@cindex @code{string} directive
+@cindex @code{string8} directive
+@cindex @code{string16} directive
+@cindex @code{string32} directive
+@cindex @code{string64} directive
Copy the characters in @var{str} to the object file. You may specify more
than
one string to copy, separated by commas. Unless otherwise specified for a
particular machine, the assembler marks the end of each string with a 0
byte.
You can use any of the escape sequences described in
@ref{Strings,,Strings}.
+The variants @code{string16}, @code{string32} and @code{string64} differ
from
+the original @code{string} Pseudo Opcode in that way, that each (8 bit)
character
+from the @var{STR} string is copied and expanded to 16, 32 or 64bit
respectively.
+Each 16, 32 or 64bit value will then be copied in target endianess byte
order
+to the object file.
+
+Example:
+@smallexample
+ .string32 "BYE"
+expands to:
+ .string "B\0\0\0Y\0\0\0E\0\0\0" /* on little endian targets */
+ .string "\0\0\0B\0\0\0Y\0\0\0E" /* on big endian targets */
+@end smallexample
+
@node Struct
@section @code{.struct @var{expression}}
Index: testsuite/gas/all/gas.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/all/gas.exp,v
retrieving revision 1.41
diff -u -p -r1.41 gas.exp
--- testsuite/gas/all/gas.exp 20 Sep 2006 11:35:11 -0000 1.41
+++ testsuite/gas/all/gas.exp 21 Nov 2006 22:59:40 -0000
@@ -281,6 +281,8 @@ gas_test_error "weakref2.s" "" "e: would
gas_test_error "weakref3.s" "" "a: would close weakref loop: a => b => c =>
d => e => a"
gas_test_error "weakref4.s" "" "is already defined"
+run_dump_test string
+
load_lib gas-dg.exp
dg-init
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/err-*.s
$srcdir/$subdir/warn-*.s]] "" ""
--- ./testsuite/gas/all/string.d.org 2006-11-21 23:54:18.000000000 +0100
+++ ./testsuite/gas/all/string.d 2006-11-21 23:53:32.000000000 +0100
@@ -0,0 +1,13 @@
+#objdump : -s -j .data -j "\$DATA\$"
+#name : .strings tests
+
+.*: .*
+
+Contents of section (\.data|\$DATA\$):
+ 0000 73747238 00000000 00000000 00000000 str8.*
+ 0010 7374726e 65773800 00000000 00000000 strnew8.*
+ 0020 (73007400 72003100 36000000 00000000|00730074 00720031 00360000
00000000).*
+ 0030 (33000000 32000000 00000000 00000000|00000033 00000032 00000000
00000000).*
+ 0040 (36000000 00000000 34000000 00000000|00000000 00000036 00000000
00000034).*
+#pass
+
--- ./testsuite/gas/all/string.s.org 2006-11-21 23:54:21.000000000 +0100
+++ ./testsuite/gas/all/string.s 2006-11-21 23:01:41.000000000 +0100
@@ -0,0 +1,14 @@
+ .data
+ .string "str8"
+
+ .align 16
+ .string8 "strnew8"
+
+ .align 16
+ .string16 "str16"
+
+ .align 16
+ .string32 "32"
+
+ .align 16
+ .string64 "64"