public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4 0/6] ASCIZ Command for output section
@ 2023-02-13 16:20 binutils
  2023-02-13 16:20 ` [PATCH v4 1/6] Document the ASCIZ command binutils
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: binutils @ 2023-02-13 16:20 UTC (permalink / raw)
  To: binutils; +Cc: nickc

Introduce an ASCIZ command for an output section
When generating a header for an embedded system
there is often a need to add text information.

There are arguments for generating the header in the linker
instead of compiling the header as part of the program.
The lack of support for strings makes this process a bit unwieldy.

The ASCIZ command allows you to specify a zero-terminated string as a parameter.

Example:

    ASCIZ "This is a string"

The string contains 16 characters, but a NUL character is added to the end,
so the areas reserved is 16+1 = 17 characters.

The string may contain '\n', '\r', '\t' and octals, but not hex characters.

Ideally, there should be a command which reserves a fixed size area.

I:E:

    ASCII 20, "This is a string"

but I have failed to get make this work in 'ld',
so this patch series is limited to ASCIZ.

[PATCH v4 1/6] Document the ASCIZ command
[PATCH v4 2/6] Add ASCIZ to NEWS
[PATCH v4 3/6] Add ASCIZ to testsuite
[PATCH v4 4/6] ldlex.l: Add ASCIZ token
[PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command
[PATCH v4 6/6] Parse ASCIZ command


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 1/6] Document the ASCIZ command
  2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
@ 2023-02-13 16:20 ` binutils
  2023-02-13 16:20 ` [PATCH v4 2/6] Add ASCIZ to NEWS binutils
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: binutils @ 2023-02-13 16:20 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ld.texi | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/ld/ld.texi b/ld/ld.texi
index 36005dc2b0d..0a3d4adfaa0 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -5308,6 +5308,7 @@ C identifiers because they contain a @samp{.} character.
 @cindex data
 @cindex section data
 @cindex output section data
+@kindex ASCIZ @var{string}
 @kindex BYTE(@var{expression})
 @kindex SHORT(@var{expression})
 @kindex LONG(@var{expression})
@@ -5338,6 +5339,16 @@ target are 32 bits, an expression is computed as 32 bits.  In this case
 @code{QUAD} stores a 32 bit value zero extended to 64 bits, and
 @code{SQUAD} stores a 32 bit value sign extended to 64 bits.
 
+You can include a zero-terminated string in an output section by using
+@code{ASCIZ} as an output section command. The keyword is followed by a string
+which is stored at the current value of the location counter adding a zero byte
+at the end.
+
+For example, this string of 16 characters will create a 17 byte area
+@smallexample
+ASCIZ     "This is 16 bytes"
+@end smallexample
+
 If the object file format of the output file has an explicit endianness,
 which is the normal case, the value will be stored in that endianness.
 When the object file format does not have an explicit endianness, as is
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 2/6] Add ASCIZ to NEWS
  2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
  2023-02-13 16:20 ` [PATCH v4 1/6] Document the ASCIZ command binutils
@ 2023-02-13 16:20 ` binutils
  2023-02-13 16:20 ` [PATCH v4 3/6] Add ASCIZ to testsuite binutils
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: binutils @ 2023-02-13 16:20 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <binutils@emagii.com>

Signed-off-by: Ulf Samuelsson <binutils@emagii.com>
---
 ld/NEWS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ld/NEWS b/ld/NEWS
index 9982ad0168d..f5a1f1a1304 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,11 @@
 -*- text -*-
 
+* The linker has a new command for output sections.
+  ASCIZ "string"
+  This will insert the string at the current location adding a zero at the end.
+  The string may contain '\n', '\r', '\t' and octal numbers.
+  Hex numbers are not supported
+
 Changes in 2.40:
 
 * The linker has a new command line option to suppress the generation of any
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 3/6] Add ASCIZ to testsuite
  2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
  2023-02-13 16:20 ` [PATCH v4 1/6] Document the ASCIZ command binutils
  2023-02-13 16:20 ` [PATCH v4 2/6] Add ASCIZ to NEWS binutils
@ 2023-02-13 16:20 ` binutils
  2023-02-13 16:20 ` [PATCH v4 4/6] ldlex.l: Add ASCIZ token binutils
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: binutils @ 2023-02-13 16:20 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <binutils@emagii.com>

Signed-off-by: Ulf Samuelsson <binutils@emagii.com>
---
 ld/testsuite/ld-scripts/asciz.d | 14 ++++++++++++++
 ld/testsuite/ld-scripts/asciz.s |  6 ++++++
 ld/testsuite/ld-scripts/asciz.t | 23 +++++++++++++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 ld/testsuite/ld-scripts/asciz.d
 create mode 100644 ld/testsuite/ld-scripts/asciz.s
 create mode 100644 ld/testsuite/ld-scripts/asciz.t

diff --git a/ld/testsuite/ld-scripts/asciz.d b/ld/testsuite/ld-scripts/asciz.d
new file mode 100644
index 00000000000..83cb61d6fb6
--- /dev/null
+++ b/ld/testsuite/ld-scripts/asciz.d
@@ -0,0 +1,14 @@
+#source: asciz.s
+#ld: -T asciz.t
+#objdump: -s -j .text
+#notarget: [is_aout_format]
+#xfail: tic4x-*-* tic54x-*-*
+
+.*:     file format .*
+
+Contents of section .text:
+ 10c0 434f4445 54686973 20697320 61207374  CODEThis is a st
+ 10d0 72696e67 00000000 00000000 00000000  ring............
+ 10e0 54686973 20697320 616e6f74 68657220  This is another 
+ 10f0 73747269 6e6700                      string.
+#pass
diff --git a/ld/testsuite/ld-scripts/asciz.s b/ld/testsuite/ld-scripts/asciz.s
new file mode 100644
index 00000000000..542dcd1a410
--- /dev/null
+++ b/ld/testsuite/ld-scripts/asciz.s
@@ -0,0 +1,6 @@
+	.section .text
+	.long 0x45444F43
+	.section .data
+	.long 0x9abcdef0
+	.section .bss
+	.long 0
diff --git a/ld/testsuite/ld-scripts/asciz.t b/ld/testsuite/ld-scripts/asciz.t
new file mode 100644
index 00000000000..986e00a1169
--- /dev/null
+++ b/ld/testsuite/ld-scripts/asciz.t
@@ -0,0 +1,23 @@
+MEMORY {
+  rom : ORIGIN = 0x00000, LENGTH = 0x10000
+  ram : ORIGIN = 0x10000, LENGTH = 0x10000
+}
+
+_start = 0x000000;
+SECTIONS
+{
+  . = 0x1000 + SIZEOF_HEADERS;
+  .text ALIGN (0x20) :
+    {
+      *(.text)
+      ASCIZ "This is a string"
+      . = ALIGN(0x20);
+      align_label = .;
+      ASCIZ "This is another string"
+      unalign_label = .;
+    }
+  .data : AT (0x10000) { *(.data) } >ram /* NO default AT>rom */
+  . = ALIGN(0x20);
+  .bss : { *(.bss) } >ram /* NO default AT>rom */
+  /DISCARD/ : { *(*) }
+}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 4/6] ldlex.l: Add ASCIZ token
  2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
                   ` (2 preceding siblings ...)
  2023-02-13 16:20 ` [PATCH v4 3/6] Add ASCIZ to testsuite binutils
@ 2023-02-13 16:20 ` binutils
  2023-02-13 16:20 ` [PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command binutils
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: binutils @ 2023-02-13 16:20 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldlex.l | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ld/ldlex.l b/ld/ldlex.l
index cf596530b20..32336cf0be2 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -309,6 +309,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 <WILD>"LONG"				{ RTOKEN(LONG); }
 <WILD>"SHORT"				{ RTOKEN(SHORT); }
 <WILD>"BYTE"				{ RTOKEN(BYTE); }
+<WILD>"ASCIZ"				{ RTOKEN(ASCIZ); }
 <SCRIPT>"NOFLOAT"			{ RTOKEN(NOFLOAT); }
 <SCRIPT,EXPRESSION>"NOCROSSREFS"	{ RTOKEN(NOCROSSREFS); }
 <SCRIPT,EXPRESSION>"NOCROSSREFS_TO"	{ RTOKEN(NOCROSSREFS_TO); }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command
  2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
                   ` (3 preceding siblings ...)
  2023-02-13 16:20 ` [PATCH v4 4/6] ldlex.l: Add ASCIZ token binutils
@ 2023-02-13 16:20 ` binutils
  2023-02-13 16:24 ` [PATCH v4 0/6] ASCIZ Command for output section Ulf Samuelsson
  2023-02-14 10:16 ` Nick Clifton
  6 siblings, 0 replies; 10+ messages in thread
From: binutils @ 2023-02-13 16:20 UTC (permalink / raw)
  To: binutils; +Cc: nickc, Ulf Samuelsson

From: Ulf Samuelsson <ulf@emagii.com>

Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
---
 ld/ldgram.y | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/ld/ldgram.y b/ld/ldgram.y
index fa5f01fef1d..67e75d43067 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -125,7 +125,7 @@ static int error_index;
 %right UNARY
 %token END
 %left <token> '('
-%token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE
+%token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE ASCIZ
 %token SECTIONS PHDRS INSERT_K AFTER BEFORE
 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
 %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
@@ -668,7 +668,10 @@ statement:
 		{
 		  lang_add_data ((int) $1, $3);
 		}
-
+	| ASCIZ NAME
+		{
+		  lang_add_stringz($2);
+		}
 	| FILL '(' fill_exp ')'
 		{
 		  lang_add_fill ($3);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/6] ASCIZ Command for output section
  2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
                   ` (4 preceding siblings ...)
  2023-02-13 16:20 ` [PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command binutils
@ 2023-02-13 16:24 ` Ulf Samuelsson
  2023-02-14 10:16 ` Nick Clifton
  6 siblings, 0 replies; 10+ messages in thread
From: Ulf Samuelsson @ 2023-02-13 16:24 UTC (permalink / raw)
  To: binutils; +Cc: nickc

Looks like I reached the mail limit PATCH V4 6/6 changed V3 like this:

-        int value = c;
+        int value = c - '0';

Best Regards
Ulf Samuelsson

Den 2023-02-13 kl. 17:20, skrev Ulf Samuelsson via Binutils:
> Introduce an ASCIZ command for an output section
> When generating a header for an embedded system
> there is often a need to add text information.
>
> There are arguments for generating the header in the linker
> instead of compiling the header as part of the program.
> The lack of support for strings makes this process a bit unwieldy.
>
> The ASCIZ command allows you to specify a zero-terminated string as a parameter.
>
> Example:
>
>      ASCIZ "This is a string"
>
> The string contains 16 characters, but a NUL character is added to the end,
> so the areas reserved is 16+1 = 17 characters.
>
> The string may contain '\n', '\r', '\t' and octals, but not hex characters.
>
> Ideally, there should be a command which reserves a fixed size area.
>
> I:E:
>
>      ASCII 20, "This is a string"
>
> but I have failed to get make this work in 'ld',
> so this patch series is limited to ASCIZ.
>
> [PATCH v4 1/6] Document the ASCIZ command
> [PATCH v4 2/6] Add ASCIZ to NEWS
> [PATCH v4 3/6] Add ASCIZ to testsuite
> [PATCH v4 4/6] ldlex.l: Add ASCIZ token
> [PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command
> [PATCH v4 6/6] Parse ASCIZ command
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/6] ASCIZ Command for output section
  2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
                   ` (5 preceding siblings ...)
  2023-02-13 16:24 ` [PATCH v4 0/6] ASCIZ Command for output section Ulf Samuelsson
@ 2023-02-14 10:16 ` Nick Clifton
  2023-02-14 16:07   ` Ulf Samuelsson
  6 siblings, 1 reply; 10+ messages in thread
From: Nick Clifton @ 2023-02-14 10:16 UTC (permalink / raw)
  To: binutils, binutils

Hi Ulf,

> Introduce an ASCIZ command for an output section
> When generating a header for an embedded system
> there is often a need to add text information.

Thanks for contributing this patch series.  I have applied
the patches with a few minor tweaks - mostly to the new
test case so that it did not cause new failures on targets
which pad code to an alignment greater than 4 bytes.

Cheers
   Nick



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/6] ASCIZ Command for output section
  2023-02-14 10:16 ` Nick Clifton
@ 2023-02-14 16:07   ` Ulf Samuelsson
  2023-02-14 16:20     ` Nick Clifton
  0 siblings, 1 reply; 10+ messages in thread
From: Ulf Samuelsson @ 2023-02-14 16:07 UTC (permalink / raw)
  To: Nick Clifton, binutils

Thank You.

I will start to try to implement the "ASCII" command as well.

ASCII <length> , <string>

I had some problems with getting syntax errors on this so I think
I will send in a preliminary patchset and see if anyone can spot an 
obvious error.


One question:
    The lang_add_string contains an error message if the string does not 
fit into the allocated area.
    This will never get triggered by the ASCIZ command, since that will 
allocate the size of the string.
    If you specify a size to the ASCII command and then provide a longer 
string it will trigger.

    There are no translations for the string at the moment.

    Will the linker output the English string, or what?

    What is the procedure to get a translation?
    I can provide a Swedish translation at the least.

Best Regards
Ulf Samuelsson

Den 2023-02-14 kl. 11:16, skrev Nick Clifton:
> Hi Ulf,
>
>> Introduce an ASCIZ command for an output section
>> When generating a header for an embedded system
>> there is often a need to add text information.
>
> Thanks for contributing this patch series.  I have applied
> the patches with a few minor tweaks - mostly to the new
> test case so that it did not cause new failures on targets
> which pad code to an alignment greater than 4 bytes.
>
> Cheers
>   Nick
>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 0/6] ASCIZ Command for output section
  2023-02-14 16:07   ` Ulf Samuelsson
@ 2023-02-14 16:20     ` Nick Clifton
  0 siblings, 0 replies; 10+ messages in thread
From: Nick Clifton @ 2023-02-14 16:20 UTC (permalink / raw)
  To: Ulf Samuelsson, binutils

Hi Ulf,

> One question:
>     The lang_add_string contains an error message if the string does not fit into the allocated area.
>     This will never get triggered by the ASCIZ command, since that will allocate the size of the string.
>     If you specify a size to the ASCII command and then provide a longer string it will trigger.

Ah - you know that I mentioned that I had tidied up the code
a little bit ?  Well the other area I tidied was the lang_add_string
function.  I simplified it, removed the redundant size checking code
and string padding code, and changed the stacked if-statements into
a simpler switch-statement...

So currently there are no messages that need translation,


>   There are no translations for the string at the moment. 
>    Will the linker output the English string, or what?

If a translation for a specific string is not available then it will
just be displayed as-is.  So in this case the English version will be
used.


>     What is the procedure to get a translation?

The hard way:

   Create a new ld/po/ld.pot file and send it to the Translation Project
   with a request for new translations:
     https://translationproject.org/html/maintainers.html

The easy way:

   Wait for the next official release of the binutils.  As part of
   the process for creating a release I take care of asking the Translation
   Project to update the translation files.

   Note - this does not mean that new translations will be created
   for all supported languages.  The translation project runs on a
   volunteer basis and it is up the the volunteers to find time to
   create new translations and/or update old translations.


>     I can provide a Swedish translation at the least.

If you would like to volunteer some time to the Translation Project
I am sure that they would love to hear from you.

Cheers
   Nick



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-02-14 16:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13 16:20 [PATCH v4 0/6] ASCIZ Command for output section binutils
2023-02-13 16:20 ` [PATCH v4 1/6] Document the ASCIZ command binutils
2023-02-13 16:20 ` [PATCH v4 2/6] Add ASCIZ to NEWS binutils
2023-02-13 16:20 ` [PATCH v4 3/6] Add ASCIZ to testsuite binutils
2023-02-13 16:20 ` [PATCH v4 4/6] ldlex.l: Add ASCIZ token binutils
2023-02-13 16:20 ` [PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command binutils
2023-02-13 16:24 ` [PATCH v4 0/6] ASCIZ Command for output section Ulf Samuelsson
2023-02-14 10:16 ` Nick Clifton
2023-02-14 16:07   ` Ulf Samuelsson
2023-02-14 16:20     ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).