From: Thomas Schwinge <thomas@codesourcery.com>
To: binutils@sourceware.org
Cc: paul@codesourcery.com, dan@codesourcery.com
Subject: [ARM] Relocations against STN_UNDEF
Date: Fri, 24 Sep 2010 11:26:00 -0000 [thread overview]
Message-ID: <87bp7ntmcq.fsf_-_@dirichlet.schwinge.homeip.net> (raw)
In-Reply-To: <20100924001235.GI16376@bubble.grove.modra.org> (Alan Modra's message of "Fri, 24 Sep 2010 09:42:35 +0930")
[-- Attachment #1: Type: text/plain, Size: 4158 bytes --]
Hello!
The ELF standard says that STN_UNDEF (symbol index zero, the undefined
symbol index) is to be marked as SHN_UNDEF, undefined symbol. There is
one exception however: during relocations processing, a relocation
against STN_UNDEF shall be treated as a symbol value of zero.
For example on ARM, the bl instruction does a PC-relative jump, so to
jump to an absolute value of 0x10000, ``bl 0x10000'' has to keep its
relocation until the final linking is done, to be converted to the proper
PC-relative offset.
$ cat < ~/sgxx/issue8612/bl_ABS.s
bl 0x10000
$ "$PWD"_install/bin/*-as -o bl_ABS.o ~/sgxx/issue8612/bl_ABS.s
$ "$PWD"_install/bin/*-readelf -r bl_ABS.o
Relocation section '.rel.text' at offset 0x25c contains 1 entries:
Offset Info Type Sym.Value Sym. Name
00000000 0000001c R_ARM_CALL
This info value translates to relocation type 28 (R_ARM_CALL) against
symbol index zero (STN_UNDEF).
On 2010-09-24 00:12, Alan Modra wrote:
> On Thu, Sep 23, 2010 at 05:37:01PM +0200, Thomas Schwinge wrote:
>> $ "$PWD"_install/bin/*-ld -o bl_ABS bl_ABS.o
>> /scratch/thomas/binutils/HEAD_build_arm-none-eabi_install/bin/arm-none-eabi-ld: warning: cannot find entry symbol _start; defaulting to 0000000000008000
>> bl_ABS.o:(.text+0x0): undefined reference to `no symbol'
>
> ARM fails because the arm backend specifically checks for undefined
> local symbols. I'd say the arm backend check needs fixing (or
> removing) rather than changing the common elflink code.
Here is a patch to fix this issue in the ARM backend. There are no
regressions with a --target=arm-none-eabi config.
bfd/
2010-09-24 Thomas Schwinge <thomas@codesourcery.com>
* elf32-arm.c (elf32_arm_final_link_relocate)
(elf32_arm_relocate_section): Handle relocations against STN_UNDEF.
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.241
diff -u -p -r1.241 elf32-arm.c
--- bfd/elf32-arm.c 26 Aug 2010 10:32:26 -0000 1.241
+++ bfd/elf32-arm.c 24 Sep 2010 11:16:45 -0000
@@ -7224,12 +7224,12 @@ elf32_arm_final_link_relocate (reloc_how
/* A branch to an undefined weak symbol is turned into a jump to
the next instruction unless a PLT entry will be created.
- Do the same for local undefined symbols.
+ Do the same for local undefined symbols (but not for STN_UNDEF).
The jump to the next instruction is optimized as a NOP depending
on the architecture. */
if (h ? (h->root.type == bfd_link_hash_undefweak
&& !(splt != NULL && h->plt.offset != (bfd_vma) -1))
- : bfd_is_und_section (sym_sec))
+ : r_symndx != STN_UNDEF && bfd_is_und_section (sym_sec))
{
value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000);
@@ -8903,9 +8903,11 @@ elf32_arm_relocate_section (bfd *
undefined symbol. This is a daft object file, but we
should at least do something about it. V4BX & NONE
relocations do not use the symbol and are explicitly
- allowed to use the undefined symbol, so allow those. */
+ allowed to use the undefined symbol, so allow those.
+ Likewise for relocations against STN_UNDEF. */
if (r_type != R_ARM_V4BX
&& r_type != R_ARM_NONE
+ && r_symndx != STN_UNDEF
&& bfd_is_und_section (sec)
&& ELF_ST_BIND (sym->st_info) != STB_WEAK)
{
Success with patched BFD:
$ "$PWD"_install/bin/*-ld -o bl_ABS bl_ABS.o
/scratch/thomas/binutils/HEAD_build_arm-none-eabi_install/bin/arm-none-eabi-ld: warning: cannot find entry symbol _start; defaulting to 0000000000008000
$ "$PWD"_install/bin/*-readelf -r bl_ABS
There are no relocations in this file.
$ "$PWD"_install/bin/*-objdump -dr bl_ABS
bl_ABS: file format elf32-littlearm
Disassembly of section .text:
00008000 <__data_start-0x8004>:
8000: eb001ffe bl 10000 <__bss_end__-0x4>
Regards,
Thomas
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2010-09-24 11:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 15:37 Thomas Schwinge
2010-09-24 0:12 ` Alan Modra
2010-09-24 7:54 ` Thomas Schwinge
2010-09-24 9:17 ` Alan Modra
2010-09-24 10:37 ` BFD, GAS, LD internal manuals (was: Relocations against STN_UNDEF) Thomas Schwinge
2010-09-24 9:46 ` Relocations against STN_UNDEF Thomas Schwinge
2010-09-24 11:33 ` Alan Modra
2010-09-24 12:16 ` Thomas Schwinge
2010-09-24 11:26 ` Thomas Schwinge [this message]
2010-09-24 14:53 ` [ARM] " Richard Henderson
2010-09-27 4:31 ` Thomas Schwinge
2010-10-08 10:33 ` Alan Modra
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=87bp7ntmcq.fsf_-_@dirichlet.schwinge.homeip.net \
--to=thomas@codesourcery.com \
--cc=binutils@sourceware.org \
--cc=dan@codesourcery.com \
--cc=paul@codesourcery.com \
/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).