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

Message ID 20240708174929.15137-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 8, 2024, 5:49 p.m. UTC
  From: Ulf Samuelsson <ulf@emagii.com>

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

Patch

diff --git a/ld/ldgram.y b/ld/ldgram.y
index 7c04025f526..a6255969857 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 ')'
 		{
@@ -1175,10 +1184,10 @@  type:
 	|  COPY    { sectype = noalloc_section; }
 	|  INFO    { sectype = noalloc_section; }
 	|  OVERLAY { sectype = noalloc_section; }
-        |  READONLY '(' TYPE '=' exp ')' { sectype = typed_readonly_section; sectype_value = $5; }
+	|  READONLY '(' TYPE '=' exp ')' { sectype = typed_readonly_section; sectype_value = $5; }
 	|  READONLY { sectype = readonly_section; }
 	|  TYPE '=' exp { sectype = type_section; sectype_value = $3; }
-        ;
+	;
 
 atype:
 		'(' type ')'