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

Message ID 20240708150422.4926-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, 3:04 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(-)
  

Comments

Jens Remus July 8, 2024, 4:22 p.m. UTC | #1
Am 08.07.2024 um 17:04 schrieb binutils@emagii.com:
> 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(-)
> 
> 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

Nit: Use a tab instead of the 8 spaces for indentation.

> +		{
> +		  /* '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 ')'
>   		{

Regards,
Jens
  

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 ')'
 		{