asm: Use .asciz and .ascii instead of .string

We use the .string pseudo-op both in some of our test assembly files
and in our -Oasm output.  We expect this to emit a \0 terminated
string into the .o file.  However for certain targets (e.g. HP
PA-RISC) it doesn't include the \0.  Use .asciz instead, which
explicitly does what we want.

There's also one place we can use .ascii (which explicitly emits a
string *without* \0 termination) instead of multiple .byte directives.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Rob Herring 2021-07-27 12:30:19 -06:00 committed by David Gibson
parent 5eb5927d81
commit ff3a30c115
6 changed files with 75 additions and 77 deletions

23
dtc.h
View file

@ -116,6 +116,12 @@ enum markertype {
TYPE_UINT64, TYPE_UINT64,
TYPE_STRING, TYPE_STRING,
}; };
static inline bool is_type_marker(enum markertype type)
{
return type >= TYPE_UINT8;
}
extern const char *markername(enum markertype markertype); extern const char *markername(enum markertype markertype);
struct marker { struct marker {
@ -140,7 +146,22 @@ struct data {
for_each_marker(m) \ for_each_marker(m) \
if ((m)->type == (t)) if ((m)->type == (t))
size_t type_marker_length(struct marker *m); static inline struct marker *next_type_marker(struct marker *m)
{
for_each_marker(m)
if (is_type_marker(m->type))
break;
return m;
}
static inline size_t type_marker_length(struct marker *m)
{
struct marker *next = next_type_marker(m->next);
if (next)
return next->offset - m->offset;
return 0;
}
void data_free(struct data d); void data_free(struct data d);

View file

@ -134,9 +134,9 @@ static void asm_emit_string(void *e, const char *str, int len)
FILE *f = e; FILE *f = e;
if (len != 0) if (len != 0)
fprintf(f, "\t.string\t\"%.*s\"\n", len, str); fprintf(f, "\t.asciz\t\"%.*s\"\n", len, str);
else else
fprintf(f, "\t.string\t\"%s\"\n", str); fprintf(f, "\t.asciz\t\"%s\"\n", str);
} }
static void asm_emit_align(void *e, int a) static void asm_emit_align(void *e, int a)
@ -438,7 +438,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)
while (p < (strbuf.val + strbuf.len)) { while (p < (strbuf.val + strbuf.len)) {
len = strlen(p); len = strlen(p);
fprintf(f, "\t.string \"%s\"\n", p); fprintf(f, "\t.asciz \"%s\"\n", p);
p += len+1; p += len+1;
} }
} }

View file

@ -32,7 +32,7 @@ _dt_reserve_map:
dt_struct_start: dt_struct_start:
_dt_struct_start: _dt_struct_start:
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "" .asciz ""
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0xa .long 0xa
@ -58,7 +58,7 @@ _dt_struct_start:
.long 0x2 .long 0x2
.balign 4 .balign 4
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "memory@0" .asciz "memory@0"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0x7 .long 0x7
@ -77,7 +77,7 @@ _dt_struct_start:
.balign 4 .balign 4
.long OF_DT_END_NODE .long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "cpus" .asciz "cpus"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0x4 .long 0x4
@ -151,22 +151,22 @@ _dt_struct_end:
.globl dt_strings_start .globl dt_strings_start
dt_strings_start: dt_strings_start:
_dt_strings_start: _dt_strings_start:
.string "model" .asciz "model"
.string "compatible" .asciz "compatible"
.string "#address-cells" .asciz "#address-cells"
.string "#size-cells" .asciz "#size-cells"
.string "device_type" .asciz "device_type"
.string "reg" .asciz "reg"
.string "d10" .asciz "d10"
.string "d23" .asciz "d23"
.string "b101" .asciz "b101"
.string "o17" .asciz "o17"
.string "hd00d" .asciz "hd00d"
.string "stuff" .asciz "stuff"
.string "bad-d-1" .asciz "bad-d-1"
.string "bad-d-2" .asciz "bad-d-2"
.string "bad-o-1" .asciz "bad-o-1"
.string "bad-o-2" .asciz "bad-o-2"
.globl dt_strings_end .globl dt_strings_end
dt_strings_end: dt_strings_end:
_dt_strings_end: _dt_strings_end:

View file

@ -44,7 +44,7 @@ _dt_reserve_map:
dt_struct_start: dt_struct_start:
_dt_struct_start: _dt_struct_start:
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "" .asciz ""
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0xc .long 0xc
@ -76,7 +76,7 @@ _dt_struct_start:
.long 0x2 .long 0x2
.balign 4 .balign 4
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "cpus" .asciz "cpus"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0x4 .long 0x4
@ -94,7 +94,7 @@ _dt_struct_start:
.long 0x0 .long 0x0
.balign 4 .balign 4
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "PowerPC,970@0" .asciz "PowerPC,970@0"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0xc .long 0xc
@ -139,7 +139,7 @@ _dt_struct_start:
.balign 4 .balign 4
.long OF_DT_END_NODE .long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "PowerPC,970@1" .asciz "PowerPC,970@1"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0xc .long 0xc
@ -181,7 +181,7 @@ _dt_struct_start:
.long OF_DT_END_NODE .long OF_DT_END_NODE
.long OF_DT_END_NODE .long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "randomnode" .asciz "randomnode"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0x13 .long 0x13
@ -216,7 +216,7 @@ _dt_struct_start:
.balign 4 .balign 4
.long OF_DT_END_NODE .long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "memory@0" .asciz "memory@0"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0x7 .long 0x7
@ -242,7 +242,7 @@ memreg:
.balign 4 .balign 4
.long OF_DT_END_NODE .long OF_DT_END_NODE
.long OF_DT_BEGIN_NODE .long OF_DT_BEGIN_NODE
.string "chosen" .asciz "chosen"
.balign 4 .balign 4
.long OF_DT_PROP .long OF_DT_PROP
.long 0xf .long 0xf
@ -267,25 +267,25 @@ _dt_struct_end:
.globl dt_strings_start .globl dt_strings_start
dt_strings_start: dt_strings_start:
_dt_strings_start: _dt_strings_start:
.string "model" .asciz "model"
.string "compatible" .asciz "compatible"
.string "#address-cells" .asciz "#address-cells"
.string "#size-cells" .asciz "#size-cells"
.string "linux,phandle" .asciz "linux,phandle"
.string "name" .asciz "name"
.string "device_type" .asciz "device_type"
.string "reg" .asciz "reg"
.string "clock-frequency" .asciz "clock-frequency"
.string "timebase-frequency" .asciz "timebase-frequency"
.string "linux,boot-cpu" .asciz "linux,boot-cpu"
.string "i-cache-size" .asciz "i-cache-size"
.string "d-cache-size" .asciz "d-cache-size"
.string "string" .asciz "string"
.string "blob" .asciz "blob"
.string "ref" .asciz "ref"
.string "mixed" .asciz "mixed"
.string "bootargs" .asciz "bootargs"
.string "linux,platform" .asciz "linux,platform"
.globl dt_strings_end .globl dt_strings_end
dt_strings_end: dt_strings_end:
_dt_strings_end: _dt_strings_end:

View file

@ -54,13 +54,13 @@ tree##_rsvmap_end: ;
#define PROP_STR(tree, name, str) \ #define PROP_STR(tree, name, str) \
PROPHDR(tree, name, 55f - 54f) \ PROPHDR(tree, name, 55f - 54f) \
54: \ 54: \
.string str ; \ .asciz str ; \
55: \ 55: \
.balign 4 ; .balign 4 ;
#define BEGIN_NODE(name) \ #define BEGIN_NODE(name) \
FDTLONG(FDT_BEGIN_NODE) ; \ FDTLONG(FDT_BEGIN_NODE) ; \
.string name ; \ .asciz name ; \
.balign 4 ; .balign 4 ;
#define END_NODE \ #define END_NODE \
@ -68,7 +68,7 @@ tree##_rsvmap_end: ;
#define STRING(tree, name, str) \ #define STRING(tree, name, str) \
tree##_##name: ; \ tree##_##name: ; \
.string str ; .asciz str ;
.data .data
@ -253,9 +253,7 @@ truncated_string_struct_end:
truncated_string_strings: truncated_string_strings:
STRING(truncated_string, good_string, "good") STRING(truncated_string, good_string, "good")
truncated_string_bad_string: truncated_string_bad_string:
.byte 'b' .ascii "bad"
.byte 'a'
.byte 'd'
/* NOTE: terminating \0 deliberately missing */ /* NOTE: terminating \0 deliberately missing */
truncated_string_strings_end: truncated_string_strings_end:
truncated_string_end: truncated_string_end:

View file

@ -124,27 +124,6 @@ static void write_propval_int(FILE *f, const char *p, size_t len, size_t width)
} }
} }
static bool has_data_type_information(struct marker *m)
{
return m->type >= TYPE_UINT8;
}
static struct marker *next_type_marker(struct marker *m)
{
while (m && !has_data_type_information(m))
m = m->next;
return m;
}
size_t type_marker_length(struct marker *m)
{
struct marker *next = next_type_marker(m->next);
if (next)
return next->offset - m->offset;
return 0;
}
static const char *delim_start[] = { static const char *delim_start[] = {
[TYPE_UINT8] = "[", [TYPE_UINT8] = "[",
[TYPE_UINT16] = "/bits/ 16 <", [TYPE_UINT16] = "/bits/ 16 <",
@ -230,7 +209,7 @@ static void write_propval(FILE *f, struct property *prop)
size_t data_len = type_marker_length(m) ? : len - m->offset; size_t data_len = type_marker_length(m) ? : len - m->offset;
const char *p = &prop->val.val[m->offset]; const char *p = &prop->val.val[m->offset];
if (has_data_type_information(m)) { if (is_type_marker(m->type)) {
emit_type = m->type; emit_type = m->type;
fprintf(f, " %s", delim_start[emit_type]); fprintf(f, " %s", delim_start[emit_type]);
} else if (m->type == LABEL) } else if (m->type == LABEL)