diff options
author | Cary Coutant <ccoutant@gmail.com> | 2016-02-05 08:27:13 -0800 |
---|---|---|
committer | Cary Coutant <ccoutant@gmail.com> | 2016-02-05 08:28:04 -0800 |
commit | 44803b5d876fcbbc1c6d9919a1b763679d5c035f (patch) | |
tree | ce379ebc2bdad88cc6c5be2170b73b9bc90e99b8 /gold/testsuite | |
parent | 6f57d0469ae5e73643aa5ef96a10e6bae7a79a15 (diff) | |
download | gdb-44803b5d876fcbbc1c6d9919a1b763679d5c035f.zip gdb-44803b5d876fcbbc1c6d9919a1b763679d5c035f.tar.gz gdb-44803b5d876fcbbc1c6d9919a1b763679d5c035f.tar.bz2 |
Overhaul relocation framework to support overflow checking.
gold/
PR gold/18695
* reloc.h (Relocate_functions::Address): New typedef.
(Relocate_functions::Addendtype): New typedef.
(Relocate_functions::Overflow_check): New enum type.
(Relocate_functions::Reloc_status): New enum type.
(Relocate_functions::check_overflow): New function template.
(Relocate_functions::rel): Add check parameter; check for overflow.
(Relocate_functions::rel_unaligned): Likewise.
(Relocate_functions::rela): Likewise.
(Relocate_functions::pcrel): Likewise.
(Relocate_functions::pcrel_unaligned): Likewise.
(Relocate_functions::pcrela): Likewise.
(Relocate_functions::rel8): Adjust parameter types.
(Relocate_functions::rela8): Likewise.
(Relocate_functions::pcrel8): Likewise.
(Relocate_functions::pcrela8): Likewise.
(Relocate_functions::rel16): Likewise.
(Relocate_functions::rela168): Likewise.
(Relocate_functions::pcrel16): Likewise.
(Relocate_functions::pcrela16): Likewise.
(Relocate_functions::rel32): Likewise.
(Relocate_functions::rel32_unaligned): Likewise.
(Relocate_functions::rela32): Likewise.
(Relocate_functions::pcrel32): Likewise.
(Relocate_functions::pcrel32_unaligned): Likewise.
(Relocate_functions::pcrela32): Likewise.
(Relocate_functions::rel8_check): New function.
(Relocate_functions::rela8_check): New function.
(Relocate_functions::pcrel8_check): New function.
(Relocate_functions::pcrela8_check): New function.
(Relocate_functions::rel16_check): New function.
(Relocate_functions::rela168_check): New function.
(Relocate_functions::pcrel16_check): New function.
(Relocate_functions::pcrela16_check): New function.
(Relocate_functions::rel32_check): New function.
(Relocate_functions::rel32_unaligned_check): New function.
(Relocate_functions::rela32_check): New function.
(Relocate_functions::pcrel32_check): New function.
(Relocate_functions::pcrel32_unaligned_check): New function.
(Relocate_functions::pcrela32_check): New function.
(Bits::has_unsigned_overflow32): New function.
(Bits::has_unsigned_overflow): New function.
* testsuite/Makefile.am (overflow_unittest): New test.
* testsuite/Makefile.in: Regenerate.
* testsuite/overflow_unittest.cc: New source file.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 5 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 34 | ||||
-rw-r--r-- | gold/testsuite/overflow_unittest.cc | 139 |
3 files changed, 171 insertions, 7 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index c8e5f9f..96d2b19 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -138,6 +138,11 @@ binary_unittest_SOURCES = binary_unittest.cc check_PROGRAMS += leb128_unittest leb128_unittest_SOURCES = leb128_unittest.cc +check_PROGRAMS += overflow_unittest +overflow_unittest_SOURCES = overflow_unittest.cc +overflow_unittest.o: overflow_unittest.cc + $(CXXCOMPILE) -O3 -c -o $@ $< + endif NATIVE_OR_CROSS_LINKER # --------------------------------------------------------------------- diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 31c9951..c771a42 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -54,7 +54,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ $(am__EXEEXT_34) $(am__EXEEXT_35) $(am__EXEEXT_36) \ $(am__EXEEXT_37) @NATIVE_OR_CROSS_LINKER_TRUE@am__append_1 = object_unittest \ -@NATIVE_OR_CROSS_LINKER_TRUE@ binary_unittest leb128_unittest +@NATIVE_OR_CROSS_LINKER_TRUE@ binary_unittest leb128_unittest \ +@NATIVE_OR_CROSS_LINKER_TRUE@ overflow_unittest @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_2 = incremental_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_comdat_test.sh gc_tls_test.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ gc_orphan_section_test.sh \ @@ -849,7 +850,8 @@ am_libgoldtest_a_OBJECTS = test.$(OBJEXT) testmain.$(OBJEXT) \ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @NATIVE_OR_CROSS_LINKER_TRUE@am__EXEEXT_1 = object_unittest$(EXEEXT) \ @NATIVE_OR_CROSS_LINKER_TRUE@ binary_unittest$(EXEEXT) \ -@NATIVE_OR_CROSS_LINKER_TRUE@ leb128_unittest$(EXEEXT) +@NATIVE_OR_CROSS_LINKER_TRUE@ leb128_unittest$(EXEEXT) \ +@NATIVE_OR_CROSS_LINKER_TRUE@ overflow_unittest$(EXEEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_2 = icf_virtual_function_folding_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ large_symbol_alignment$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_test$(EXEEXT) \ @@ -1584,6 +1586,14 @@ object_unittest_DEPENDENCIES = libgoldtest.a ../libgold.a \ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) +@NATIVE_OR_CROSS_LINKER_TRUE@am_overflow_unittest_OBJECTS = \ +@NATIVE_OR_CROSS_LINKER_TRUE@ overflow_unittest.$(OBJEXT) +overflow_unittest_OBJECTS = $(am_overflow_unittest_OBJECTS) +overflow_unittest_LDADD = $(LDADD) +overflow_unittest_DEPENDENCIES = libgoldtest.a ../libgold.a \ + ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) permission_test_SOURCES = permission_test.c permission_test_OBJECTS = permission_test.$(OBJEXT) permission_test_LDADD = $(LDADD) @@ -2126,11 +2136,12 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \ $(large_symbol_alignment_SOURCES) $(leb128_unittest_SOURCES) \ local_labels_test.c many_sections_r_test.c \ $(many_sections_test_SOURCES) $(object_unittest_SOURCES) \ - permission_test.c $(pie_copyrelocs_test_SOURCES) \ - plugin_test_1.c plugin_test_10.c plugin_test_11.c \ - plugin_test_2.c plugin_test_3.c plugin_test_4.c \ - plugin_test_5.c plugin_test_6.c plugin_test_7.c \ - plugin_test_8.c plugin_test_tls.c $(protected_1_SOURCES) \ + $(overflow_unittest_SOURCES) permission_test.c \ + $(pie_copyrelocs_test_SOURCES) plugin_test_1.c \ + plugin_test_10.c plugin_test_11.c plugin_test_2.c \ + plugin_test_3.c plugin_test_4.c plugin_test_5.c \ + plugin_test_6.c plugin_test_7.c plugin_test_8.c \ + plugin_test_tls.c $(protected_1_SOURCES) \ $(protected_2_SOURCES) $(relro_now_test_SOURCES) \ $(relro_script_test_SOURCES) $(relro_strip_test_SOURCES) \ $(relro_test_SOURCES) $(script_test_1_SOURCES) \ @@ -2496,6 +2507,7 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ @NATIVE_OR_CROSS_LINKER_TRUE@object_unittest_SOURCES = object_unittest.cc @NATIVE_OR_CROSS_LINKER_TRUE@binary_unittest_SOURCES = binary_unittest.cc @NATIVE_OR_CROSS_LINKER_TRUE@leb128_unittest_SOURCES = leb128_unittest.cc +@NATIVE_OR_CROSS_LINKER_TRUE@overflow_unittest_SOURCES = overflow_unittest.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@large_symbol_alignment_SOURCES = large_symbol_alignment.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@large_symbol_alignment_DEPENDENCIES = gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@large_symbol_alignment_LDFLAGS = -Bgcctestdir/ @@ -3533,6 +3545,9 @@ many_sections_test$(EXEEXT): $(many_sections_test_OBJECTS) $(many_sections_test_ object_unittest$(EXEEXT): $(object_unittest_OBJECTS) $(object_unittest_DEPENDENCIES) @rm -f object_unittest$(EXEEXT) $(CXXLINK) $(object_unittest_OBJECTS) $(object_unittest_LDADD) $(LIBS) +overflow_unittest$(EXEEXT): $(overflow_unittest_OBJECTS) $(overflow_unittest_DEPENDENCIES) + @rm -f overflow_unittest$(EXEEXT) + $(CXXLINK) $(overflow_unittest_OBJECTS) $(overflow_unittest_LDADD) $(LIBS) @GCC_FALSE@permission_test$(EXEEXT): $(permission_test_OBJECTS) $(permission_test_DEPENDENCIES) @GCC_FALSE@ @rm -f permission_test$(EXEEXT) @GCC_FALSE@ $(LINK) $(permission_test_OBJECTS) $(permission_test_LDADD) $(LIBS) @@ -3969,6 +3984,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/many_sections_r_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/many_sections_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object_unittest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/overflow_unittest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/permission_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pie_copyrelocs_test-pie_copyrelocs_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_1.Po@am__quote@ @@ -4550,6 +4566,8 @@ binary_unittest.log: binary_unittest$(EXEEXT) @p='binary_unittest$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) leb128_unittest.log: leb128_unittest$(EXEEXT) @p='leb128_unittest$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +overflow_unittest.log: overflow_unittest$(EXEEXT) + @p='overflow_unittest$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) icf_virtual_function_folding_test.log: icf_virtual_function_folding_test$(EXEEXT) @p='icf_virtual_function_folding_test$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) large_symbol_alignment.log: large_symbol_alignment$(EXEEXT) @@ -5027,6 +5045,8 @@ uninstall-am: @GCC_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ test -d gcctestdir || mkdir -p gcctestdir @GCC_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ rm -f gcctestdir/as @GCC_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ (cd gcctestdir && $(LN_S) $(abs_top_builddir)/../gas/as-new as) +@NATIVE_OR_CROSS_LINKER_TRUE@overflow_unittest.o: overflow_unittest.cc +@NATIVE_OR_CROSS_LINKER_TRUE@ $(CXXCOMPILE) -O3 -c -o $@ $< # --------------------------------------------------------------------- # These tests test the output of gold (end-to-end tests). In diff --git a/gold/testsuite/overflow_unittest.cc b/gold/testsuite/overflow_unittest.cc new file mode 100644 index 0000000..e33e012 --- /dev/null +++ b/gold/testsuite/overflow_unittest.cc @@ -0,0 +1,139 @@ +// overflow_unittest.cc -- test functions that check for overflow. + +// Copyright (C) 2016 Free Software Foundation, Inc. +// Written by Cary Coutant <ccoutant@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. + +#include "gold.h" +#include "reloc.h" + +#include <sys/types.h> + +#include "test.h" + +namespace gold_testsuite +{ + +using namespace gold; + +bool +Overflow_test(Test_report*) +{ + CHECK(! Bits<16>::has_unsigned_overflow(0ULL)); + CHECK(! Bits<16>::has_unsigned_overflow(1ULL)); + CHECK(! Bits<16>::has_unsigned_overflow(0x7fffULL)); + CHECK(! Bits<16>::has_unsigned_overflow(0x8000ULL)); + CHECK(! Bits<16>::has_unsigned_overflow(0x8001ULL)); + CHECK(! Bits<16>::has_unsigned_overflow(0xffffULL)); + CHECK(Bits<16>::has_unsigned_overflow(0x10000ULL)); + CHECK(Bits<16>::has_unsigned_overflow(0x10001ULL)); + CHECK(Bits<16>::has_unsigned_overflow(~0ULL)); + CHECK(Bits<16>::has_unsigned_overflow(~0x7fffULL + 1)); + CHECK(Bits<16>::has_unsigned_overflow(~0x8000ULL + 1)); + CHECK(Bits<16>::has_unsigned_overflow(~0x8001ULL + 1)); + CHECK(Bits<16>::has_unsigned_overflow(~0xffffULL + 1)); + CHECK(Bits<16>::has_unsigned_overflow(~0x10000ULL + 1)); + CHECK(Bits<16>::has_unsigned_overflow(~0x10001ULL + 1)); + + CHECK(! Bits<16>::has_overflow(0ULL)); + CHECK(! Bits<16>::has_overflow(1ULL)); + CHECK(! Bits<16>::has_overflow(0x7fffULL)); + CHECK(Bits<16>::has_overflow(0x8000ULL)); + CHECK(Bits<16>::has_overflow(0x8001ULL)); + CHECK(Bits<16>::has_overflow(0xffffULL)); + CHECK(Bits<16>::has_overflow(0x10000ULL)); + CHECK(Bits<16>::has_overflow(0x10001ULL)); + CHECK(! Bits<16>::has_overflow(~0ULL)); + CHECK(! Bits<16>::has_overflow(~0x7fffULL + 1)); + CHECK(! Bits<16>::has_overflow(~0x8000ULL + 1)); + CHECK(Bits<16>::has_overflow(~0x8001ULL + 1)); + CHECK(Bits<16>::has_overflow(~0xffffULL + 1)); + CHECK(Bits<16>::has_overflow(~0x10000ULL + 1)); + CHECK(Bits<16>::has_overflow(~0x10001ULL + 1)); + + CHECK(! Bits<16>::has_signed_unsigned_overflow64(0ULL)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(1ULL)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(0x7fffULL)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(0x8000ULL)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(0x8001ULL)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(0xffffULL)); + CHECK(Bits<16>::has_signed_unsigned_overflow64(0x10000ULL)); + CHECK(Bits<16>::has_signed_unsigned_overflow64(0x10001ULL)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(~0ULL)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(~0x7fffULL + 1)); + CHECK(! Bits<16>::has_signed_unsigned_overflow64(~0x8000ULL + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow64(~0x8001ULL + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow64(~0xffffULL + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow64(~0x10000ULL + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow64(~0x10001ULL + 1)); + + CHECK(! Bits<16>::has_unsigned_overflow32(0U)); + CHECK(! Bits<16>::has_unsigned_overflow32(1U)); + CHECK(! Bits<16>::has_unsigned_overflow32(0x7fffU)); + CHECK(! Bits<16>::has_unsigned_overflow32(0x8000U)); + CHECK(! Bits<16>::has_unsigned_overflow32(0x8001U)); + CHECK(! Bits<16>::has_unsigned_overflow32(0xffffU)); + CHECK(Bits<16>::has_unsigned_overflow32(0x10000U)); + CHECK(Bits<16>::has_unsigned_overflow32(0x10001U)); + CHECK(Bits<16>::has_unsigned_overflow32(~0U)); + CHECK(Bits<16>::has_unsigned_overflow32(~0x7fffU + 1)); + CHECK(Bits<16>::has_unsigned_overflow32(~0x8000U + 1)); + CHECK(Bits<16>::has_unsigned_overflow32(~0x8001U + 1)); + CHECK(Bits<16>::has_unsigned_overflow32(~0xffffU + 1)); + CHECK(Bits<16>::has_unsigned_overflow32(~0x10000U + 1)); + CHECK(Bits<16>::has_unsigned_overflow32(~0x10001U + 1)); + + CHECK(! Bits<16>::has_overflow32(0U)); + CHECK(! Bits<16>::has_overflow32(1U)); + CHECK(! Bits<16>::has_overflow32(0x7fffU)); + CHECK(Bits<16>::has_overflow32(0x8000U)); + CHECK(Bits<16>::has_overflow32(0x8001U)); + CHECK(Bits<16>::has_overflow32(0xffffU)); + CHECK(Bits<16>::has_overflow32(0x10000U)); + CHECK(Bits<16>::has_overflow32(0x10001U)); + CHECK(! Bits<16>::has_overflow32(~0U)); + CHECK(! Bits<16>::has_overflow32(~0x7fffU + 1)); + CHECK(! Bits<16>::has_overflow32(~0x8000U + 1)); + CHECK(Bits<16>::has_overflow32(~0x8001U + 1)); + CHECK(Bits<16>::has_overflow32(~0xffffU + 1)); + CHECK(Bits<16>::has_overflow32(~0x10000U + 1)); + CHECK(Bits<16>::has_overflow32(~0x10001U + 1)); + + CHECK(! Bits<16>::has_signed_unsigned_overflow32(0U)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(1U)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(0x7fffU)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(0x8000U)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(0x8001U)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(0xffffU)); + CHECK(Bits<16>::has_signed_unsigned_overflow32(0x10000U)); + CHECK(Bits<16>::has_signed_unsigned_overflow32(0x10001U)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(~0U)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(~0x7fffU + 1)); + CHECK(! Bits<16>::has_signed_unsigned_overflow32(~0x8000U + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow32(~0x8001U + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow32(~0xffffU + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow32(~0x10000U + 1)); + CHECK(Bits<16>::has_signed_unsigned_overflow32(~0x10001U + 1)); + + return true; +} + +Register_test overflow_register("Overflow", Overflow_test); + +} // End namespace gold_testsuite. |