This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[patch] Thumb entry points
- From: Paul Brook <paul at codesourcery dot com>
- To: binutils at sourceware dot org
- Date: Sat, 4 Feb 2006 03:05:11 +0000
- Subject: [patch] Thumb entry points
The attached patch makes the Arm linker set the low bit of the entry point
address when the symbol is a Thumb function.
Tested with cross to arm-none-eabi
Ok?
Paul
2006-02-04 Paul Brook <paul@codesourcery.com>
ld/
* emultempl/armelf.em: Include elf/arm.h.
(arm_elf_finish): Set low address bit if enty point is a Thumb
function.
ld/testsuite/
* ld-arm/arm-elf.exp: Add thumb-entry test.
* ld-arm/thumb-entry.d: New test.
* ld-arm/thumb-entry.s: New test.
Index: ld/emultempl/armelf.em
===================================================================
RCS file: /var/cvsroot/src-cvs/src/ld/emultempl/armelf.em,v
retrieving revision 1.48
diff -u -p -r1.48 armelf.em
--- ld/emultempl/armelf.em 17 Nov 2005 00:10:05 -0000 1.48
+++ ld/emultempl/armelf.em 4 Feb 2006 02:53:53 -0000
@@ -26,6 +26,8 @@
test -z "$TARGET2_TYPE" && TARGET2_TYPE="rel"
cat >>e${EMULATION_NAME}.c <<EOF
+#include "elf/arm.h"
+
static char *thumb_entry_symbol = NULL;
static bfd *bfd_for_interwork;
static int byteswap_code = 0;
@@ -150,11 +152,25 @@ arm_elf_finish (void)
/* Call the elf32.em routine. */
gld${EMULATION_NAME}_finish ();
- if (thumb_entry_symbol == NULL)
- return;
+ if (thumb_entry_symbol)
+ {
+ h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
+ FALSE, FALSE, TRUE);
+ }
+ else
+ {
+ struct elf_link_hash_entry * eh;
+
+ if (!entry_symbol.name)
+ return;
+
+ h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name,
+ FALSE, FALSE, TRUE);
+ eh = (struct elf_link_hash_entry *)h;
+ if (!h || ELF_ST_TYPE(eh->type) != STT_ARM_TFUNC)
+ return;
+ }
- h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
- FALSE, FALSE, TRUE);
if (h != (struct bfd_link_hash_entry *) NULL
&& (h->type == bfd_link_hash_defined
@@ -180,7 +196,8 @@ arm_elf_finish (void)
sprintf_vma (buffer + 2, val);
- if (entry_symbol.name != NULL && entry_from_cmdline)
+ if (thumb_entry_symbol != NULL && entry_symbol.name != NULL
+ && entry_from_cmdline)
einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
thumb_entry_symbol, entry_symbol.name);
entry_symbol.name = buffer;
Index: ld/testsuite/ld-arm/arm-elf.exp
===================================================================
RCS file: /var/cvsroot/src-cvs/src/ld/testsuite/ld-arm/arm-elf.exp,v
retrieving revision 1.9
diff -u -p -r1.9 arm-elf.exp
--- ld/testsuite/ld-arm/arm-elf.exp 12 Dec 2005 17:03:40 -0000 1.9
+++ ld/testsuite/ld-arm/arm-elf.exp 4 Feb 2006 02:47:51 -0000
@@ -89,6 +89,9 @@ set armelftests {
{"TLS dynamic application" "-T arm-dyn.ld tmpdir/tls-lib.so" "" {tls-app.s}
{{objdump -fdw tls-app.d} {objdump -Rw tls-app.r}}
"tls-app"}
+ {"Thumb entry point" "-T arm.ld" "" {thumb-entry.s}
+ {{readelf -h thumb-entry.d}}
+ "thumb-entry"}
}
run_ld_link_tests $armelftests
Index: ld/testsuite/ld-arm/thumb-entry.d
===================================================================
RCS file: ld/testsuite/ld-arm/thumb-entry.d
diff -N ld/testsuite/ld-arm/thumb-entry.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/thumb-entry.d 4 Feb 2006 02:31:13 -0000
@@ -0,0 +1,3 @@
+#...
+ Entry point address: 0x8001
+#...
Index: ld/testsuite/ld-arm/thumb-entry.s
===================================================================
RCS file: ld/testsuite/ld-arm/thumb-entry.s
diff -N ld/testsuite/ld-arm/thumb-entry.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-arm/thumb-entry.s 4 Feb 2006 02:32:17 -0000
@@ -0,0 +1,8 @@
+ .text
+ .arch armv4t
+ .thumb
+ .global _start
+ .thumb_func
+_start:
+ bx lr
+