[v2,2/7] ldgram.y: Add ASCII parsing

Message ID 20240705162248.24954-3-binutils@emagii.com
State New
Headers
Series ASCII output section command |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Build failed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Build failed

Commit Message

Ulf Samuelsson July 5, 2024, 4:22 p.m. UTC
  From: Ulf Samuelsson <ulf@emagii.com>

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

Patch

diff --git a/ld/ldgram.y b/ld/ldgram.y
index 7c04025f526..1d6965ff49d 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -128,7 +128,7 @@  static void yyerror (const char *);
 %right UNARY
 %token END
 %left <token> '('
-%token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE ASCIZ
+%token <token> ALIGN_K BLOCK BIND QUAD SQUAD LONG SHORT BYTE ASCII ASCIZ
 %token SECTIONS PHDRS INSERT_K AFTER BEFORE LINKER_VERSION
 %token DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END DATA_SEGMENT_END
 %token SORT_BY_NAME SORT_BY_ALIGNMENT SORT_NONE
@@ -703,9 +703,18 @@  statement:
 		{
 		  lang_add_data ((int) $1, $3);
 		}
+        | ASCII mustbe_exp ',' NAME
+		{
+		  /* 'value' is a memory leak, do we care?  */
+		  etree_type *value = $2;
+		  if (value->type.node_code == INT)
+		    lang_add_string (value->value.value, $4);
+		  else
+		    einfo (_("%X%P:%pS: ASCII expression must be an integer\n"), NULL);
+		}
 	| ASCIZ NAME
 		{
-		  lang_add_string ($2);
+		  lang_add_string (0, $2);
 		}
 	| FILL '(' fill_exp ')'
 		{