Don't compare symbol addresses directly
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 22 Jul 2015 10:36:42 +0000 (03:36 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 22 Jul 2015 10:38:00 +0000 (03:38 -0700)
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.

gold/ChangeLog
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/script_test_1.cc [deleted file]
gold/testsuite/script_test_1.h [new file with mode: 0644]
gold/testsuite/script_test_11.c [deleted file]
gold/testsuite/script_test_11.h [new file with mode: 0644]
gold/testsuite/script_test_11a.c [new file with mode: 0644]
gold/testsuite/script_test_11b.c [new file with mode: 0644]
gold/testsuite/script_test_1a.cc [new file with mode: 0644]
gold/testsuite/script_test_1b.cc [new file with mode: 0644]

index 45daaa573a028f8b49e59d05181338872a5ab353..2977734f3ce47227f4049d25a43b8e955d83f232 100644 (file)
@@ -1,3 +1,27 @@
+2015-07-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+       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.
+
 2015-07-22  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gold/18628
index 4b0027397e578d34dae35357aaa2470d069f422b..ca070163a720e5f7691ec7d1b6f7cab808c86746 100644 (file)
@@ -1636,7 +1636,7 @@ relro_script_test.so: gcctestdir/ld relro_script_test.t relro_test_pic.o
        $(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro -Wl,-T,$(srcdir)/relro_script_test.t relro_test_pic.o
 
 check_PROGRAMS += script_test_1
-script_test_1_SOURCES = script_test_1.cc
+script_test_1_SOURCES = script_test_1a.cc script_test_1b.cc
 script_test_1_DEPENDENCIES = gcctestdir/ld script_test_1.t
 script_test_1_LDFLAGS = -Bgcctestdir/ -Wl,-R,. -Wl,-T,$(srcdir)/script_test_1.t
 script_test_1_LDADD =
@@ -1769,9 +1769,11 @@ script_test_9.stdout: script_test_9
 check_PROGRAMS += script_test_11
 script_test_11: gcctestdir/ld script_test_11_r.o
        $(LINK) -Bgcctestdir/ script_test_11_r.o
-script_test_11_r.o: gcctestdir/ld $(srcdir)/script_test_11.t script_test_11.o
-       gcctestdir/ld -r -o $@ -T $(srcdir)/script_test_11.t script_test_11.o
-script_test_11.o: script_test_11.c
+script_test_11_r.o: gcctestdir/ld $(srcdir)/script_test_11.t script_test_11a.o script_test_11b.o
+       gcctestdir/ld -r -o $@ -T $(srcdir)/script_test_11.t script_test_11a.o script_test_11b.o
+script_test_11a.o: script_test_11a.c
+       $(COMPILE) -c -g -o $@ $<
+script_test_11b.o: script_test_11b.c
        $(COMPILE) -c -g -o $@ $<
 
 # Test difference between "*(a b)" and "*(a) *(b)" in input section spec.
index 720558bacc19f354bc74d51d5424389bdc0448bb..d4cc5dca69ea1c9cd629b399e60bfe1aa923e2ee 100644 (file)
@@ -1706,7 +1706,8 @@ relro_test_OBJECTS = $(am_relro_test_OBJECTS)
 relro_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
        $(relro_test_LDFLAGS) $(LDFLAGS) -o $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am_script_test_1_OBJECTS =  \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1.$(OBJEXT)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1a.$(OBJEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1b.$(OBJEXT)
 script_test_1_OBJECTS = $(am_script_test_1_OBJECTS)
 script_test_1_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
        $(script_test_1_LDFLAGS) $(LDFLAGS) -o $@
@@ -2838,7 +2839,7 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test_DEPENDENCIES = gcctestdir/ld relro_script_test.so
 @GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
 @GCC_TRUE@@NATIVE_LINKER_TRUE@relro_script_test_LDADD = relro_script_test.so
-@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_SOURCES = script_test_1.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_SOURCES = script_test_1a.cc script_test_1b.cc
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_DEPENDENCIES = gcctestdir/ld script_test_1.t
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_LDFLAGS = -Bgcctestdir/ -Wl,-R,. -Wl,-T,$(srcdir)/script_test_1.t
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_1_LDADD = 
@@ -3986,10 +3987,11 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_2.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_3.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/relro_test_main.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_1.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_11.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_12.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_12i.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_1a.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_1b.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_2.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_2a.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script_test_2b.Po@am__quote@
@@ -5828,9 +5830,11 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -lW script_test_9 > script_test_9.stdout
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_11: gcctestdir/ld script_test_11_r.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ script_test_11_r.o
-@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_11_r.o: gcctestdir/ld $(srcdir)/script_test_11.t script_test_11.o
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -r -o $@ -T $(srcdir)/script_test_11.t script_test_11.o
-@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_11.o: script_test_11.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_11_r.o: gcctestdir/ld $(srcdir)/script_test_11.t script_test_11a.o script_test_11b.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -r -o $@ -T $(srcdir)/script_test_11.t script_test_11a.o script_test_11b.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_11a.o: script_test_11a.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -g -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_11b.o: script_test_11b.c
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -g -o $@ $<
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_12: gcctestdir/ld $(srcdir)/script_test_12.t script_test_12a.o script_test_12b.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,-T,$(srcdir)/script_test_12.t script_test_12a.o script_test_12b.o
diff --git a/gold/testsuite/script_test_1.cc b/gold/testsuite/script_test_1.cc
deleted file mode 100644 (file)
index 32ff102..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// script_test_1.cc -- linker script test 1 for gold  -*- C++ -*-
-
-// Copyright (C) 2008-2015 Free Software Foundation, Inc.
-// Written by Ian Lance Taylor <iant@google.com>.
-
-// This file is part of gold.
-
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-// MA 02110-1301, USA.
-
-// A test for a linker script which sets symbols to values.
-
-#include <cassert>
-#include <cstddef>
-#include <stdint.h>
-
-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;
-}
diff --git a/gold/testsuite/script_test_1.h b/gold/testsuite/script_test_1.h
new file mode 100644 (file)
index 0000000..5c23c54
--- /dev/null
@@ -0,0 +1,25 @@
+// script_test_1.h -- linker script test 1 for gold  -*- C++ -*-
+
+// Copyright (C) 2015 Free Software Foundation, Inc.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+#include <stdint.h>
+
+extern void check_int(intptr_t, intptr_t);
+extern void check_ptr(int *, int *);
diff --git a/gold/testsuite/script_test_11.c b/gold/testsuite/script_test_11.c
deleted file mode 100644 (file)
index d932813..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-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;
-}
diff --git a/gold/testsuite/script_test_11.h b/gold/testsuite/script_test_11.h
new file mode 100644 (file)
index 0000000..959a8ab
--- /dev/null
@@ -0,0 +1 @@
+extern int ptr_equal(char *, char *);
diff --git a/gold/testsuite/script_test_11a.c b/gold/testsuite/script_test_11a.c
new file mode 100644 (file)
index 0000000..9e69877
--- /dev/null
@@ -0,0 +1,18 @@
+#include "script_test_11.h"
+
+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 (!ptr_equal(&__foo_start, (char *)&foo))
+    return 2;
+  return 0;
+}
diff --git a/gold/testsuite/script_test_11b.c b/gold/testsuite/script_test_11b.c
new file mode 100644 (file)
index 0000000..9f95e13
--- /dev/null
@@ -0,0 +1,7 @@
+#include "script_test_11.h"
+
+int 
+ptr_equal(char *a, char *b)
+{
+  return a == b;
+} 
diff --git a/gold/testsuite/script_test_1a.cc b/gold/testsuite/script_test_1a.cc
new file mode 100644 (file)
index 0000000..648b42a
--- /dev/null
@@ -0,0 +1,46 @@
+// script_test_1a.cc -- linker script test 1 for gold  -*- C++ -*-
+
+// Copyright (C) 2008-2015 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// A test for a linker script which sets symbols to values.
+
+#include "script_test_1.h"
+
+extern char a, b, c, d, e, f, g;
+int sym = 3;
+int common_sym;
+
+int
+main(int, char**)
+{
+  check_int(reinterpret_cast<intptr_t>(&a), 123);
+  check_int(reinterpret_cast<intptr_t>(&b),
+           reinterpret_cast<intptr_t>(&a) * 2);
+  check_int(reinterpret_cast<intptr_t>(&c),
+           reinterpret_cast<intptr_t>(&b) + 3 * 6);
+  check_int(reinterpret_cast<intptr_t>(&d),
+           (reinterpret_cast<intptr_t>(&b) + 3) * 6);
+  check_ptr(reinterpret_cast<int*>(&e), &sym);
+  check_int(reinterpret_cast<intptr_t>(&f),
+           reinterpret_cast<intptr_t>(&sym) + 10);
+  check_ptr(reinterpret_cast<int*>(&g), &common_sym);
+  return 0;
+}
diff --git a/gold/testsuite/script_test_1b.cc b/gold/testsuite/script_test_1b.cc
new file mode 100644 (file)
index 0000000..553ebca
--- /dev/null
@@ -0,0 +1,38 @@
+// script_test_1b.cc -- linker script test 1 for gold  -*- C++ -*-
+
+// Copyright (C) 2015 Free Software Foundation, Inc.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// A test for a linker script which sets symbols to values.
+
+#include <cassert>
+
+#include "script_test_1.h"
+
+void
+check_int(intptr_t i, intptr_t j)
+{
+  assert (i == j);
+}
+
+void
+check_ptr(int *i, int *j)
+{
+  assert (i == j);
+}
This page took 0.04697 seconds and 4 git commands to generate.