This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH, Take 2] Gold: Added R_ARM_ABS8 relocation unit test
Viktor Kutuzov <vkutuzov@accesssoftek.com> writes:
> Please find attached the updated patch for the R_ARM_ABS8 relocation unit test.
I appreciate all the hard work you've done here, but this doesn't seem
like the right approach to me.
For standard relocations like 8-bit absolute we can write a reasonably
standard test. We don't need to write a target dependent test.
I think we can make these tests more robust by using special section
names.
I don't understand your check_relocation_abs test. As far as I can
tell, what it tests is that the final value of a symbol is the value
in the object file plus the offset of the section in the executable.
It doesn't seem to test the relocation value.
What I'm thinking is something along the lines of the appended,
although that is incomplete.
Ian
Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gold/configure.ac,v
retrieving revision 1.46
diff -u -r1.46 configure.ac
--- configure.ac 23 Jun 2009 18:10:41 -0000 1.46
+++ configure.ac 27 Sep 2009 07:34:02 -0000
@@ -180,6 +180,11 @@
fi
AC_SUBST(TARGETOBJS)
+DEFAULT_ELF_MACHINE="$default_machine"
+AC_SUBST(DEFAULT_ELF_MACHINE)
+DEFAULT_ELF_SIZE="$default_size"
+AC_SUBST(DEFAULT_ELF_SIZE)
+
AC_DEFINE_UNQUOTED(GOLD_DEFAULT_MACHINE, $default_machine,
[Default machine code])
AC_DEFINE_UNQUOTED(GOLD_DEFAULT_SIZE, $default_size,
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.103
diff -u -r1.103 Makefile.am
--- testsuite/Makefile.am 18 Sep 2009 20:02:21 -0000 1.103
+++ testsuite/Makefile.am 27 Sep 2009 07:34:03 -0000
@@ -25,6 +25,7 @@
TEST_STRIP = $(top_builddir)/../binutils/strip-new
TEST_AR = $(top_builddir)/../binutils/ar
TEST_NM = $(top_builddir)/../binutils/nm-new
+TEST_AS = $(top_builddir)/../gas/as-new
if PLUGINS
LIBDL = -ldl
@@ -76,6 +77,20 @@
binary_unittest_SOURCES = binary_unittest.cc
+# Test simple relocations
+check_SCRIPTS += relocs_test.sh
+check_DATA += relocs-syms.stdout relocs-secs.stdout relocs-size.stdout
+relocs.o: relocs.s
+ $(TEST_AS) --defsym CPU=$(DEFAULT_ELF_MACHINE) --defsym SIZE=$(DEFAULT_ELF_SIZE) -o $@ $<
+relocs: relocs.o gcctestdir/ld
+ gcctestdir/ld -N -o $@ --defsym global_sym=0x10 -Ttext 0 -e entry relocs.o
+relocs-syms.stdout: relocs
+ $(TEST_NM) relocs > $@
+relocs-secs.stdout: relocs
+ $(TEST_OBJDUMP) -s relocs > $@
+relocs-size.stdout: Makefile
+ echo $(DEFAULT_ELF_SIZE) > $@
+
# ---------------------------------------------------------------------
# These tests test the output of gold (end-to-end tests). In
# particular, they make sure that gold can link "difficult" object
@@ -670,7 +685,6 @@
endif
-
# Test --detect-odr-violations
check_SCRIPTS += debug_msg.sh
Index: testsuite/relocs.s
===================================================================
RCS file: testsuite/relocs.s
diff -N testsuite/relocs.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/relocs.s 27 Sep 2009 07:34:03 -0000
@@ -0,0 +1,69 @@
+ .text
+entry:
+ .globl entry
+ .8byte 0
+
+ .data
+ .8byte 0
+local_sym:
+ .8byte 0
+
+.macro section name
+.ifeqs "CPU", "EM_ARM"
+ .section \name,"aw",%progbits
+.else
+ .section \name,"aw",@progbits
+.endif
+.endm
+
+ section test_1_l
+ .byte local_sym
+
+ section test_1_g
+ .byte global_sym
+
+ section test_1_lp
+ .byte local_sym - .
+
+ section test_1_gp
+ .byte global_sym - .
+
+ section test_2_l
+ .2byte local_sym
+
+ section test_2_g
+ .2byte global_sym
+
+ section test_2_lp
+ .2byte local_sym - .
+
+ section test_2_gp
+ .2byte global_sym - .
+
+ section test_4_l
+ .4byte local_sym
+
+ section test_4_g
+ .4byte global_sym
+
+ section test_4_lp
+ .4byte local_sym - .
+
+ section test_4_gp
+ .4byte global_sym - .
+
+.if SIZE != 32
+
+ section test_8_l
+ .8byte local_sym
+
+ section test_8_g
+ .8byte global_sym
+
+ section test_8_lp
+ .8byte local_sym - .
+
+ section test_8_gp
+ .8byte global_sym - .
+
+.endif
Index: testsuite/relocs_test.sh
===================================================================
RCS file: testsuite/relocs_test.sh
diff -N testsuite/relocs_test.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/relocs_test.sh 27 Sep 2009 07:34:03 -0000
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+# Copyright 2009 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.
+
+# Test that basic relocations produce the right value.
+
+# Get the value of the symbol "local_sym".
+locval=`grep local_sym relocs-syms.stdout | sed -e 's/ .*//' -e 's/^0*//'`
+if ! expr "$locval" : '[0-9a-f][0-9a-f]' >/dev/null 2>&1; then
+ echo 1>&2 "local_sym value is ${locval}; expected two hex digits"
+ exit 1
+fi
+
+# Get the value of the symbol "global_sym", which should be 0x10.
+globval=`grep global_sym relocs-syms.stdout | sed -e 's/ .*//' -e 's/^0*//'`
+if test "$globval" != "10"; then
+ echo 1>&2 "global_sym value is ${globval}; expected two hex digits"
+ exit 1
+fi
+
+# Set the variable contents to the contents of section $1.
+get_contents()
+{
+ contents=`sed -ne "
+ /section $1:/ {
+ n
+ s/^ *[0-9a-fA-F]* //
+ s/ .*$//
+ s/ //g
+ p
+ }
+ " < relocs-secs.stdout`
+}
+
+# Verify that the contents of section $1 is either $2 or $3.
+check_contents()
+{
+ get_contents $1
+ if test "$contents" != "$2" -a "$contents" != "$3"; then
+ echo 1>&2 "Section $1 is '$contents'; expected '$2' or '$3'"
+ exit 1
+ fi
+}
+
+check_contents "test_1_l" "${locval}" "${locval}"
+check_contents "test_1_g" "${globval}" "${globval}"
+check_contents "test_2_l" "00${locval}" "${locval}00"
+check_contents "test_2_g" "00${globval}" "${globval}00"
+check_contents "test_4_l" "000000${locval}" "${locval}000000"
+check_contents "test_4_g" "000000${globval}" "${globval}000000"
+
+size=`cat relocs-size.stdout`
+if test "$size" != "32"; then
+ check_contents "test_8_l" "00000000000000${locval}" "${locval}00000000000000"
+ check_contents "test_8_g" "00000000000000${globval}" "${globval}00000000000000"
+fi
+
+exit 0