Bug 18663 - gold/testsuite/script_test_1.cc is incompatible with GCC 5
Summary: gold/testsuite/script_test_1.cc is incompatible with GCC 5
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.26
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks: 18521
  Show dependency treegraph
 
Reported: 2015-07-13 19:02 UTC by H.J. Lu
Modified: 2015-07-22 10:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2015-07-13 19:02:49 UTC
gold/testsuite/script_test_1.cc has

extern char a, b, c, d, e, f, g;
int sym = 3;
int common_sym;

int
main(int, char**)
{
  assert(reinterpret_cast<intptr_t>(&a) == 123);
  assert(reinterpret_cast<intptr_t>(&b) == reinterpret_cast<intptr_t>(&a) * 2);
  assert(reinterpret_cast<intptr_t>(&c)
	 == reinterpret_cast<intptr_t>(&b) + 3 * 6);
  assert(reinterpret_cast<intptr_t>(&d)
	 == (reinterpret_cast<intptr_t>(&b) + 3) * 6);
  assert(reinterpret_cast<int*>(&e) == &sym);
  assert(reinterpret_cast<intptr_t>(&f)
	 == reinterpret_cast<intptr_t>(&sym) + 10);
  assert(reinterpret_cast<int*>(&g) == &common_sym);
  return 0;
}

GCC 5 will fold many asserts, assuming each symbol has a different
address, which leads to abort.
Comment 1 H.J. Lu 2015-07-13 19:27:24 UTC
gold/testsuite/script_test_11.t has the same issue:

---
static unsigned int buffer1[256] __attribute((used));
static unsigned int buffer2[256] __attribute((used)) = { 1 };

unsigned int foo __attribute__((section(".foo")));
extern char __foo_start;
extern char __foo_end;

int
main (void)
{
  if (&__foo_end - &__foo_start != sizeof(foo))
    return 1;
  if (&__foo_start != (char *)&foo)
    return 2;
  return 0;
}
---

GCC 5 folds "&__foo_start != (char *)&foo" to true.
Comment 2 Cary Coutant 2015-07-22 02:16:38 UTC
(Why do I have to type something here?) Duplicate of PR 18521.

*** This bug has been marked as a duplicate of bug 18521 ***
Comment 3 H.J. Lu 2015-07-22 02:23:42 UTC
This bug report has some analysis while PR 18521 doesn't.
Comment 4 H.J. Lu 2015-07-22 02:24:21 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2015-07/msg00099.html
Comment 5 cvs-commit@gcc.gnu.org 2015-07-22 10:41:53 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5b2af7dd40a4f3b570aef71daf11b9dfce9a5d13

commit 5b2af7dd40a4f3b570aef71daf11b9dfce9a5d13
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 22 03:36:42 2015 -0700

    Don't compare symbol addresses directly
    
    GCC 5 will fold symbol address comparison, assuming each symbol has a
    different address, which leads to abort.  We should use separate
    functions to compare symbol address.
    
    	PR gold/18663
    	* testsuite/Makefile.am (script_test_1_SOURCES): Set to
    	script_test_1a.cc script_test_1b.cc.
    	(script_test_11_r.o): Replace script_test_11.o with
    	script_test_11a.o script_test_11b.o.
    	(script_test_11.o): Removed.
    	(script_test_11a.o): New.
    	(script_test_11b.o): Likewise.
    	* testsuite/Makefile.in: Regenerated.
    	* testsuite/script_test_1.h: New file.
    	* testsuite/script_test_1b.cc: Likewise.
    	* testsuite/script_test_11.h: Likewise.
    	* testsuite/script_test_11b.c: Likewise.
    	* testsuite/script_test_1.cc: Renamed to ...
    	* testsuite/script_test_1a.cc: This.
    	Include "script_test_1.h".
    	(main): Call check_int and check_ptr.
    	* testsuite/script_test_11.c: Renamed to ...
    	* testsuite/script_test_11a.c: This.
    	Include "script_test_11.h".
    	(main): Call ptr_equal.
Comment 6 H.J. Lu 2015-07-22 10:45:07 UTC
Fixed.