From 22dc1b094d9ad4794c07aeb9b923d8fb0d51b161 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 22 Sep 2007 22:44:33 +0000 Subject: [PATCH] Add standalone test case. --- gold/testsuite/Makefile.am | 30 +++- gold/testsuite/Makefile.in | 23 ++- gold/testsuite/t1.cc | 318 +++++++++++++++++++++++++++++++++++++ 3 files changed, 367 insertions(+), 4 deletions(-) create mode 100644 gold/testsuite/t1.cc diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 12268c68ad5..265717d6829 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -14,7 +14,13 @@ INCLUDES = -D_GNU_SOURCE \ -DLOCALEDIR="\"$(datadir)/locale\"" \ @INCINTL@ -TESTS = object_unittest +if GCC +if NATIVE_LINKER +NATIVE_TESTING = t1 t1_pic +endif +endif + +TESTS = object_unittest $(NATIVE_TESTING) check_LIBRARIES = libgoldtest.a libgoldtest_a_SOURCES = test.cc testmain.cc testfile.cc @@ -24,3 +30,25 @@ LDADD = libgoldtest.a ../libgold.a check_PROGRAMS = object_unittest object_unittest_SOURCES = object_unittest.cc + +if GCC +if NATIVE_LINKER + +gcctestdir/ld: ../ld-new + test -d gcctestdir || mkdir -p gcctestdir + rm -f gcctestdir/ld + (cd gcctestdir && $(LN_S) ../../ld-new ld) + +# Override the default CXXFLAGS--we don't want any optimization +t1.o: t1.cc + $(CXXCOMPILE) -O0 -c -o $@ $< +t1: t1.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ t1.o + +t1_pic.o: t1.cc + $(CXXCOMPILE) -O0 -c -fpic -o $@ $< +t1_pic: t1_pic.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ t1_pic.o + +endif +endif diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 0990cc630bf..28b7350d8ca 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -208,7 +208,8 @@ INCLUDES = -D_GNU_SOURCE \ -DLOCALEDIR="\"$(datadir)/locale\"" \ @INCINTL@ -TESTS = object_unittest +@GCC_TRUE@@NATIVE_LINKER_TRUE@NATIVE_TESTING = t1 t1_pic +TESTS = object_unittest $(NATIVE_TESTING) check_LIBRARIES = libgoldtest.a libgoldtest_a_SOURCES = test.cc testmain.cc testfile.cc LDADD = libgoldtest.a ../libgold.a @@ -226,9 +227,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign testsuite/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu testsuite/Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign testsuite/Makefile + $(AUTOMAKE) --gnu testsuite/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -525,6 +526,22 @@ uninstall-am: uninstall-info-am mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-info-am + +@GCC_TRUE@@NATIVE_LINKER_TRUE@gcctestdir/ld: ../ld-new +@GCC_TRUE@@NATIVE_LINKER_TRUE@ test -d gcctestdir || mkdir -p gcctestdir +@GCC_TRUE@@NATIVE_LINKER_TRUE@ rm -f gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ (cd gcctestdir && $(LN_S) ../../ld-new ld) + +# Override the default CXXFLAGS--we don't want any optimization +@GCC_TRUE@@NATIVE_LINKER_TRUE@t1.o: t1.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@t1: t1.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ t1.o + +@GCC_TRUE@@NATIVE_LINKER_TRUE@t1_pic.o: t1.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -fpic -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@t1_pic: t1_pic.o gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ t1_pic.o # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/gold/testsuite/t1.cc b/gold/testsuite/t1.cc new file mode 100644 index 00000000000..795f0496850 --- /dev/null +++ b/gold/testsuite/t1.cc @@ -0,0 +1,318 @@ +// t1.cc -- a test case for gold + +// Copyright 2006, 2007 Free Software Foundation, Inc. +// Written by Ian Lance Taylor . + +// 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. + +// The goal of this program is to produce as many different types of +// relocations as we can in a stand-alone program that does not use +// TLS. This program is compiled without optimization. + +// 1 Code reference to global data. +// 2 Code reference to static data. +// 3 Code reference to BSS data. +// 4 Code reference to offset within global data. +// 5 Code reference to offset within static data. +// 6 Code reference to offset within BSS data. +// 7 Switch statement with a table of destinations. +// 8 Taking the address of a label (a gcc extension). +// 9 Taking the address of a nested function (a gcc extension). +// 10 Data reference to global data. +// 11 Data reference to static data. +// 12 Data reference to BSS data. +// 13 Data reference to offset within global data. +// 14 Data reference to offset within static data. +// 15 Data reference to offset within BSS data. +// 16 Virtual table. +// 17 Inline function. +// 18 Call through pointer to method. +// 19 Initialize variable to pointer to method. +// 20 Global constructor and destructor. + +// 1 Code reference to global data. +int t1 = 11; + +// 2 Code reference to static data. +static int t2 = 22; + +// 3 Code reference to BSS data (initialized after program starts, to +// 33). +int t3; + +// 4 Code reference to offset within global data. +char t4[] = "Hello, world"; + +// 5 Code reference to offset within static data. +static char t5[] = "Hello, world"; + +// 6 Code reference to offset within BSS data (initialized after +// program starts, to contents of t4). +char t6[13]; + +// Test cases 1 through 6. + +bool +t1_6() +{ + return (t1 == 11 + && t2 == 22 + && t3 == 33 + && t4[5] == ',' + && t5[7] == 'w' + && t6[9] == 'r'); +} + +// 7 Switch statement with a table of destinations. + +int +t7(int i) +{ + switch (i) + { + case 0: + return 12; + case 1: + return 34; + case 2: + return 56; + case 3: + return 78; + case 4: + return 90; + case 5: + return 13; + case 6: + return 0; + case 7: + return 57; + case 8: + return 79; + case 9: + return 81; + default: + return 144; + } +} + +// 8 Taking the address of a label (a gcc extension). + +int +t8(int i) +{ + for (int j = 0; j < 10; ++j) + { + void* p; + if (i + j > 6) + p = &&lab1; + else + p = &&lab2; + if (j == 7) + goto *p; + } + return 15; + lab1: + return 0; + lab2: + return 12; +} + +// 9 Taking the address of a nested function (a gcc extension). +// Disabled because this is only supported in C, not C++. + +int +t9a(int (*pfn)(int)) +{ + return (*pfn)(10) - 10; +} + +int +t9(int i) +{ +#if 0 + int + t9c(int j) + { + return i + j; + } + return t9a(&t9c); +#else + return i; +#endif +} + +// 10 Data reference to global data. +int* t10 = &t1; + +// 11 Data reference to static data. +int* t11 = &t2; + +// 12 Data reference to BSS data. +int* t12 = &t3; + +// 13 Data reference to offset within global data. +char* t13 = &t4[6]; + +// 14 Data reference to offset within static data. +char* t14 = &t5[8]; + +// 15 Data reference to offset within BSS data. +char* t15 = &t6[10]; + +// Test cases 10 through 15. + +bool +t10_15() +{ + return (*t10 == 11 + && *t11 == 22 + && *t12 == 33 + && *t13 == ' ' + && *t14 == 'o' + && *t15 == 'l'); +} + +// 16 Virtual table. + +class t16a +{ + public: + virtual + ~t16a() + { } + virtual int + t() + { return 83; } +}; + +class t16b : public t16a +{ + public: + virtual int + t() + { return 92; } +}; + +t16b t16v; + +bool +t16() +{ + return t16v.t() == 92; +} + +// 17 Inline function. + +inline int +t17a() +{ + return 74; +} + +bool +t17() +{ + return t17a() == 74; +} + +// 18 Call through pointer to method. + +class t18a +{ + public: + int + ta() + { return 65; } + + int + tb() + { return 90; } +}; + +t18a t18v; + +int +t18f(int (t18a::* p)()) +{ + return (t18v.*p)(); +} + +bool +t18() +{ + return t18f(&t18a::ta) == 65; +} + +// 19 Initialize variable to pointer to method. + +int (t18a::* t19v)() = &t18a::tb; + +bool +t19() +{ + return (t18v.*t19v)() == 90; +} + +// 20 Global constructor and destructor. + +class t20a +{ + public: + t20a() + : i(96) + { } + ~t20a() + { } + int + get() const + { return this->i; } + private: + int i; +}; + +t20a t20v; + +bool +t20() +{ + return t20v.get() == 96; +} + +// Main function. Initialize variables and call test functions. + +int +main() +{ + t3 = 33; + for (int i = 0; i < 13; ++i) + t6[i] = t4[i]; + + if (t1_6() + && t7(6) == 0 + && t8(0) == 0 + && t9(5) == 5 + && t10_15() + && t16() + && t17() + && t18() + && t19() + && t20()) + return 0; + else + return 1; +} -- 2.30.2