aboutsummaryrefslogtreecommitdiff
path: root/gold/testsuite
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2008-02-08 07:06:58 +0000
committerIan Lance Taylor <iant@google.com>2008-02-08 07:06:58 +0000
commitbc644c6cfca852cd34e486a018bfde7fd1ac55e8 (patch)
tree0a3f5a7539df0cebdaddc0accf07a156e5c5221c /gold/testsuite
parent897b09ca9f17a38ab9c552ae6933eb595283aa4c (diff)
downloadgdb-bc644c6cfca852cd34e486a018bfde7fd1ac55e8.zip
gdb-bc644c6cfca852cd34e486a018bfde7fd1ac55e8.tar.gz
gdb-bc644c6cfca852cd34e486a018bfde7fd1ac55e8.tar.bz2
Add support for --format binary for input files.
Diffstat (limited to 'gold/testsuite')
-rw-r--r--gold/testsuite/Makefile.am13
-rw-r--r--gold/testsuite/Makefile.in51
-rw-r--r--gold/testsuite/binary.in1
-rw-r--r--gold/testsuite/binary_test.cc46
-rw-r--r--gold/testsuite/binary_unittest.cc147
5 files changed, 252 insertions, 6 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index c1a081c..0d1db37 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -53,6 +53,9 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \
check_PROGRAMS += object_unittest
object_unittest_SOURCES = object_unittest.cc
+check_PROGRAMS += binary_unittest
+binary_unittest_SOURCES = binary_unittest.cc
+
# ---------------------------------------------------------------------
# These tests test the output of gold (end-to-end tests). In
@@ -550,6 +553,16 @@ justsyms_2.o: justsyms_2.cc
justsyms_2r.o: justsyms_2.o gcctestdir/ld
gcctestdir/ld -o $@ -r -T $(srcdir)/justsyms.t justsyms_2.o
+check_PROGRAMS += binary_test
+binary_test_SOURCES = binary_test.cc
+binary_test_DEPENDENCIES = gcctestdir/ld binary.txt
+binary_test_LDFLAGS = -Bgcctestdir/ -Wl,--format,binary,binary.txt,--format,elf
+# Copy the file to the build directory to avoid worrying about the
+# full pathname in the generated symbols.
+binary.txt: $(srcdir)/binary.in
+ rm -f $@
+ $(LN_S) $< $@
+
if OBJDUMP_AND_CPPFILT
check_SCRIPTS += ver_matching_test.sh
check_DATA += ver_matching_test.stdout
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 10119eb..7b3a6c5 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -42,10 +42,10 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
-check_PROGRAMS = object_unittest$(EXEEXT) $(am__EXEEXT_1) \
- $(am__EXEEXT_2) $(am__EXEEXT_3) $(am__EXEEXT_4) \
- $(am__EXEEXT_5) $(am__EXEEXT_6) $(am__EXEEXT_7) \
- $(am__EXEEXT_8)
+check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
+ $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
+ $(am__EXEEXT_4) $(am__EXEEXT_5) $(am__EXEEXT_6) \
+ $(am__EXEEXT_7) $(am__EXEEXT_8)
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_1 = basic_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_static_test basic_pic_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ basic_static_pic_test \
@@ -176,7 +176,8 @@ check_PROGRAMS = object_unittest$(EXEEXT) $(am__EXEEXT_1) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ flagstest_o_specialfile \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ flagstest_o_specialfile_and_compress_debug_sections \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test script_test_1 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2 justsyms
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2 justsyms \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test
@GCC_FALSE@script_test_1_DEPENDENCIES = libgoldtest.a ../libgold.a \
@GCC_FALSE@ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
@GCC_FALSE@ $(am__DEPENDENCIES_1)
@@ -198,6 +199,13 @@ check_PROGRAMS = object_unittest$(EXEEXT) $(am__EXEEXT_1) \
@NATIVE_LINKER_FALSE@ ../libgold.a ../../libiberty/libiberty.a \
@NATIVE_LINKER_FALSE@ $(am__DEPENDENCIES_1) \
@NATIVE_LINKER_FALSE@ $(am__DEPENDENCIES_1)
+@GCC_FALSE@binary_test_DEPENDENCIES = libgoldtest.a ../libgold.a \
+@GCC_FALSE@ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+@GCC_FALSE@ $(am__DEPENDENCIES_1)
+@NATIVE_LINKER_FALSE@binary_test_DEPENDENCIES = libgoldtest.a \
+@NATIVE_LINKER_FALSE@ ../libgold.a ../../libiberty/libiberty.a \
+@NATIVE_LINKER_FALSE@ $(am__DEPENDENCIES_1) \
+@NATIVE_LINKER_FALSE@ $(am__DEPENDENCIES_1)
@GCC_TRUE@@NATIVE_LINKER_TRUE@@OBJDUMP_AND_CPPFILT_TRUE@am__append_11 = ver_matching_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@OBJDUMP_AND_CPPFILT_TRUE@ script_test_3.sh
@GCC_TRUE@@NATIVE_LINKER_TRUE@@OBJDUMP_AND_CPPFILT_TRUE@am__append_12 = ver_matching_test.stdout \
@@ -272,7 +280,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_1$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2$(EXEEXT) \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ justsyms$(EXEEXT)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ justsyms$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test$(EXEEXT)
@GCC_TRUE@@NATIVE_LINKER_TRUE@@OBJDUMP_AND_CPPFILT_TRUE@am__EXEEXT_8 = script_test_3$(EXEEXT)
basic_pic_test_SOURCES = basic_pic_test.c
basic_pic_test_OBJECTS = basic_pic_test.$(OBJEXT)
@@ -299,6 +308,17 @@ basic_test_LDADD = $(LDADD)
basic_test_DEPENDENCIES = libgoldtest.a ../libgold.a \
../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
+am__binary_test_SOURCES_DIST = binary_test.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am_binary_test_OBJECTS = \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test.$(OBJEXT)
+binary_test_OBJECTS = $(am_binary_test_OBJECTS)
+binary_test_LDADD = $(LDADD)
+am_binary_unittest_OBJECTS = binary_unittest.$(OBJEXT)
+binary_unittest_OBJECTS = $(am_binary_unittest_OBJECTS)
+binary_unittest_LDADD = $(LDADD)
+binary_unittest_DEPENDENCIES = libgoldtest.a ../libgold.a \
+ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1)
am__constructor_static_test_SOURCES_DIST = constructor_test.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__objects_1 = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ constructor_test.$(OBJEXT)
@@ -577,6 +597,7 @@ CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
-o $@
SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \
basic_static_pic_test.c basic_static_test.c basic_test.c \
+ $(binary_test_SOURCES) $(binary_unittest_SOURCES) \
$(constructor_static_test_SOURCES) $(constructor_test_SOURCES) \
$(exception_same_shared_test_SOURCES) \
$(exception_separate_shared_12_test_SOURCES) \
@@ -612,6 +633,7 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \
$(ver_test_SOURCES) $(weak_test_SOURCES)
DIST_SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \
basic_static_pic_test.c basic_static_test.c basic_test.c \
+ $(am__binary_test_SOURCES_DIST) $(binary_unittest_SOURCES) \
$(am__constructor_static_test_SOURCES_DIST) \
$(am__constructor_test_SOURCES_DIST) \
$(am__exception_same_shared_test_SOURCES_DIST) \
@@ -826,6 +848,7 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \
$(THREADSLIB)
object_unittest_SOURCES = object_unittest.cc
+binary_unittest_SOURCES = binary_unittest.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_SOURCES = constructor_test.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_DEPENDENCIES = gcctestdir/ld
@GCC_TRUE@@NATIVE_LINKER_TRUE@constructor_test_LDFLAGS = -Bgcctestdir/
@@ -1025,6 +1048,9 @@ object_unittest_SOURCES = object_unittest.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@justsyms_SOURCES = justsyms_1.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@justsyms_DEPENDENCIES = gcctestdir/ld justsyms_2r.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@justsyms_LDFLAGS = -Bgcctestdir/ -Wl,-R,justsyms_2r.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@binary_test_SOURCES = binary_test.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@binary_test_DEPENDENCIES = gcctestdir/ld binary.txt
+@GCC_TRUE@@NATIVE_LINKER_TRUE@binary_test_LDFLAGS = -Bgcctestdir/ -Wl,--format,binary,binary.txt,--format,elf
all: all-am
.SUFFIXES:
@@ -1092,6 +1118,12 @@ clean-checkPROGRAMS:
@NATIVE_LINKER_FALSE@basic_test$(EXEEXT): $(basic_test_OBJECTS) $(basic_test_DEPENDENCIES)
@NATIVE_LINKER_FALSE@ @rm -f basic_test$(EXEEXT)
@NATIVE_LINKER_FALSE@ $(LINK) $(basic_test_LDFLAGS) $(basic_test_OBJECTS) $(basic_test_LDADD) $(LIBS)
+binary_test$(EXEEXT): $(binary_test_OBJECTS) $(binary_test_DEPENDENCIES)
+ @rm -f binary_test$(EXEEXT)
+ $(CXXLINK) $(binary_test_LDFLAGS) $(binary_test_OBJECTS) $(binary_test_LDADD) $(LIBS)
+binary_unittest$(EXEEXT): $(binary_unittest_OBJECTS) $(binary_unittest_DEPENDENCIES)
+ @rm -f binary_unittest$(EXEEXT)
+ $(CXXLINK) $(binary_unittest_LDFLAGS) $(binary_unittest_OBJECTS) $(binary_unittest_LDADD) $(LIBS)
constructor_static_test$(EXEEXT): $(constructor_static_test_OBJECTS) $(constructor_static_test_DEPENDENCIES)
@rm -f constructor_static_test$(EXEEXT)
$(CXXLINK) $(constructor_static_test_LDFLAGS) $(constructor_static_test_OBJECTS) $(constructor_static_test_LDADD) $(LIBS)
@@ -1250,6 +1282,8 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic_static_pic_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic_static_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic_test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/binary_test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/binary_unittest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/constructor_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exception_test_1.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exception_test_2.Po@am__quote@
@@ -1718,6 +1752,11 @@ uninstall-am: uninstall-info-am
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@justsyms_2r.o: justsyms_2.o gcctestdir/ld
@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -o $@ -r -T $(srcdir)/justsyms.t justsyms_2.o
+# Copy the file to the build directory to avoid worrying about the
+# full pathname in the generated symbols.
+@GCC_TRUE@@NATIVE_LINKER_TRUE@binary.txt: $(srcdir)/binary.in
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ rm -f $@
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LN_S) $< $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@@OBJDUMP_AND_CPPFILT_TRUE@ver_matching_def.so: ver_matching_def.cc gcctestdir/ld
@GCC_TRUE@@NATIVE_LINKER_TRUE@@OBJDUMP_AND_CPPFILT_TRUE@ $(CXXLINK) -O0 -Bgcctestdir/ -shared $(srcdir)/ver_matching_def.cc -Wl,--version-script=$(srcdir)/version_script.map
@GCC_TRUE@@NATIVE_LINKER_TRUE@@OBJDUMP_AND_CPPFILT_TRUE@ver_matching_test.stdout: ver_matching_def.so
diff --git a/gold/testsuite/binary.in b/gold/testsuite/binary.in
new file mode 100644
index 0000000..cf5d631
--- /dev/null
+++ b/gold/testsuite/binary.in
@@ -0,0 +1 @@
+This file is used for the binary test.
diff --git a/gold/testsuite/binary_test.cc b/gold/testsuite/binary_test.cc
new file mode 100644
index 0000000..d645536
--- /dev/null
+++ b/gold/testsuite/binary_test.cc
@@ -0,0 +1,46 @@
+// binary_test.cc -- test --format binary for gold
+
+// Copyright 2008 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.
+
+// This program is linked with a small text file named binary.txt
+// using --formatbinary.
+
+#include <cassert>
+#include <cstddef>
+#include <cstring>
+#include <stdint.h>
+
+extern char _binary_binary_txt_start[];
+extern char _binary_binary_txt_end[];
+extern char _binary_binary_txt_size[];
+
+int
+main(int, char**)
+{
+ int size = reinterpret_cast<uintptr_t>(_binary_binary_txt_size);
+ assert(size == _binary_binary_txt_end - _binary_binary_txt_start);
+
+ const char* const txt = "This file is used for the binary test.\n";
+ assert(strncmp(txt, _binary_binary_txt_start, size) == 0);
+ assert(static_cast<size_t>(size) == strlen(txt));
+
+ return 0;
+}
diff --git a/gold/testsuite/binary_unittest.cc b/gold/testsuite/binary_unittest.cc
new file mode 100644
index 0000000..0be2478
--- /dev/null
+++ b/gold/testsuite/binary_unittest.cc
@@ -0,0 +1,147 @@
+// binary_unittest.cc -- test Binary_to_elf
+
+// Copyright 2008 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.
+
+#include "gold.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "elfcpp.h"
+#include "parameters.h"
+#include "errors.h"
+#include "options.h"
+#include "binary.h"
+#include "object.h"
+
+#include "test.h"
+#include "testfile.h"
+
+namespace gold_testsuite
+{
+
+using namespace gold;
+
+template<int size, bool big_endian>
+bool
+Sized_binary_test(Target* target)
+{
+ // We need a pretend Task.
+ const Task* task = reinterpret_cast<const Task*>(-1);
+
+ // Use the executable itself as the binary data.
+ struct stat st;
+ CHECK(::stat(gold::program_name, &st) == 0);
+ int o = ::open(gold::program_name, O_RDONLY);
+ CHECK(o >= 0);
+ unsigned char* filedata = new unsigned char[st.st_size];
+ CHECK(::read(o, filedata, st.st_size) == st.st_size);
+ CHECK(::close(o) == 0);
+
+ Binary_to_elf binary(static_cast<elfcpp::EM>(0xffff), size, big_endian,
+ gold::program_name);
+
+ CHECK(binary.convert(task));
+
+ Input_file input_file(task, "test.o", binary.converted_data(),
+ binary.converted_size());
+ Object* object = make_elf_object("test.o", &input_file, 0,
+ binary.converted_data(),
+ binary.converted_size());
+ CHECK(object != NULL);
+ if (object == NULL)
+ return false;
+
+ CHECK(!object->is_dynamic());
+ CHECK(object->target() == target);
+ CHECK(object->shnum() == 5);
+ CHECK(object->section_name(1) == ".data");
+ CHECK(object->section_flags(1) == elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE);
+ section_size_type len;
+ const unsigned char* contents = object->section_contents(1, &len, false);
+ CHECK(len == st.st_size);
+ CHECK(memcmp(filedata, contents, len) == 0);
+
+ // Force the symbols to be read internally, so that
+ // symbol_section_and_value will work.
+ Read_symbols_data sd;
+ object->read_symbols(&sd);
+ delete sd.section_headers;
+ delete sd.section_names;
+ delete sd.symbols;
+ delete sd.symbol_names;
+
+ Sized_relobj<size, big_endian>* relobj =
+ static_cast<Sized_relobj<size, big_endian>*>(object);
+ typename Sized_relobj<size, big_endian>::Address value;
+ CHECK(relobj->symbol_section_and_value(0, &value) == 0);
+ CHECK(value == 0);
+ CHECK(relobj->symbol_section_and_value(1, &value) == 1);
+ CHECK(value == 0);
+ CHECK(relobj->symbol_section_and_value(2, &value) == 1);
+ CHECK(static_cast<off_t>(value) == st.st_size);
+ CHECK(relobj->symbol_section_and_value(3, &value) == elfcpp::SHN_ABS);
+ CHECK(static_cast<off_t>(value) == st.st_size);
+
+ object->unlock(task);
+ return true;
+}
+
+bool
+Binary_test(Test_report*)
+{
+ Errors errors(gold::program_name);
+ initialize_parameters(&errors);
+
+ Script_options script_options;
+ General_options options(&script_options);
+ set_parameters_from_options(&options);
+
+ int fail = 0;
+
+#ifdef HAVE_TARGET_32_LITTLE
+ if (!Sized_binary_test<32, false>(target_test_pointer_32_little))
+ ++fail;
+#endif
+
+#ifdef HAVE_TARGET_32_BIG
+ if (!Sized_binary_test<32, true>(target_test_pointer_32_big))
+ ++fail;
+#endif
+
+#ifdef HAVE_TARGET_64_LITTLE
+ if (!Sized_binary_test<64, false>(target_test_pointer_64_little))
+ ++fail;
+#endif
+
+#ifdef HAVE_TARGET_64_BIG
+ if (!Sized_binary_test<64, true>(target_test_pointer_64_big))
+ ++fail;
+#endif
+
+ return fail == 0;
+}
+
+Register_test binary_register("Binary", Binary_test);
+
+} // End namespace gold_testsuite.