From: Viktor Kutuzov <vkutuzov@accesssoftek.com>
To: <binutils@sourceware.org>
Subject: Fw: [PATCH] Gold: Added R_ARM_GOT_PREL relocation and unit tests
Date: Tue, 22 Sep 2009 20:37:00 -0000 [thread overview]
Message-ID: <65358F01739A40049E53A7B01C000645@andreic6e7fe55> (raw)
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]
Ping.
Best regards,
Viktor
----- Original Message -----
From: "Viktor Kutuzov" <vkutuzov@accesssoftek.com>
To: <binutils@sourceware.org>
Sent: Tuesday, September 15, 2009 5:23 PM
Subject: [PATCH] Gold: Added R_ARM_GOT_PREL relocation and unit tests
Hello everyone,
Please find attached the patch for R_ARM_GOT_PREL relocation along with the unit tests.
Best regards,
Viktor
* gold/arm.cc: Added R_ARM_GOT_PREL relocation, added missing R_ARM_ABS8 in to the list of implemented relocations
* gold/testsuite/arm/Makefile.am: Added unit tests to make
* gold/testsuite/arm/reloc_got_test.sh: Script to test platform-dependent R_ARM_GOT_PREL relocation
* gold/testsuite/arm/arm_r_got_prel.s: Asm for the R_ARM_GOT_PREL relocation unit tests
[-- Attachment #2: binutil-gold-arm-rel-gotprel.diff --]
[-- Type: application/octet-stream, Size: 10833 bytes --]
diff -rupN -x .deps -x autom4te.cache -x configure -x 'config.*' -x Makefile -x Makefile.in -x '*~' binutils.orig/src/gold/arm.cc binutils.gold/src/gold/arm.cc
--- binutils.orig/src/gold/arm.cc 2009-09-15 15:40:09.000000000 -0700
+++ binutils.gold/src/gold/arm.cc 2009-09-15 16:48:49.000000000 -0700
@@ -68,11 +68,13 @@ class Output_data_plt_arm;
// R_ARM_RELATIVE
// R_ARM_GOTOFF32
// R_ARM_GOT_BREL
+// R_ARM_GOT_PREL
// R_ARM_PLT32
// R_ARM_CALL
// R_ARM_JUMP24
// R_ARM_TARGET1
// R_ARM_PREL31
+// R_ARM_ABS8
//
// TODOs:
// - Generate various branch stubs.
@@ -679,6 +681,16 @@ class Arm_relocate_functions : public Re
return This::STATUS_OKAY;
}
+ // R_ARM_GOT_PREL: GOT(S) + A – P
+ static inline typename This::Status
+ got_prel(unsigned char* view,
+ typename elfcpp::Swap<32, big_endian>::Valtype got_offset,
+ elfcpp::Elf_types<32>::Elf_Addr address)
+ {
+ Base::rel32(view, got_offset - address);
+ return This::STATUS_OKAY;
+ }
+
// R_ARM_PLT32: (S + A) | T - P
static inline typename This::Status
plt32(unsigned char *view,
@@ -1156,6 +1168,7 @@ Target_arm<big_endian>::Scan::local(cons
break;
case elfcpp::R_ARM_GOT_BREL:
+ case elfcpp::R_ARM_GOT_PREL:
{
// The symbol requires a GOT entry.
Output_data_got<32, big_endian>* got =
@@ -1351,6 +1364,7 @@ Target_arm<big_endian>::Scan::global(con
break;
case elfcpp::R_ARM_GOT_BREL:
+ case elfcpp::R_ARM_GOT_PREL:
{
// The symbol requires a GOT entry.
Output_data_got<32, big_endian>* got =
@@ -1623,6 +1637,7 @@ Target_arm<big_endian>::Relocate::reloca
switch (r_type)
{
case elfcpp::R_ARM_GOT_BREL:
+ case elfcpp::R_ARM_GOT_PREL:
if (gsym != NULL)
{
gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
@@ -1708,6 +1723,15 @@ Target_arm<big_endian>::Relocate::reloca
reloc_status = Arm_relocate_functions::got_brel(view, got_offset);
break;
+ case elfcpp::R_ARM_GOT_PREL:
+ gold_assert(have_got_offset);
+ // Get the address origin for GOT PLT, which is allocated right after the GOT section,
+ // to calculate an absolute address of the symbol GOT entry (got_origin + got_offset).
+ elfcpp::Elf_types<32>::Elf_Addr got_origin;
+ got_origin = target->got_plt_section()->address();
+ reloc_status = Arm_relocate_functions::got_prel(view, got_origin + got_offset, address);
+ break;
+
case elfcpp::R_ARM_PLT32:
gold_assert(gsym == NULL
|| gsym->has_plt_offset()
@@ -1835,6 +1859,7 @@ Target_arm<big_endian>::Relocatable_size
case elfcpp::R_ARM_GOTOFF32:
case elfcpp::R_ARM_BASE_PREL:
case elfcpp::R_ARM_GOT_BREL:
+ case elfcpp::R_ARM_GOT_PREL:
case elfcpp::R_ARM_PLT32:
case elfcpp::R_ARM_CALL:
case elfcpp::R_ARM_JUMP24:
diff -rupN -x .deps -x autom4te.cache -x configure -x 'config.*' -x Makefile -x Makefile.in -x '*~' binutils.orig/src/gold/testsuite/arm/arm_r_got_prel.s binutils.gold/src/gold/testsuite/arm/arm_r_got_prel.s
--- binutils.orig/src/gold/testsuite/arm/arm_r_got_prel.s 1969-12-31 16:00:00.000000000 -0800
+++ binutils.gold/src/gold/testsuite/arm/arm_r_got_prel.s 2009-09-15 16:25:03.000000000 -0700
@@ -0,0 +1,60 @@
+@FILE: arm_r_got_prel.s
+@TEST RELOCATION : R_ARM_GOT_PREL
+@Local static relocation
+
+@COMPILE: arm-none-linux-gnueabi-gcc arm_r_got_prel.s arm_r_got_prel.o
+@LINK: ../binutils.gold/src/gold/ld-new arm_r_got_prel.o -o arm_r_got_prel
+
+ .cpu arm10tdmi
+ .file "arm_r_got_prel.s"
+ .text
+ .align 2
+start:
+ .global start
+.LCFI2:
+ ldr r4, .L3
+.LPIC0:
+ add r4, pc, r4 @ r4 will contain the GOT pointer
+ @ after this.
+
+ @----------------------------------------------------
+ @ printf _global_string_got_prel
+
+ ldr r3, .LL0 @ Loading statically relocated value
+ @ -- an offset to GOT entry from
+ @ the relocation address
+ add r3, r3, #(.LL0-.LOFF1) @ Building an absolute address to
+ @ the GOT entry (pc + off_to_word +
+ @ off_to_GOT)
+ ldr r3, [pc, r3] @ Loading a value of the GOT entry
+ ldr r3, [r3, #0] @ Loading a pointer to the destination
+ @ string.
+.LOFF1: mov r0, r3
+ @bl printf(PLT) @ kind of printing
+
+ @----------------------------------------------------
+ .align 2
+.L3:
+ .word _GLOBAL_OFFSET_TABLE_-(.LPIC0+8)
+REL_PREL_ADDRESS:
+ @ NOTE: put this variable into the symbol table to use in the tests.
+ .global REL_PREL_ADDRESS
+ @ NOTE: TARGET2 relocation will be interpreted as GOT_PREL by GOLD
+.LL0: .word _global_string_got_prel(TARGET2)
+
+ .global _global_string_got_prel
+
+ @----------------------------------------------------
+ .section .rodata
+ .align 2
+.LC0:
+ .ascii "GLOBAL (TARGET2/R_ARM_GOT_PREL).\012\000"
+
+ @----------------------------------------------------
+ .section .data.rel.local,"aw",%progbits
+ .align 2
+_global_string_got_prel:
+ .word .LC0
+
+ @----------------------------------------------------
+ .end
diff -rupN -x .deps -x autom4te.cache -x configure -x 'config.*' -x Makefile -x Makefile.in -x '*~' binutils.orig/src/gold/testsuite/arm/Makefile.am binutils.gold/src/gold/testsuite/arm/Makefile.am
--- binutils.orig/src/gold/testsuite/arm/Makefile.am 2009-09-15 15:40:44.000000000 -0700
+++ binutils.gold/src/gold/testsuite/arm/Makefile.am 2009-09-15 14:26:53.000000000 -0700
@@ -55,22 +55,25 @@ if TARGET_ARM
# Test - ABS relocations
-MOSTLYCLEANFILES += arm_r_abs8_local arm_r_abs8_localrw arm_r_abs8_external
+MOSTLYCLEANFILES += arm_r_abs8_local arm_r_abs8_localrw arm_r_abs8_external arm_r_got_prel
BUILT_SOURCES += \
arm_r_abs8_local.s \
arm_r_abs8_localrw.s \
arm_r_abs8_global.s \
- arm_r_abs8_external.s
+ arm_r_abs8_external.s \
+ arm_r_got_prel.s
check_DATA += \
arm_r_abs8_local \
arm_r_abs8_external \
arm_r_abs8_localrw \
- arm_r_abs8_localoverflow.o
+ arm_r_abs8_localoverflow.o \
+ arm_r_got_prel
check_SCRIPTS += \
- reloc_abs_test.sh
+ reloc_abs_test.sh \
+ reloc_got_test.sh
arm_r_abs8_local.o: arm_r_abs8_local.s
$(TEST_AS) -o $@ $<
@@ -82,6 +85,8 @@ arm_r_abs8_global.o: arm_r_abs8_global.s
$(TEST_AS) -o $@ $<
arm_r_abs8_external.o: arm_r_abs8_external.s
$(TEST_AS) -o $@ $<
+arm_r_got_prel.o: arm_r_got_prel.s
+ $(TEST_AS) -o $@ $<
arm_r_abs8_local: arm_r_abs8_local.o
$(TEST_LD) -Ttext=0 -o $@ $<
@@ -89,6 +94,8 @@ arm_r_abs8_localrw: arm_r_abs8_localrw.o
$(TEST_LD) -Ttext=0 -Tdata=0x90 -o $@ $<
arm_r_abs8_external: arm_r_abs8_external.o arm_r_abs8_global.o
$(TEST_LD) -Ttext=0 -o $@ $< arm_r_abs8_global.o
+arm_r_got_prel: arm_r_got_prel.o
+ $(TEST_LD) -o $@ $<
endif TARGET_ARM
diff -rupN -x .deps -x autom4te.cache -x configure -x 'config.*' -x Makefile -x Makefile.in -x '*~' binutils.orig/src/gold/testsuite/arm/reloc_got_test.sh binutils.gold/src/gold/testsuite/arm/reloc_got_test.sh
--- binutils.orig/src/gold/testsuite/arm/reloc_got_test.sh 1969-12-31 16:00:00.000000000 -0800
+++ binutils.gold/src/gold/testsuite/arm/reloc_got_test.sh 2009-09-15 16:27:25.000000000 -0700
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+# reloc_got_test.sh -- a test case for the GOT relocations.
+
+# Copyright 2009 Free Software Foundation, Inc.
+# Written by Viktor Kutuzov <vkutuzov@accesssoftek.com>.
+
+# This file is a 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.
+
+check_relocation_got_prel_value()
+{
+ # Arguments:
+ # $1 - Linked file name. The file with the same name and extention '.o'
+ # will be looked for objects.
+ file_name=$1
+ # $2 - Symbol name. The relocation to test is referenced by this unique
+ # symbol name.
+ symbol_name=$2
+ # $3 - Symbol name. The relocation reference within the .text section
+ symbol_reloc_name=$3
+
+
+ # Retrieve the requested segment address from the linked file.
+ # The value is in the readelf output dump looks something like this:
+ # ----------------------------vvvvvvvv--------------------------------
+ # Section Headers:
+ # [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
+ # [ 4] .got PROGBITS 000090c0 0000c0 000010 00 WA 0 0 4
+ valid_result=`readelf -S $file_name | grep -w ".got" | sed 's/\]//;s/\[//;s/^/:/;s/$/:/;s/[: ][: ]*/:/g' | cut -d: -f5`
+ if test -z "$valid_result"; then
+ echo "Did not find segment .got in $file_name"
+ exit 1
+ fi
+
+ symbol_reloc_address=`readelf -s $file_name | grep -w $symbol_reloc_name | sed 's/^/:/;s/$/:/;s/[: ][: ]*/:/g' | cut -d: -f3 | sed 's/^0*//g'`
+ if test -z "$symbol_reloc_address"; then
+ echo "Did not find symbol $symbol_reloc_name in $file_name"
+ exit 1
+ fi
+
+ # Result transformation from string like "76: 90 .byte 0x90"
+ # to "76:90:.byte:0x90"
+ linker_result=`../../../binutils/objdump -ds $file_name | sed -e 's/^\s*//g' -e 's/^0*//g' | grep "^$symbol_reloc_address:" | sed -e 's/://' -e 's/\t/:/g' -e 's/\s//g' | cut -d: -f2`
+
+ # Add the symbol relocation address to the relocated value. We will get
+ # a pointer (address) to the GOT entry as result.
+ # This entry has been placed at beginning of the table, because we have
+ # only one entry in GOT. In that way an address of GOT must be equal with
+ # an address of the entry (see $valid_result)
+ linker_result=$((0x$linker_result + 0x$symbol_reloc_address))
+ valid_result=$((0x$valid_result + 0))
+
+ #echo "debug: valid_result=$valid_result"
+ #echo "debug: symbol_reloc_address=$symbol_reloc_address"
+ #echo "debug: linked_result=$linker_result"
+
+ if test $linker_result != $valid_result; then
+ echo "check_relocation_abs_global: unexpected result for relocation value in $file_name:"
+ echo " $valid_result"
+ echo ""
+ echo "Actual value below:"
+ echo "$linker_result"
+ exit 1
+ fi
+}
+
+
+# Unit tests:
+
+check_relocation_got_prel_value arm_r_got_prel "_global_string_got_prel" "REL_PREL_ADDRESS"
+
+exit 0
+
reply other threads:[~2009-09-22 20:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65358F01739A40049E53A7B01C000645@andreic6e7fe55 \
--to=vkutuzov@accesssoftek.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).