Bug 86984 - invalid relocation accessing a const char array
Summary: invalid relocation accessing a const char array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 84184 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-08-16 23:10 UTC by Martin Sebor
Modified: 2019-05-06 09:40 UTC (History)
6 users (show)

See Also:
Host:
Target: alpha-linux
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Reduced test case. (892 bytes, text/plain)
2018-08-16 23:14 UTC, Martin Sebor
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2018-08-16 23:10:58 UTC
As discussed here https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00839.html, the Alpha back end seems to emit invalid relocations for accesses to constant arrays in some cases, causing Glibc build failures.  This must have been latent a bug that was triggered by the transformation of braced array initializers to STRING_CSTs in r263511 as the same issue can be reproduced by replacing the initializer with a string literal in the test case.
Comment 1 Martin Sebor 2018-08-16 23:14:09 UTC
Created attachment 44552 [details]
Reduced test case.

Compiling the attached test case shows the invalid offsets in the assembly:

$ gcc -S -O2 -Wall -Wwrite-strings -Werror -fmerge-all-constants -fno-stack-protector -mieee plural.c -o/dev/stdout | grep gprelhigh

	ldah $1,yypgoto+2305843009213693936($29)		!gprelhigh
	ldah $1,yypact($29)		!gprelhigh
	ldah $1,yytable($29)		!gprelhigh
	ldah $1,yydefact($29)		!gprelhigh
	ldah $2,yyr2($29)		!gprelhigh
	ldah $15,yyr1($29)		!gprelhigh
	ldah $1,yypgoto($29)		!gprelhigh
	ldah $5,yycheck($29)		!gprelhigh
	ldah $1,yydefgoto($29)		!gprelhigh
	ldah $2,yypgoto+2305843009213693936($29)		!gprelhigh
	ldah $2,yytable($29)		!gprelhigh
Comment 2 Martin Sebor 2018-08-16 23:19:10 UTC
The excessive offset appears in the first RTL dump:

$ grep -A3 -B3  2305843009213693936 plural.c.230r.expand
(insn 87 86 88 10 (set (reg:DI 154)
        (lshiftrt:DI (reg:DI 155)
            (const_int 3 [0x3]))) -1
     (expr_list:REG_EQUAL (const_int 2305843009213693936 [0x1ffffffffffffff0])
        (nil)))
(insn 88 87 89 10 (set (reg/f:DI 152)
        (plus:DI (reg:DI 153)
Comment 3 Jeffrey A. Law 2018-08-20 14:21:31 UTC
Author: law
Date: Mon Aug 20 14:20:59 2018
New Revision: 263664

URL: https://gcc.gnu.org/viewcvs?rev=263664&root=gcc&view=rev
Log:
	PR target/86984
	* expr.c (expand_assignment): Assert that bitpos is positive.
	(store_field): Likewise
	(expand_expr_real_1): Make sure that bitpos is positive.
	* config/alpha/alpha.h (CONSTANT_ADDRESS_P): Avoid signed
	integer overflow.

	PR target/86984
	* gcc.target/alpha/pr86984.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/alpha/pr86984.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/alpha/alpha.h
    trunk/gcc/expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Eric Botcazou 2018-08-20 15:05:10 UTC
*** Bug 84184 has been marked as a duplicate of this bug. ***
Comment 5 Richard Biener 2018-08-22 08:42:02 UTC
Fixed I assume.
Comment 6 John Paul Adrian Glaubitz 2019-04-29 10:51:26 UTC
Is there a chance this can get backported to the gcc-8 branch?
Comment 7 Richard Biener 2019-05-03 08:19:20 UTC
Author: rguenth
Date: Fri May  3 08:18:48 2019
New Revision: 270841

URL: https://gcc.gnu.org/viewcvs?rev=270841&root=gcc&view=rev
Log:
2019-05-03  Richard Biener  <rguenther@suse.de>

	Backport from mainline
	2019-03-14  Richard Biener  <rguenther@suse.de>

	PR middle-end/89698
	* fold-const.c (operand_equal_p): For INDIRECT_REF check
	that the access types are similar.

	* g++.dg/torture/pr89698.C: New testcase.

	2019-03-07  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/89595
	* tree-ssa-dom.c (dom_opt_dom_walker::optimize_stmt): Take
	stmt iterator as reference, take boolean output parameter to
	indicate whether the stmt was removed and thus the iterator
	already advanced.
	(dom_opt_dom_walker::before_dom_children): Re-iterate over
	stmts created by folding.

	* gcc.dg/torture/pr89595.c: New testcase.

	2019-03-14  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/89710
	* tree-ssa-loop-ch.c (should_duplicate_loop_header_p): Use
	safe_dyn_cast.

	* gcc.dg/torture/pr89710.c: New testcase.

	2019-04-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/90071
	* tree-ssa-reassoc.c (init_range_entry): Do not pick up
	abnormal operands from def stmts.

	* gcc.dg/torture/pr90071.c: New testcase.

	2018-08-20  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR target/86984
	* expr.c (expand_assignment): Assert that bitpos is positive.
	(store_field): Likewise
	(expand_expr_real_1): Make sure that bitpos is positive.
	* config/alpha/alpha.h (CONSTANT_ADDRESS_P): Avoid signed
	integer overflow.

	* gcc.target/alpha/pr86984.c: New test.

	2019-03-14  Richard Biener  <rguenther@suse.de>

	PR target/89711
	* config/i386/i386.c (make_resolver_func): Properly set
	DECL_CONTEXT on the RESULT_DECL.
	* config/rs6000/rs6000.c (make_resolver_func): Likewise.

Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/config/alpha/alpha.h
    branches/gcc-8-branch/gcc/config/i386/i386.c
    branches/gcc-8-branch/gcc/config/rs6000/rs6000.c
    branches/gcc-8-branch/gcc/expr.c
    branches/gcc-8-branch/gcc/fold-const.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
    branches/gcc-8-branch/gcc/tree-ssa-dom.c
    branches/gcc-8-branch/gcc/tree-ssa-loop-ch.c
    branches/gcc-8-branch/gcc/tree-ssa-reassoc.c
Comment 8 Richard Biener 2019-05-03 08:21:58 UTC
Backported to fix IA64 kernel miscompilation.
Comment 9 John Paul Adrian Glaubitz 2019-05-03 08:27:30 UTC
(In reply to Richard Biener from comment #8)
> Backported to fix IA64 kernel miscompilation.

Thanks a lot \o/
Comment 10 Richard Biener 2019-05-06 09:40:46 UTC
Author: rguenth
Date: Mon May  6 09:40:15 2019
New Revision: 270904

URL: https://gcc.gnu.org/viewcvs?rev=270904&root=gcc&view=rev
Log:
2019-05-03  Richard Biener  <rguenther@suse.de>

	Backport from mainline
	2019-03-14  Richard Biener  <rguenther@suse.de>

	PR middle-end/89698
	* fold-const.c (operand_equal_p): For INDIRECT_REF check
	that the access types are similar.

	* g++.dg/torture/pr89698.C: New testcase.

	2019-03-07  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/89595
	* tree-ssa-dom.c (dom_opt_dom_walker::optimize_stmt): Take
	stmt iterator as reference, take boolean output parameter to
	indicate whether the stmt was removed and thus the iterator
	already advanced.
	(dom_opt_dom_walker::before_dom_children): Re-iterate over
	stmts created by folding.

	* gcc.dg/torture/pr89595.c: New testcase.

	2019-03-14  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/89710
	* tree-ssa-loop-ch.c (should_duplicate_loop_header_p): Use
	safe_dyn_cast.

	* gcc.dg/torture/pr89710.c: New testcase.

	2019-04-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/90071
	* tree-ssa-reassoc.c (init_range_entry): Do not pick up
	abnormal operands from def stmts.

	* gcc.dg/torture/pr90071.c: New testcase.

	2018-08-20  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR target/86984
	* expr.c (expand_assignment): Assert that bitpos is positive.
	(store_field): Likewise
	(expand_expr_real_1): Make sure that bitpos is positive.
	* config/alpha/alpha.h (CONSTANT_ADDRESS_P): Avoid signed
	integer overflow.

	* gcc.target/alpha/pr86984.c: New test.

	2019-03-14  Richard Biener  <rguenther@suse.de>

	PR target/89711
	* config/i386/i386.c (make_resolver_func): Properly set
	DECL_CONTEXT on the RESULT_DECL.
	* config/rs6000/rs6000.c (make_resolver_func): Likewise.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/torture/pr89698.C
    branches/gcc-8-branch/gcc/testsuite/gcc.dg/torture/pr89595.c
    branches/gcc-8-branch/gcc/testsuite/gcc.dg/torture/pr89710.c
    branches/gcc-8-branch/gcc/testsuite/gcc.dg/torture/pr90071.c
    branches/gcc-8-branch/gcc/testsuite/gcc.target/alpha/pr86984.c