varasm: Fix up constpool alias handling [PR99872]

Message ID 20210407071655.GR1179226@tucnak
State New
Headers show
Series
  • varasm: Fix up constpool alias handling [PR99872]
Related show

Commit Message

Iain Buclaw via Gcc-patches April 7, 2021, 7:16 a.m.
Hi!

Last year, I have added in r11-2944-g0106300f6c3f7bae5eb1c46dbd45aa07c94e1b15
(aka PR54201 fix) code to find bitwise duplicates in constant pool and output
them as aliases instead of duplicating the data.

Unfortunately this broke mingw32 -m32.
On most targets, ASM_GENERATE_INTERNAL_LABEL with "LC" emits something like
*.LC123 and the targets don't add user label prefixes, so the aliases
that we print should be something like
	.set	.LC5, .LC6
or
	.set	.LC5, .LC6 + 8
and I wasn't sure if ASM_OUTPUT_DEF can handle the * and therefore I have
stripped it.
But, on mingw32 -m32, ASM_GENERATE_INTERNAL_LABEL with "LC" emits
*LC123 and the target has user label prefixes, which means what I wrote
results in
LC6:
	...
	.set	_LC5, _LC6
which results in unresolved symbols.  I went through the ASM_OUTPUT_DEF
definitions of all targets and all of them use assemble_name twice under
the hood (with various differences on what they print before, in between or
after those names).  And assemble_name handles the name encoding properly,
so if we pass it ASM_OUTPUT_DEF (..., "*.LC123", "*.LC456+16") it will
emit .LC123 and .LC456+16 and if we pass it "*LC789", it will emit
LC789.

Bootstrapped/regtested on x86_64-linux and i686-linux and Jonathan said in
the PR he has tested it on mingw32.

Ok for trunk?

2021-04-07  Jakub Jelinek  <jakub@redhat.com>

	PR target/99872
	* varasm.c (output_constant_pool_contents): Don't strip name encoding
	from XSTR (desc->sym, 0) or from label before passing those to
	ASM_OUTPUT_DEF.


	Jakub

Comments

Richard Biener April 7, 2021, 1:33 p.m. | #1
On Wed, 7 Apr 2021, Jakub Jelinek wrote:

> Hi!

> 

> Last year, I have added in r11-2944-g0106300f6c3f7bae5eb1c46dbd45aa07c94e1b15

> (aka PR54201 fix) code to find bitwise duplicates in constant pool and output

> them as aliases instead of duplicating the data.

> 

> Unfortunately this broke mingw32 -m32.

> On most targets, ASM_GENERATE_INTERNAL_LABEL with "LC" emits something like

> *.LC123 and the targets don't add user label prefixes, so the aliases

> that we print should be something like

> 	.set	.LC5, .LC6

> or

> 	.set	.LC5, .LC6 + 8

> and I wasn't sure if ASM_OUTPUT_DEF can handle the * and therefore I have

> stripped it.

> But, on mingw32 -m32, ASM_GENERATE_INTERNAL_LABEL with "LC" emits

> *LC123 and the target has user label prefixes, which means what I wrote

> results in

> LC6:

> 	...

> 	.set	_LC5, _LC6

> which results in unresolved symbols.  I went through the ASM_OUTPUT_DEF

> definitions of all targets and all of them use assemble_name twice under

> the hood (with various differences on what they print before, in between or

> after those names).  And assemble_name handles the name encoding properly,

> so if we pass it ASM_OUTPUT_DEF (..., "*.LC123", "*.LC456+16") it will

> emit .LC123 and .LC456+16 and if we pass it "*LC789", it will emit

> LC789.

> 

> Bootstrapped/regtested on x86_64-linux and i686-linux and Jonathan said in

> the PR he has tested it on mingw32.

> 

> Ok for trunk?


OK.

Thanks.
Richard.

> 2021-04-07  Jakub Jelinek  <jakub@redhat.com>

> 

> 	PR target/99872

> 	* varasm.c (output_constant_pool_contents): Don't strip name encoding

> 	from XSTR (desc->sym, 0) or from label before passing those to

> 	ASM_OUTPUT_DEF.

> 

> --- gcc/varasm.c.jj	2021-02-19 12:14:11.082112515 +0100

> +++ gcc/varasm.c	2021-04-06 13:26:21.708116790 +0200

> @@ -4290,13 +4290,13 @@ output_constant_pool_contents (struct rt

>      if (desc->mark < 0)

>        {

>  #ifdef ASM_OUTPUT_DEF

> -	const char *name = targetm.strip_name_encoding (XSTR (desc->sym, 0));

> +	const char *name = XSTR (desc->sym, 0);

>  	char label[256];

>  	char buffer[256 + 32];

>  	const char *p;

>  

>  	ASM_GENERATE_INTERNAL_LABEL (label, "LC", ~desc->mark);

> -	p = targetm.strip_name_encoding (label);

> +	p = label;

>  	if (desc->offset)

>  	  {

>  	    sprintf (buffer, "%s+%ld", p, (long) (desc->offset));

> 

> 	Jakub

> 

> 


-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Patch

--- gcc/varasm.c.jj	2021-02-19 12:14:11.082112515 +0100
+++ gcc/varasm.c	2021-04-06 13:26:21.708116790 +0200
@@ -4290,13 +4290,13 @@  output_constant_pool_contents (struct rt
     if (desc->mark < 0)
       {
 #ifdef ASM_OUTPUT_DEF
-	const char *name = targetm.strip_name_encoding (XSTR (desc->sym, 0));
+	const char *name = XSTR (desc->sym, 0);
 	char label[256];
 	char buffer[256 + 32];
 	const char *p;
 
 	ASM_GENERATE_INTERNAL_LABEL (label, "LC", ~desc->mark);
-	p = targetm.strip_name_encoding (label);
+	p = label;
 	if (desc->offset)
 	  {
 	    sprintf (buffer, "%s+%ld", p, (long) (desc->offset));